use short config in code samples + update Rector overview

This commit is contained in:
Tomas Votruba 2018-11-11 13:22:35 +01:00
parent 9eb3057bc0
commit 0abecd8087
30 changed files with 1102 additions and 674 deletions

File diff suppressed because it is too large Load Diff

View File

@ -54,7 +54,7 @@ final class JmsInjectAnnotationRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition(
'Changes properties with @JMS\DiExtraBundle\Annotation\Inject to constructor injection',
'Changes properties with `@JMS\DiExtraBundle\Annotation\Inject` to constructor injection',
[
new CodeSample(
<<<'CODE_SAMPLE'

View File

@ -19,7 +19,7 @@ final class ExceptionHandlerTypehintRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition(
'Changes property @var annotations from annotation to type.',
'Changes property `@var` annotations from annotation to type.',
[
new CodeSample(
<<<'CODE_SAMPLE'

View File

@ -62,7 +62,7 @@ final class TypedPropertyRector extends AbstractRector
public function getDefinition(): RectorDefinition
{
return new RectorDefinition(
'Changes property @var annotations from annotation to type.',
'Changes property `@var` annotations from annotation to type.',
[
new CodeSample(
<<<'CODE_SAMPLE'

View File

@ -26,9 +26,9 @@ final class SensitiveHereNowDocRector extends AbstractRector
return new RectorDefinition('Changes heredoc/nowdoc that contains closing word to safe wrapper name', [
new CodeSample(
<<<'CODE_SAMPLE'
$value = <<<A
A
$value = <<<A
A
A
CODE_SAMPLE
,
<<<'CODE_SAMPLE'

View File

@ -53,7 +53,7 @@ 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',
'Turns `@Template` annotation to explicit method call in Controller of FrameworkExtraBundle in Symfony',
[
new CodeSample(
<<<'CODE_SAMPLE'

View File

@ -3,12 +3,14 @@
namespace Rector\Console;
use Jean85\PrettyVersions;
use Rector\Console\Command\GenerateRectorOverviewCommand;
use Symfony\Component\Console\Application as SymfonyApplication;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symplify\PackageBuilder\Console\Command\CommandNaming;
use function Safe\getcwd;
use function Safe\realpath;
@ -33,6 +35,11 @@ final class Application extends SymfonyApplication
{
$shouldFollowByNewline = false;
// skip in this case, since generate content must be clear from meta-info
if ($input->getFirstArgument() === CommandNaming::classToName(GenerateRectorOverviewCommand::class)) {
return parent::doRun($input, $output);
}
if ($this->isVersionPrintedElsewhere($input) === false) {
// always print name version to more debug info
$output->writeln($this->getLongVersion());

View File

@ -252,7 +252,9 @@ final class GenerateRectorOverviewCommand extends Command
$this->printCodeWrapped($diff, 'diff');
}
$this->symfonyStyle->newLine(1);
$this->symfonyStyle->newLine();
$this->symfonyStyle->writeln('<br>');
$this->symfonyStyle->newLine();
}
private function getRectorClassWithoutNamespace(RectorInterface $rector): string

View File

@ -68,10 +68,8 @@ class SomeTest extends PHPUnit\Framework\TestCase
CODE_SAMPLE
,
[
'$classToAnnotationMap' => [
'PHPUnit\Framework\TestCase' => [
'test' => 'scenario',
],
'PHPUnit\Framework\TestCase' => [
'test' => 'scenario',
],
]
),

View File

@ -39,7 +39,7 @@ final class AnnotatedPropertyInjectToConstructorInjectionRector extends Abstract
public function getDefinition(): RectorDefinition
{
return new RectorDefinition(
'Turns non-private properties with @annotation to private properties and constructor injection',
'Turns non-private properties with `@annotation` to private properties and constructor injection',
[
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'

View File

@ -51,14 +51,12 @@ $someObject->someMethod(false);'
CODE_SAMPLE
,
[
'$argumentChangesByMethodAndType' => [
'SomeExampleClass' => [
'someMethod' => [
0 => [
[
'before' => 'SomeClass::OLD_CONSTANT',
'after' => 'false',
],
'SomeExampleClass' => [
'someMethod' => [
0 => [
[
'before' => 'SomeClass::OLD_CONSTANT',
'after' => 'false',
],
],
],

View File

@ -51,9 +51,7 @@ function (SomeNewClass $someOldClass): SomeNewClass
CODE_SAMPLE
,
[
'$oldToNewClasses' => [
'SomeOldClass' => 'SomeNewClass',
],
'SomeOldClass' => 'SomeNewClass',
]
),
]);

View File

@ -56,9 +56,7 @@ class SomeClass
CODE_SAMPLE
,
[
'$parentClassToTraits' => [
'Nette\Object' => ['Nette\SmartObject'],
],
'Nette\Object' => ['Nette\SmartObject'],
]
),
]);

View File

@ -35,10 +35,8 @@ final class ClassConstantReplacerRector extends AbstractRector
'$value = SomeClass::OLD_CONSTANT;',
'$value = SomeClass::NEW_CONSTANT;',
[
'$oldToNewConstantsByClass' => [
'SomeClass' => [
'OLD_CONSTANT' => 'NEW_CONSTANT',
],
'SomeClass' => [
'OLD_CONSTANT' => 'NEW_CONSTANT',
],
]
),

View File

@ -31,9 +31,7 @@ final class FunctionReplaceRector extends AbstractRector
'view("...", []);',
'Laravel\Templating\render("...", []);',
[
'$functionToStaticCall' => [
'view' => 'Laravel\Templating\render',
],
'view' => 'Laravel\Templating\render',
]
),
]);

View File

@ -32,9 +32,7 @@ final class FunctionToMethodCallRector extends AbstractRector
'view("...", []);',
'$this->render("...", []);',
[
'$functionToMethodCall' => [
'view' => ['this', 'render'],
],
'view' => ['this', 'render'],
]
),
]);

View File

@ -33,9 +33,7 @@ final class FunctionToStaticCallRector extends AbstractRector
'view("...", []);',
'SomeClass::render("...", []);',
[
'$functionToStaticCall' => [
'view' => ['SomeStaticClass', 'render'],
],
'view' => ['SomeStaticClass', 'render'],
]
),
]);

View File

@ -47,9 +47,7 @@ class SomeClass implements SomeInterface
CODE_SAMPLE
,
[
'$oldToNewInterfaces' => [
'SomeOldInterface' => 'SomeInterface',
],
'SomeOldInterface' => 'SomeInterface',
]
),
]);

View File

@ -50,10 +50,8 @@ $container->setService("someService", $someService);
CODE_SAMPLE
,
[
'$typeToMethodCalls' => [
'SomeContainer' => [
'set' => 'addService',
],
'SomeContainer' => [
'set' => 'addService',
],
]
),

View File

@ -44,9 +44,7 @@ $result = $someValue->getPath();
CODE_SAMPLE
,
[
'$methodNamesByType' => [
'SomeObject' => 'getPath',
],
'SomeObject' => 'getPath',
]
),
]);

View File

@ -42,10 +42,8 @@ $container->hasService("someKey");
CODE_SAMPLE
,
[
'$typeToMethodCalls' => [
'SomeContainer' => [
'isset' => 'hasService',
],
'SomeContainer' => [
'isset' => 'hasService',
],
]
),
@ -61,12 +59,8 @@ $container->removeService("someKey");
CODE_SAMPLE
,
[
[
'$typeToMethodCalls' => [
'SomeContainer' => [
'unset' => 'removeService',
],
],
'SomeContainer' => [
'unset' => 'removeService',
],
]
),

View File

@ -39,9 +39,7 @@ $someClass->someFunction();
$someClass->otherFunction();
CODE_SAMPLE
,
[
'$classesToDefluent' => ['SomeExampleClass'],
]
[['SomeExampleClass']]
),
]);
}

