YamlRector - add getDefinition() to be compatible with RectorInterface

This commit is contained in:
Tomas Votruba 2018-07-17 22:01:20 +02:00
parent 910b26a577
commit 2a3cc2db31
3 changed files with 22 additions and 0 deletions

View File

@ -2,8 +2,12 @@
namespace Rector\YamlRector\Contract;
use Rector\RectorDefinition\RectorDefinition;
interface YamlRectorInterface
{
public function getDefinition(): RectorDefinition;
public function isCandidate(string $content): bool;
public function refactor(string $content): string;

View File

@ -3,6 +3,8 @@
namespace Rector\YamlRector\Rector;
use Nette\Utils\Strings;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
use Rector\YamlRector\Contract\YamlRectorInterface;
final class RenameSubKeyYamlRector implements YamlRectorInterface
@ -20,6 +22,13 @@ final class RenameSubKeyYamlRector implements YamlRectorInterface
$this->pathsToNewKeys = $pathsToNewKeys;
}
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Replaces specifically nested key by another.', [
new CodeSample('key > another_key > old_key: value', 'key > another_key > new_key: value'),
]);
}
public function isCandidate(string $content): bool
{
foreach ($this->pathsToNewKeys as $path => $newKey) {

View File

@ -3,6 +3,8 @@
namespace Rector\YamlRector\Rector;
use Nette\Utils\Strings;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
use Rector\YamlRector\Contract\YamlRectorInterface;
final class ReplaceStringYamlRector implements YamlRectorInterface
@ -20,6 +22,13 @@ final class ReplaceStringYamlRector implements YamlRectorInterface
$this->oldToNewString = $oldToNewString;
}
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Replaces one string by another. Use only for very specific strings only.', [
new CodeSample('key: !super_old_complex', 'key: !super_old_complex'),
]);
}
public function isCandidate(string $content): bool
{
foreach ($this->oldToNewString as $oldString => $newString) {