This commit is contained in:
Tomas Votruba 2018-04-08 16:05:11 +02:00
parent e0004ae7ba
commit 7e5a9a1002
47 changed files with 313 additions and 159 deletions

View File

@ -45,9 +45,15 @@ final class ExpandFunctionToStaticExpandFunctionRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns expand() to Nette\DI\Helpers::expand() value in Nette\DI\CompilerExtension', [
new CodeSample('$builder->expand(object|array)', '\Nette\DI\Helpers::expand(object|array, $builder->parameters);'),
]);
return new RectorDefinition(
'Turns expand() to Nette\DI\Helpers::expand() value in Nette\DI\CompilerExtension',
[
new CodeSample(
'$builder->expand(object|array)',
'\Nette\DI\Helpers::expand(object|array, $builder->parameters);'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -38,9 +38,15 @@ final class SetEntityToStatementRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns setDefinition() to Nette\DI\Helpers::expand() value in Nette\DI\CompilerExtension', [
new CodeSample('$definition->setEntity("someEntity");', '$definition = new Statement("someEntity", $definition->arguments);'),
]);
return new RectorDefinition(
'Turns setDefinition() to Nette\DI\Helpers::expand() value in Nette\DI\CompilerExtension',
[
new CodeSample(
'$definition->setEntity("someEntity");',
'$definition = new Statement("someEntity", $definition->arguments);'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -63,9 +63,12 @@ final class MagicMethodRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Catches @method annotations of Nette\Object instances and converts them to real methods.', [
new CodeSample('/** @method getId() */', 'public function getId() { $this->id; }'),
]);
return new RectorDefinition(
'Catches @method annotations of Nette\Object instances and converts them to real methods.',
[
new CodeSample('/** @method getId() */', 'public function getId() { $this->id; }'),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -41,7 +41,8 @@ final class DelegateExceptionArgumentsRector extends AbstractPHPUnitRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Takes setExpectedException() 2nd and next arguments to own methods in PHPUnit.', [
new CodeSample('$this->setExpectedException(Exception::class, "Message", "CODE");',
new CodeSample(
'$this->setExpectedException(Exception::class, "Message", "CODE");',
<<<'CODE_SAMPLE'
$this->setExpectedException(Exception::class);
$this->expectExceptionMessage("Message");

View File

@ -54,7 +54,8 @@ final class ExceptionAnnotationRector extends AbstractPHPUnitRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Takes setExpectedException() 2nd and next arguments to own methods in PHPUnit.', [
new CodeSample('$this->setExpectedException(Exception::class, "Message", "CODE");',
new CodeSample(
'$this->setExpectedException(Exception::class, "Message", "CODE");',
<<<'CODE_SAMPLE'
$this->setExpectedException(Exception::class);
$this->expectExceptionMessage("Message");

View File

@ -32,7 +32,7 @@ final class GetMockRector extends AbstractPHPUnitRector
{
return new RectorDefinition('Turns getMock*() methods to createMock()', [
new CodeSample('$this->getMock("Class")', '$this->createMock("Class")'),
new CodeSample('$this->getMockWithoutInvokingTheOriginalConstructor("Class")', '$this->createMock("Class"')
new CodeSample('$this->getMockWithoutInvokingTheOriginalConstructor("Class")', '$this->createMock("Class"'),
]);
}

View File

@ -50,12 +50,27 @@ final class AssertCompareToSpecificMethodRector extends AbstractPHPUnitRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns vague php-only method in PHPUnit Test Case to more specific', [
new CodeSample('$this->assertSame(10, count($anything), "message");', '$this->assertCount(10, $anything, "message");'),
new CodeSample('$this->assertSame($value, {function}($anything), "message");', '$this->assert{function}($value, $anything, "message\");'),
new CodeSample('$this->assertEquals($value, {function}($anything), "message");', '$this->assert{function}($value, $anything, "message\");'),
new CodeSample(
'$this->assertSame(10, count($anything), "message");',
'$this->assertCount(10, $anything, "message");'
),
new CodeSample(
'$this->assertSame($value, {function}($anything), "message");',
'$this->assert{function}($value, $anything, "message\");'
),
new CodeSample(
'$this->assertEquals($value, {function}($anything), "message");',
'$this->assert{function}($value, $anything, "message\");'
),
new CodeSample('$this->assertNotSame($value, {function}($anything), "message");', '$this->assertNot{function}($value, $anything, "message")'),
new CodeSample('$this->assertNotEquals($value, {function}($anything), "message");', '$this->assertNot{function}($value, $anything, "message")'),
new CodeSample(
'$this->assertNotSame($value, {function}($anything), "message");',
'$this->assertNot{function}($value, $anything, "message")'
),
new CodeSample(
'$this->assertNotEquals($value, {function}($anything), "message");',
'$this->assertNot{function}($value, $anything, "message")'
),
]);
}

View File

@ -54,7 +54,10 @@ final class AssertComparisonToSpecificMethodRector extends AbstractPHPUnitRector
{
return new RectorDefinition('Turns === comparisons to their method name alternatives in PHPUnit Test Case', [
new CodeSample('$this->assertTrue($foo === $bar, "message");', '$this->assertSame($bar, $foo, "message");'),
new CodeSample('$this->assertFalse($foo >= $bar, "message");', '$this->assertLessThanOrEqual($bar, $foo, "message");'),
new CodeSample(
'$this->assertFalse($foo >= $bar, "message");',
'$this->assertLessThanOrEqual($bar, $foo, "message");'
),
]);
}

View File

@ -42,10 +42,19 @@ final class AssertFalseStrposToContainsRector extends AbstractPHPUnitRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns strpos()/stripos() comparisons to their method name alternatives in PHPUnit Test Case', [
new CodeSample('$this->assertFalse(strpos($anything, "foo"), "message");', '$this->assertNotContains("foo", $anything, "message");'),
new CodeSample('$this->assertNotFalse(stripos($anything, "foo"), "message");', '$this->assertContains("foo", $anything, "message");'),
]);
return new RectorDefinition(
'Turns strpos()/stripos() comparisons to their method name alternatives in PHPUnit Test Case',
[
new CodeSample(
'$this->assertFalse(strpos($anything, "foo"), "message");',
'$this->assertNotContains("foo", $anything, "message");'
),
new CodeSample(
'$this->assertNotFalse(stripos($anything, "foo"), "message");',
'$this->assertContains("foo", $anything, "message");'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -49,10 +49,19 @@ final class AssertInstanceOfComparisonRector extends AbstractPHPUnitRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns instanceof comparisons to their method name alternatives in PHPUnit Test Case', [
new CodeSample('$this->assertTrue($foo instanceof Foo, "message");', '$this->assertFalse($foo instanceof Foo, "message");'),
new CodeSample('$this->assertInstanceOf("Foo", $foo, "message");', '$this->assertNotInstanceOf("Foo", $foo, "message");'),
]);
return new RectorDefinition(
'Turns instanceof comparisons to their method name alternatives in PHPUnit Test Case',
[
new CodeSample(
'$this->assertTrue($foo instanceof Foo, "message");',
'$this->assertFalse($foo instanceof Foo, "message");'
),
new CodeSample(
'$this->assertInstanceOf("Foo", $foo, "message");',
'$this->assertNotInstanceOf("Foo", $foo, "message");'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -44,8 +44,14 @@ final class AssertIssetToSpecificMethodRector extends AbstractPHPUnitRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns isset comparisons to their method name alternatives in PHPUnit Test Case', [
new CodeSample('$this->assertTrue(isset($anything->foo));', '$this->assertFalse(isset($anything["foo"]), "message");'),
new CodeSample('$this->assertObjectHasAttribute("foo", $anything);', '$this->assertArrayNotHasKey("foo", $anything, "message");'),
new CodeSample(
'$this->assertTrue(isset($anything->foo));',
'$this->assertFalse(isset($anything["foo"]), "message");'
),
new CodeSample(
'$this->assertObjectHasAttribute("foo", $anything);',
'$this->assertArrayNotHasKey("foo", $anything, "message");'
),
]);
}

View File

@ -39,10 +39,13 @@ final class AssertNotOperatorRector extends AbstractPHPUnitRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns not-operator comparisons to their method name alternatives in PHPUnit Test Case', [
new CodeSample('$this->assertTrue(!$foo, "message");', '$this->assertFalse($foo, "message");'),
new CodeSample('$this->assertFalse(!$foo, "message");', '$this->assertTrue($foo, "message");'),
]);
return new RectorDefinition(
'Turns not-operator comparisons to their method name alternatives in PHPUnit Test Case',
[
new CodeSample('$this->assertTrue(!$foo, "message");', '$this->assertFalse($foo, "message");'),
new CodeSample('$this->assertFalse(!$foo, "message");', '$this->assertTrue($foo, "message");'),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -52,10 +52,19 @@ final class AssertPropertyExistsRector extends AbstractPHPUnitRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns property_exists() comparisons to their method name alternatives in PHPUnit Test Case', [
new CodeSample('$this->assertTrue(property_exists(new Class, "property"), "message");', '$this->assertClassHasAttribute("property", "Class", "message");'),
new CodeSample('$this->assertFalse(property_exists(new Class, "property"), "message");', '$this->assertClassNotHasAttribute("property", "Class", "message");'),
]);
return new RectorDefinition(
'Turns property_exists() comparisons to their method name alternatives in PHPUnit Test Case',
[
new CodeSample(
'$this->assertTrue(property_exists(new Class, "property"), "message");',
'$this->assertClassHasAttribute("property", "Class", "message");'
),
new CodeSample(
'$this->assertFalse(property_exists(new Class, "property"), "message");',
'$this->assertClassNotHasAttribute("property", "Class", "message");'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -46,10 +46,13 @@ final class AssertSameBoolNullToSpecificMethodRector extends AbstractPHPUnitRect
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns same with null comparisons to their method name alternatives in PHPUnit Test Case', [
new CodeSample('$this->assertSame(null, $anything);', '$this->assertNull($anything);'),
new CodeSample('$this->assertNotSame(false, $anything);', '$this->assertNotFalse($anything);'),
]);
return new RectorDefinition(
'Turns same with null comparisons to their method name alternatives in PHPUnit Test Case',
[
new CodeSample('$this->assertSame(null, $anything);', '$this->assertNull($anything);'),
new CodeSample('$this->assertNotSame(false, $anything);', '$this->assertNotFalse($anything);'),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -71,10 +71,19 @@ final class AssertTrueFalseInternalTypeToSpecificMethodRector extends AbstractPH
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns true/false with is_internal() comparisons to their method name alternatives in PHPUnit Test Case', [
new CodeSample('$this->assertTrue(is_{internal_type}($anything), "message");', '$this->assertInternalType({internal_type}, $anything, "message");'),
new CodeSample('$this->assertFalse(is_{internal_type}($anything), "message");', '$this->assertNotInternalType({internal_type}, $anything, "message");'),
]);
return new RectorDefinition(
'Turns true/false with is_internal() comparisons to their method name alternatives in PHPUnit Test Case',
[
new CodeSample(
'$this->assertTrue(is_{internal_type}($anything), "message");',
'$this->assertInternalType({internal_type}, $anything, "message");'
),
new CodeSample(
'$this->assertFalse(is_{internal_type}($anything), "message");',
'$this->assertNotInternalType({internal_type}, $anything, "message");'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -77,9 +77,15 @@ final class AssertTrueFalseToSpecificMethodRector extends AbstractPHPUnitRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns true/false comparisons to their method name alternatives in PHPUnit Test Case', [
new CodeSample('$this->assertTrue(is_readable($readmeFile), "message");', '$this->assertIsReadable($readmeFile, "message");'),
]);
return new RectorDefinition(
'Turns true/false comparisons to their method name alternatives in PHPUnit Test Case',
[
new CodeSample(
'$this->assertTrue(is_readable($readmeFile), "message");',
'$this->assertIsReadable($readmeFile, "message");'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -75,7 +75,7 @@ final class IdentifierRector extends AbstractRector
new CodeSample(
'$constNode = new \PhpParser\Node\Const_; $name = $constNode->name;',
'$constNode = new \PhpParser\Node\Const_; $name = $constNode->name->toString();'
)
),
]);
}

View File

@ -35,10 +35,13 @@ final class UseWithAliasRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns use property to method and $node->alias to last name in UseAlias Node of PHP-Parser', [
new CodeSample('$node->alias;', '$node->getAlias();'),
new CodeSample('$node->name->getLast();', '$node->alias'),
]);
return new RectorDefinition(
'Turns use property to method and $node->alias to last name in UseAlias Node of PHP-Parser',
[
new CodeSample('$node->alias;', '$node->getAlias();'),
new CodeSample('$node->name->getLast();', '$node->alias'),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -68,11 +68,16 @@ final class TemplateAnnotationRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns @Template annotation to explicit method call in Controller of FrameworkExtraBundle in Symfony', [
new CodeSample(
'/** @Template() */ public function indexAction() { }', 'public function indexAction() {
return $this->render("index.html.twig"); }'),
]);
return new RectorDefinition(
'Turns @Template annotation to explicit method call in Controller of FrameworkExtraBundle in Symfony',
[
new CodeSample(
'/** @Template() */ public function indexAction() { }',
'public function indexAction() {
return $this->render("index.html.twig"); }'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -40,9 +40,15 @@ final class ReplaceCreateMethodWithoutReviewerRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns createForSubjectWithReviewer() with null review to standalone method in Sylius', [
new CodeSample('$this->createForSubjectWithReviewer($subject, null)', '$this->createForSubject($subject)'),
]);
return new RectorDefinition(
'Turns createForSubjectWithReviewer() with null review to standalone method in Sylius',
[
new CodeSample(
'$this->createForSubjectWithReviewer($subject, null)',
'$this->createForSubject($subject)'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -43,7 +43,10 @@ final class ConsoleExceptionToErrorEventConstantRector extends AbstractRector
{
return new RectorDefinition('Turns old event name with EXCEPTION to ERROR constant in Console in Symfony', [
new CodeSample('"console.exception"', 'Symfony\Component\Console\ConsoleEvents::ERROR'),
new CodeSample('Symfony\Component\Console\ConsoleEvents::EXCEPTION', 'Symfony\Component\Console\ConsoleEvents::ERROR'),
new CodeSample(
'Symfony\Component\Console\ConsoleEvents::EXCEPTION',
'Symfony\Component\Console\ConsoleEvents::ERROR'
),
]);
}

View File

@ -30,12 +30,15 @@ final class ContainerBuilderCompileEnvArgumentRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns old default value to parameter in ContinerBuilder->build() method in DI in Symfony', [
new CodeSample(
'$containerBuilder = new Symfony\Component\DependencyInjection\ContainerBuilder(); $containerBuilder->compile();',
'$containerBuilder = new Symfony\Component\DependencyInjection\ContainerBuilder(); $containerBuilder->compile(true);'
),
]);
return new RectorDefinition(
'Turns old default value to parameter in ContinerBuilder->build() method in DI in Symfony',
[
new CodeSample(
'$containerBuilder = new Symfony\Component\DependencyInjection\ContainerBuilder(); $containerBuilder->compile();',
'$containerBuilder = new Symfony\Component\DependencyInjection\ContainerBuilder(); $containerBuilder->compile(true);'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -33,12 +33,15 @@ final class FormIsValidRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Adds $form->isSubmitted() validatoin to all $form->isValid() calls in Form in Symfony', [
new CodeSample(
'if ($form->isValid()) { ... };',
'if ($form->isSubmitted() && $form->isValid()) { ... };'
),
]);
return new RectorDefinition(
'Adds $form->isSubmitted() validatoin to all $form->isValid() calls in Form in Symfony',
[
new CodeSample(
'if ($form->isValid()) { ... };',
'if ($form->isSubmitted() && $form->isValid()) { ... };'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -31,16 +31,19 @@ final class FormTypeGetParentRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns string Form Type references to their CONSTANT alternatives in getParent() and getExtendedType() methods in Form in Symfony', [
new CodeSample(
'function getParent() { return "collection"; }',
'function getParent() { return CollectionType::class; }'
),
new CodeSample(
'function getExtendedType() { return "collection"; }',
'function getExtendedType() { return CollectionType::class; }'
)
]);
return new RectorDefinition(
'Turns string Form Type references to their CONSTANT alternatives in getParent() and getExtendedType() methods in Form in Symfony',
[
new CodeSample(
'function getParent() { return "collection"; }',
'function getParent() { return CollectionType::class; }'
),
new CodeSample(
'function getExtendedType() { return "collection"; }',
'function getExtendedType() { return CollectionType::class; }'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -38,7 +38,7 @@ final class OptionNameRector extends AbstractRector
new CodeSample(
'$builder->add("...", ["precision" => "...", "virtual" => "..."];',
'$builder->add("...", ["scale" => "...", "inherit_data" => "..."];'
)
),
]);
}

View File

@ -34,12 +34,15 @@ final class StringFormTypeToClassRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns string Form Type references to their CONSTANT alternatives in FormTypes in Form in Symfony', [
new CodeSample(
'$form->add("name", "form.type.text");',
'$form->add("name", \Symfony\Component\Form\Extension\Core\Type\TextType::class);'
)
]);
return new RectorDefinition(
'Turns string Form Type references to their CONSTANT alternatives in FormTypes in Form in Symfony',
[
new CodeSample(
'$form->add("name", "form.type.text");',
'$form->add("name", \Symfony\Component\Form\Extension\Core\Type\TextType::class);'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -22,8 +22,10 @@ final class ContainerGetToConstructorInjectionRector extends AbstractToConstruct
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns fetching of dependencies via $container->get() in ContainerAware to constructor injection in Command and Controller in Symfony', [
new CodeSample(
return new RectorDefinition(
'Turns fetching of dependencies via $container->get() in ContainerAware to constructor injection in Command and Controller in Symfony',
[
new CodeSample(
<<<'CODE_SAMPLE'
class MyCommand extends ContainerAwareCommand
{
@ -35,7 +37,7 @@ class MyCommand extends ContainerAwareCommand
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class MyCommand extends Command
{
@ -52,8 +54,9 @@ class MyCommand extends Command
}
}
CODE_SAMPLE
)
]);
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -50,8 +50,10 @@ final class GetParameterToConstructorInjectionRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns fetching of parmaters via getParmaeter() in ContainerAware to constructor injection in Command and Controller in Symfony', [
new CodeSample(
return new RectorDefinition(
'Turns fetching of parmaters via getParmaeter() in ContainerAware to constructor injection in Command and Controller in Symfony',
[
new CodeSample(
<<<'CODE_SAMPLE'
class MyCommand extends ContainerAwareCommand
{
@ -61,7 +63,7 @@ class MyCommand extends ContainerAwareCommand
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class MyCommand extends Command
{
@ -78,8 +80,9 @@ class MyCommand extends Command
}
}
CODE_SAMPLE
)
]);
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -11,9 +11,11 @@ final class GetToConstructorInjectionRector extends AbstractToConstructorInjecti
{
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns fetching of dependencies via $this->get() to constructor injection in Command and Controller in Symfony', [
new CodeSample(
<<<'CODE_SAMPLE'
return new RectorDefinition(
'Turns fetching of dependencies via $this->get() to constructor injection in Command and Controller in Symfony',
[
new CodeSample(
<<<'CODE_SAMPLE'
class MyCommand extends ContainerAwareCommand
{
public function someMethod()
@ -23,8 +25,8 @@ class MyCommand extends ContainerAwareCommand
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
,
<<<'CODE_SAMPLE'
class MyCommand extends Command
{
public function __construct(SomeService $someService)
@ -38,8 +40,9 @@ class MyCommand extends Command
}
}
CODE_SAMPLE
)
]);
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -62,9 +62,11 @@ final class GetRequestRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns fetching of dependencies via $this->get() to constructor injection in Command and Controller in Symfony', [
new CodeSample(
<<<'CODE_SAMPLE'
return new RectorDefinition(
'Turns fetching of dependencies via $this->get() to constructor injection in Command and Controller in Symfony',
[
new CodeSample(
<<<'CODE_SAMPLE'
class MyCommand extends ContainerAwareCommand
{
public function someMethod()
@ -74,8 +76,8 @@ class MyCommand extends ContainerAwareCommand
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
,
<<<'CODE_SAMPLE'
class MyCommand extends Command
{
public function __construct(SomeService $someService)
@ -89,8 +91,9 @@ class MyCommand extends Command
}
}
CODE_SAMPLE
)
]);
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -23,21 +23,24 @@ final class ProcessBuilderGetProcessRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Removes $processBuilder->getProcess() calls to $processBuilder in Process in Symfony, because ProcessBuilder was removed. This is part of multi-step Rector and has very narrow focus.', [
new CodeSample(
<<<'CODE_SAMPLE'
return new RectorDefinition(
'Removes $processBuilder->getProcess() calls to $processBuilder in Process in Symfony, because ProcessBuilder was removed. This is part of multi-step Rector and has very narrow focus.',
[
new CodeSample(
<<<'CODE_SAMPLE'
$processBuilder = new Symfony\Component\Process\ProcessBuilder;
$process = $processBuilder->getProcess();
$commamdLine = $processBuilder->getProcess()->getCommandLine();
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
,
<<<'CODE_SAMPLE'
$processBuilder = new Symfony\Component\Process\ProcessBuilder;
$process = $processBuilder;
$commamdLine = $processBuilder->getCommandLine();
CODE_SAMPLE
)
]);
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -24,9 +24,15 @@ final class ProcessBuilderInstanceRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Turns ProcessBuilder::instance() to new ProcessBuilder in Process in Symfony. Part of multi-step Rector.', [
new CodeSample('$processBuilder = Symfony\Component\Process\ProcessBuilder::instance($args);', '$processBuilder = new Symfony\Component\Process\ProcessBuilder($args);')
]);
return new RectorDefinition(
'Turns ProcessBuilder::instance() to new ProcessBuilder in Process in Symfony. Part of multi-step Rector.',
[
new CodeSample(
'$processBuilder = Symfony\Component\Process\ProcessBuilder::instance($args);',
'$processBuilder = new Symfony\Component\Process\ProcessBuilder($args);'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -37,7 +37,7 @@ final class ConstraintUrlOptionRector extends AbstractRector
new CodeSample(
'$constraint = new Url(["checkDNS" => true]);',
'$constraint = new Url(["checkDNS" => Url::CHECK_DNS_TYPE_ANY]);'
)
),
]);
}

View File

@ -37,16 +37,19 @@ final class VarDumperTestTraitMethodArgsRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Adds new $format argument in VarDumperTestTrait->assertDumpEquals() in in Validator in Symfony.', [
new CodeSample(
'VarDumperTestTrait->assertDumpEquals($dump, $data, $mesage = "");',
'VarDumperTestTrait->assertDumpEquals($dump, $data, $context = null, $mesage = "");'
),
new CodeSample(
'VarDumperTestTrait->assertDumpMatchesFormat($dump, $format, $mesage = "");',
'VarDumperTestTrait->assertDumpMatchesFormat($dump, $format, $context = null, $mesage = "");'
)
]);
return new RectorDefinition(
'Adds new $format argument in VarDumperTestTrait->assertDumpEquals() in in Validator in Symfony.',
[
new CodeSample(
'VarDumperTestTrait->assertDumpEquals($dump, $data, $mesage = "");',
'VarDumperTestTrait->assertDumpEquals($dump, $data, $context = null, $mesage = "");'
),
new CodeSample(
'VarDumperTestTrait->assertDumpMatchesFormat($dump, $format, $mesage = "");',
'VarDumperTestTrait->assertDumpMatchesFormat($dump, $format, $context = null, $mesage = "");'
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -39,14 +39,17 @@ final class AnnotationReplacerRector extends AbstractPHPUnitRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('[Dynamic] Turns defined annotations above properties and methods to their new values.', [
new CodeSample(
'/** @test */
return new RectorDefinition(
'[Dynamic] Turns defined annotations above properties and methods to their new values.',
[
new CodeSample(
'/** @test */
public function someMethod() {};',
'/** @scenario */
'/** @scenario */
public function someMethod() {};'
)
]);
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -72,14 +72,17 @@ final class ArgumentReplacerRector extends AbstractRector
*/
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('[Dynamic] Adds, removes or replaces defined arguments in defined methods and their calls.', [
new CodeSample(
'$containerBuilder = new Symfony\Component\DependencyInjection\ContainerBuilder;
return new RectorDefinition(
'[Dynamic] Adds, removes or replaces defined arguments in defined methods and their calls.',
[
new CodeSample(
'$containerBuilder = new Symfony\Component\DependencyInjection\ContainerBuilder;
$containerBuilder->compile();',
'$containerBuilder = new Symfony\Component\DependencyInjection\ContainerBuilder;
'$containerBuilder = new Symfony\Component\DependencyInjection\ContainerBuilder;
$containerBuilder->compile(true);'
)
]);
),
]
);
}
public function isCandidate(Node $node): bool

View File

@ -56,7 +56,7 @@ final class ClassConstantReplacerRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('[Dynamic] Replaces defined class constants in their calls.', [
new CodeSample('$value = SomeClass::OLD_CONSTANT;','$value = SomeClass::NEW_CONSTANT;')
new CodeSample('$value = SomeClass::OLD_CONSTANT;', '$value = SomeClass::NEW_CONSTANT;'),
]);
}

View File

@ -32,7 +32,7 @@ final class ClassReplacerRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('[Dynamic] Replaces defined classes by new ones.', [
new CodeSample('$value = new SomeOldClass;','$value = new SomeNewClass;')
new CodeSample('$value = new SomeOldClass;', '$value = new SomeNewClass;'),
]);
}

View File

@ -64,7 +64,7 @@ final class FluentReplaceRector extends AbstractRector
->otherFunction();
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
<<<'CODE_SAMPLE'
class SomeClass
{
public function someFunction()
@ -80,7 +80,7 @@ CODE_SAMPLE
$someClass->someFunction();
$someClass->otherFunction();
CODE_SAMPLE
)
),
]);
}

View File

@ -35,7 +35,7 @@ final class FunctionToMethodCallRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('[Dynamic] Turns defined function calls to local method calls.', [
new CodeSample('view("...", []);', '$this->render("...", []);')
new CodeSample('view("...", []);', '$this->render("...", []);'),
]);
}

View File

@ -34,7 +34,10 @@ final class NamespaceReplacerRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('[Dynamic] Replaces old namespace by new one.', [
new CodeSample('$someObject = new SomeOldNamespace\SomeClass;', '$someObject = new SomeNewNamespace\SomeClass;'),
new CodeSample(
'$someObject = new SomeOldNamespace\SomeClass;',
'$someObject = new SomeNewNamespace\SomeClass;'
),
]);
}

View File

@ -73,7 +73,7 @@ CODE_SAMPLE
$result = $object->getProperty();
$object->setProperty($value);
CODE_SAMPLE
),
),
]);
}

