mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 12:29:43 +01:00
YamlRector - add getDefinition() to be compatible with RectorInterface
This commit is contained in:
parent
910b26a577
commit
2a3cc2db31
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user