mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-31 12:42:05 +01:00
add ConfiguredCodeSample
This commit is contained in:
parent
8dcc357104
commit
2bf86874f4
@ -111,7 +111,7 @@ CODE_SAMPLE
|
||||
[
|
||||
'$annotation' => 'inject',
|
||||
]
|
||||
),
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -68,8 +68,8 @@ final class MoveRepositoryFromParentToConstructorRector extends AbstractRector
|
||||
DoctrineEntityAndRepositoryMapperInterface $doctrineEntityAndRepositoryMapper,
|
||||
BuilderFactory $builderFactory,
|
||||
VariableInfoFactory $variableInfoFactory,
|
||||
string $entityRepositoryClass = 'Doctrine\ORM\EntityRepository',
|
||||
string $entityManagerClass = 'Doctrine\ORM\EntityManager'
|
||||
string $entityRepositoryClass,
|
||||
string $entityManagerClass
|
||||
) {
|
||||
$this->propertyBuilder = $propertyBuilder;
|
||||
$this->constructorMethodBuilder = $constructorMethodBuilder;
|
||||
@ -138,7 +138,7 @@ CODE_SAMPLE
|
||||
'$entityRepositoryClass' => 'Doctrine\ORM\EntityRepository',
|
||||
'$entityManagerClass' => 'Doctrine\ORM\EntityManager',
|
||||
]
|
||||
),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,9 @@ final class PropertyAssignToMethodCallRector extends AbstractRector
|
||||
public function __construct(
|
||||
PropertyFetchAnalyzer $propertyFetchAnalyzer,
|
||||
MethodCallNodeFactory $methodCallNodeFactory,
|
||||
array $types = ['Nette\Forms\Controls\MultiChoiceControl', 'Nette\Forms\Controls\ChoiceControl'],
|
||||
string $oldPropertyName = 'checkAllowedValues',
|
||||
string $newMethodName = 'checkDefaultValue'
|
||||
array $types,
|
||||
string $oldPropertyName,
|
||||
string $newMethodName
|
||||
) {
|
||||
$this->propertyFetchAnalyzer = $propertyFetchAnalyzer;
|
||||
$this->methodCallNodeFactory = $methodCallNodeFactory;
|
||||
|
@ -9,7 +9,6 @@ use Rector\Builder\StatementGlue;
|
||||
use Rector\Node\Attribute;
|
||||
use Rector\Node\NodeFactory;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
@ -65,9 +64,11 @@ class SomeClass
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
['$parentClassToTraits' => [
|
||||
'Nette\Object' => ['Nette\SmartObject']
|
||||
]]
|
||||
[
|
||||
'$parentClassToTraits' => [
|
||||
'Nette\Object' => ['Nette\SmartObject'],
|
||||
],
|
||||
]
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ use PhpParser\Node\Name\FullyQualified;
|
||||
use Rector\Node\Attribute;
|
||||
use Rector\Node\NodeFactory;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
@ -33,11 +32,8 @@ final class RenameClassConstantsUseToStringsRector extends AbstractRector
|
||||
/**
|
||||
* @param string[] $oldConstantToNewValue
|
||||
*/
|
||||
public function __construct(
|
||||
NodeFactory $nodeFactory,
|
||||
string $class,
|
||||
array $oldConstantToNewValue
|
||||
) {
|
||||
public function __construct(NodeFactory $nodeFactory, string $class, array $oldConstantToNewValue)
|
||||
{
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
$this->class = $class;
|
||||
$this->oldConstantToNewValue = $oldConstantToNewValue;
|
||||
@ -54,7 +50,7 @@ final class RenameClassConstantsUseToStringsRector extends AbstractRector
|
||||
'$oldConstantToNewValue' => [
|
||||
'DEVELOPMENT' => 'development',
|
||||
'PRODUCTION' => 'production',
|
||||
]
|
||||
],
|
||||
]
|
||||
),
|
||||
]);
|
||||
|
@ -8,6 +8,7 @@ use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Node\Attribute;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
/**
|
||||
@ -33,7 +34,7 @@ final class MergeInterfacesRector extends AbstractRector
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Merges old interface to a new one, that already has its methods', [
|
||||
new CodeSample(
|
||||
new ConfiguredCodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass implements SomeInterface, SomeOldInterface
|
||||
{
|
||||
@ -45,6 +46,11 @@ class SomeClass implements SomeInterface
|
||||
{
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, [
|
||||
'$oldToNewInterfaces' => [
|
||||
'SomeOldInterface' => 'SomeInterface'
|
||||
]
|
||||
]
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ use Rector\NodeAnalyzer\ExpressionAnalyzer;
|
||||
use Rector\NodeAnalyzer\PropertyFetchAnalyzer;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
final class GetAndSetToMethodCallRector extends AbstractRector
|
||||
@ -63,14 +64,28 @@ final class GetAndSetToMethodCallRector extends AbstractRector
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Turns defined `__get`/`__set` to specific method calls.', [
|
||||
new CodeSample(
|
||||
'$someService = $container->someService;',
|
||||
'$someService = $container->getService("someService");'
|
||||
),
|
||||
new CodeSample(
|
||||
new ConfiguredCodeSample(
|
||||
'$container->someService = $someService;',
|
||||
'$container->setService("someService", $someService);'
|
||||
'$container->setService("someService", $someService);',
|
||||
[
|
||||
'$typeToMethodCalls' => [
|
||||
'SomeContainer' => [
|
||||
'set' => 'addService',
|
||||
]
|
||||
]
|
||||
]
|
||||
),
|
||||
new ConfiguredCodeSample(
|
||||
'$someService = $container->someService;',
|
||||
'$someService = $container->getService("someService");',
|
||||
[
|
||||
'$typeToMethodCalls' => [
|
||||
'SomeContainer' => [
|
||||
'get' => 'getService',
|
||||
]
|
||||
]
|
||||
]
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
final class ToStringToMethodCallRector extends AbstractRector
|
||||
@ -67,8 +68,25 @@ final class ToStringToMethodCallRector extends AbstractRector
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Turns defined __toString() to specific method calls.', [
|
||||
new CodeSample('$result = (string) $someValue;', '$result = $someValue->someMethod();'),
|
||||
new CodeSample('$result = $someValue->__toString();', '$result = $someValue->someMethod();'),
|
||||
new ConfiguredCodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
$result = (string) $someValue;
|
||||
$result = $someValue->__toString();
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
$result = $someValue->someMethod();
|
||||
$result = $someValue->someMethod();
|
||||
CODE_SAMPLE
|
||||
,
|
||||
[
|
||||
'$typeToMethodCalls' => [
|
||||
'SomeObject' => [
|
||||
'toString' => 'getPath'
|
||||
]
|
||||
]
|
||||
]
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ use Rector\Node\MethodCallNodeFactory;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
final class UnsetAndIssetToMethodCallRector extends AbstractRector
|
||||
@ -54,8 +55,29 @@ final class UnsetAndIssetToMethodCallRector extends AbstractRector
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Turns defined `__isset`/`__unset` calls to specific method calls.', [
|
||||
new CodeSample('isset($container["someKey"]);', '$container->hasService("someKey");'),
|
||||
new CodeSample('unset($container["someKey"])', '$container->removeService("someKey");'),
|
||||
new ConfiguredCodeSample(
|
||||
'isset($container["someKey"]);',
|
||||
'$container->hasService("someKey");',
|
||||
[
|
||||
'$typeToMethodCalls' => [
|
||||
'Nette\DI\Container' => [
|
||||
'isset' => 'hasService',
|
||||
]
|
||||
]
|
||||
]
|
||||
),
|
||||
new ConfiguredCodeSample(
|
||||
'unset($container["someKey"])',
|
||||
'$container->removeService("someKey");',
|
||||
[
|
||||
[
|
||||
'$typeToMethodCalls' => [
|
||||
'Nette\DI\Container' => [
|
||||
'unset' => 'removeService'
|
||||
]
|
||||
]
|
||||
]
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ use Rector\Builder\IdentifierRenamer;
|
||||
use Rector\Node\NodeFactory;
|
||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
final class MethodCallToAnotherMethodCallWithArgumentsRector extends AbstractRector
|
||||
@ -55,10 +55,10 @@ final class MethodCallToAnotherMethodCallWithArgumentsRector extends AbstractRec
|
||||
MethodCallAnalyzer $methodCallAnalyzer,
|
||||
IdentifierRenamer $identifierRenamer,
|
||||
NodeFactory $nodeFactory,
|
||||
string $serviceDefinitionClass = 'Nette\DI\ServiceDefinition',
|
||||
string $oldMethod = 'setInject',
|
||||
string $newMethod = 'addTag',
|
||||
array $newMethodArguments = ['inject']
|
||||
string $serviceDefinitionClass,
|
||||
string $oldMethod,
|
||||
string $newMethod,
|
||||
array $newMethodArguments
|
||||
) {
|
||||
$this->methodCallAnalyzer = $methodCallAnalyzer;
|
||||
$this->identifierRenamer = $identifierRenamer;
|
||||
@ -72,7 +72,7 @@ final class MethodCallToAnotherMethodCallWithArgumentsRector extends AbstractRec
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Turns old method call with specfici type to new one with arguments', [
|
||||
new CodeSample(
|
||||
new ConfiguredCodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
$serviceDefinition = new Nette\DI\ServiceDefinition;
|
||||
$serviceDefinition->setInject();
|
||||
@ -82,7 +82,13 @@ CODE_SAMPLE
|
||||
$serviceDefinition = new Nette\DI\ServiceDefinition;
|
||||
$serviceDefinition->addTag('inject');
|
||||
CODE_SAMPLE
|
||||
),
|
||||
, [
|
||||
'$serviceDefinitionClass' => 'Nette\DI\ServiceDefinition',
|
||||
'$oldMethod' => 'setInject',
|
||||
'$newMethod' => 'addTag',
|
||||
'$newMethodArguments' => ['inject']
|
||||
]
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ use Rector\Node\Attribute;
|
||||
use Rector\NodeModifier\VisibilityModifier;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
final class ChangeConstantVisibilityRector extends AbstractRector
|
||||
@ -35,7 +36,7 @@ final class ChangeConstantVisibilityRector extends AbstractRector
|
||||
{
|
||||
return new RectorDefinition(
|
||||
'Change visibility of constant from parent class.',
|
||||
[new CodeSample(
|
||||
[new ConfiguredCodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class FrameworkClass
|
||||
{
|
||||
@ -59,7 +60,13 @@ class MyClass extends FrameworkClass
|
||||
protected const SOME_CONSTANT = 1;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]
|
||||
, [
|
||||
'Rector\Tests\Rector\Visibility\ChangeConstantVisibilityRector\Source\ParentObject' => [
|
||||
'$constantToVisibilityByClass' => [
|
||||
'SOME_CONSTANT' => 'protected'
|
||||
]
|
||||
]
|
||||
])]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,2 +1,5 @@
|
||||
services:
|
||||
Rector\Rector\Assign\PropertyAssignToMethodCallRector: ~
|
||||
Rector\Rector\Assign\PropertyAssignToMethodCallRector:
|
||||
$types: ['Nette\Forms\Controls\MultiChoiceControl', 'Nette\Forms\Controls\ChoiceControl']
|
||||
$oldPropertyName: 'checkAllowedValues'
|
||||
$newMethodName: 'checkDefaultValue'
|
||||
|
@ -1,3 +1,6 @@
|
||||
services:
|
||||
Rector\Rector\MethodCall\MethodCallToAnotherMethodCallWithArgumentsRector:
|
||||
$serviceDefinitionClass: 'Rector\Nette\Tests\Rector\DI\SetInjectToAddTagRector\Source\NetteServiceDefinition'
|
||||
$oldMethod: 'setInject'
|
||||
$newMethod: 'addTag'
|
||||
$newMethodArguments: ['inject']
|
||||
|
Loading…
x
Reference in New Issue
Block a user