View File

@ -47,9 +47,7 @@ $someObject->someFunction()
CODE_SAMPLE
,
[
'$fluentMethodsByType' => [
'SomeClass' => ['someFunction', 'otherFunction'],
],
'SomeClass' => ['someFunction', 'otherFunction'],
]
),
]);

View File

@ -65,9 +65,7 @@ class SomeClass
}
CODE_SAMPLE
,
[
'$classesToDefluent' => ['SomeExampleClass'],
]
[['SomeExampleClass']]
),
]);
}

View File

@ -43,10 +43,8 @@ $someObject->newMethod();
CODE_SAMPLE
,
[
'$perClassOldToNewMethods' => [
'SomeExampleClass' => [
'oldMethod' => 'newMethod',
],
'SomeExampleClass' => [
'oldMethod' => 'newMethod',
],
]
),

View File

@ -32,10 +32,8 @@ final class StaticMethodNameReplacerRector extends AbstractRector
'SomeClass::oldStaticMethod();',
'AnotherExampleClass::newStaticMethod();',
[
'$oldToNewMethodByClasses' => [
'SomeClass' => [
'oldMethod' => ['AnotherExampleClass', 'newStaticMethod'],
],
'SomeClass' => [
'oldMethod' => ['AnotherExampleClass', 'newStaticMethod'],
],
]
),

View File

@ -68,11 +68,9 @@ class SomeClass implements SomeInterface
CODE_SAMPLE
,
[
'$typehintForArgumentByMethodAndClass' => [
'SomeInterface' => [
'read' => [
'$content' => 'string',
],
'SomeInterface' => [
'read' => [
'$content' => 'string',
],
],
]

View File

@ -8,7 +8,6 @@ use Rector\PhpParser\Node\Maintainer\VisibilityMaintainer;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\ConfiguredCodeSample;
use Rector\RectorDefinition\RectorDefinition;
use Rector\Tests\Rector\Visibility\ChangeConstantVisibilityRector\Source\ParentObject;
final class ChangeConstantVisibilityRector extends AbstractRector
{
@ -61,10 +60,8 @@ class MyClass extends FrameworkClass
CODE_SAMPLE
,
[
ParentObject::class => [
'$constantToVisibilityByClass' => [
'SOME_CONSTANT' => 'protected',
],
'ParentObject' => [
'SOME_CONSTANT' => 'protected',
],
]
)]

View File

@ -69,10 +69,8 @@ class MyClass extends FrameworkClass
CODE_SAMPLE
,
[
'$methodToVisibilityByClass' => [
'FrameworkClass' => [
'someMethod' => 'protected',
],
'FrameworkClass' => [
'someMethod' => 'protected',
],
]
)]

View File

@ -61,10 +61,8 @@ class MyClass extends FrameworkClass
CODE_SAMPLE
,
[
'$propertyToVisibilityByClass' => [
'FrameworkClass' => [
'someProperty' => 'protected',
],
'FrameworkClass' => [
'someProperty' => 'protected',
],
]
)]