View File

@ -60,7 +60,7 @@ final class PseudoNamespaceToNamespaceRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('[Dynamic] Replaces defined Pseudo_Namespaces by Namespace\Ones.', [
new CodeSample('$someServie = Some_Object;', '$someServie = Some\Object;')
new CodeSample('$someServie = Some_Object;', '$someServie = Some\Object;'),
]);
}

View File

@ -50,7 +50,7 @@ final class ValueObjectRemoverRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('[Dynamic] Remove values objects and use directly the value.', [
new CodeSample('$someValue = new SomeValueObject("just_a_string");', '$someValue = "just_a_string";')
new CodeSample('$someValue = new SomeValueObject("just_a_string");', '$someValue = "just_a_string";'),
]);
}

View File

@ -64,7 +64,10 @@ final class GetAndSetToMethodCallRector extends AbstractRector
{
return new RectorDefinition('[Dynamic] Turns defined __get/__set to specific method calls.', [
new CodeSample('$someService = $container->someService;', '$container->getService("someService");'),
new CodeSample('$container->someService = $someService;', '$container->setService("someService", $someService);')
new CodeSample(
'$container->someService = $someService;',
'$container->setService("someService", $someService);'
),
]);
}

View File

@ -68,7 +68,7 @@ final class ToStringToMethodCallRector extends AbstractRector
{
return new RectorDefinition('[Dynamic] Turns defined __toString() to specific method calls.', [
new CodeSample('$result = (string) $someValue;', '$result = $someValue->someMethod();'),
new CodeSample('$result = $someValue->__toString();', '$result = $someValue->someMethod();')
new CodeSample('$result = $someValue->__toString();', '$result = $someValue->someMethod();'),
]);
}

View File

@ -55,7 +55,7 @@ final class UnsetAndIssetToMethodCallRector extends AbstractRector
{
return new RectorDefinition('[Dynamic] 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 CodeSample('unset($container["someKey"])', '$container->removeService("someKey");'),
]);
}