mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-30 07:50:53 +00:00
[Symplify 9] First update + switch to RuleDocGenerator (#4616)
* [composer] bump to Symplify 9 * [Symplify 9] Update phpstan rules * bump to Symplify 9 BETA2 * update AbstractKernel from Tests to Testing namespace * decoupling removing node trait * remove fluent calls * removing variadic * [CodingStyle] Improve AnnotateThrowablesRector * bump deps * Make use of RuleDocGenerator * first short * [DocumentationGenerator] Drop deprecated package, RuleSetGenerator now handles it * import namespace * update docs
This commit is contained in:
parent
7b0cfd56da
commit
a7705ed0a5
|
@ -109,11 +109,8 @@ vendor/bin/rector init
|
|||
And modify it:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
// rector.php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Php74\Rector\Property\TypedPropertyRector;
|
||||
|
@ -152,11 +149,8 @@ vendor/bin/rector process src
|
|||
## Full Config Configuration
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
// rector.php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
@ -197,11 +191,8 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
To work with some Symfony rules, you now need to link your container XML file
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
// rector.php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
|
|
@ -32,13 +32,13 @@
|
|||
"symfony/finder": "^4.4.8|^5.1",
|
||||
"symfony/http-kernel": "^4.4.8|^5.1",
|
||||
"symfony/process": "^4.4.8|^5.1",
|
||||
"symplify/autowire-array-parameter": "^8.3.48",
|
||||
"symplify/composer-json-manipulator": "^8.3.48",
|
||||
"symplify/console-color-diff": "^8.3.48",
|
||||
"symplify/easy-testing": "^8.3.48",
|
||||
"symplify/package-builder": "^8.3.48",
|
||||
"symplify/set-config-resolver": "^8.3.48",
|
||||
"symplify/smart-file-system": "^8.3.48",
|
||||
"symplify/autowire-array-parameter": "dev-master",
|
||||
"symplify/composer-json-manipulator": "dev-master",
|
||||
"symplify/console-color-diff": "dev-master",
|
||||
"symplify/package-builder": "dev-master",
|
||||
"symplify/set-config-resolver": "dev-master",
|
||||
"symplify/smart-file-system": "dev-master",
|
||||
"symplify/rule-doc-generator": "dev-master",
|
||||
"webmozart/assert": "^1.9"
|
||||
},
|
||||
"require-dev": {
|
||||
|
@ -52,11 +52,14 @@
|
|||
"php-parallel-lint/php-parallel-lint": "^1.2",
|
||||
"phpunit/phpunit": "^8.5|^9.2",
|
||||
"psr/event-dispatcher": "^1.0",
|
||||
"symplify/changelog-linker": "^8.3.48",
|
||||
"symplify/easy-coding-standard": "^8.3.48",
|
||||
"symplify/easy-testing": "^8.3.48",
|
||||
"symplify/monorepo-builder": "^8.3.48",
|
||||
"symplify/phpstan-extensions": "^8.3.48",
|
||||
"symplify/changelog-linker": "dev-master",
|
||||
"symplify/easy-coding-standard": "dev-master",
|
||||
"symplify/coding-standard": "dev-master",
|
||||
"symplify/easy-testing": "dev-master",
|
||||
"symplify/monorepo-builder": "dev-master",
|
||||
"symplify/phpstan-extensions": "dev-master",
|
||||
"symplify/markdown-diff": "dev-master",
|
||||
"symplify/phpstan-rules": "dev-master",
|
||||
"tracy/tracy": "^2.7"
|
||||
},
|
||||
"replace": {
|
||||
|
@ -87,7 +90,6 @@
|
|||
"Rector\\DoctrineCodeQuality\\": "rules/doctrine-code-quality/src",
|
||||
"Rector\\DoctrineGedmoToKnplabs\\": "rules/doctrine-gedmo-to-knplabs/src",
|
||||
"Rector\\Doctrine\\": "rules/doctrine/src",
|
||||
"Rector\\DocumentationGenerator\\": "packages/documentation-generator/src",
|
||||
"Rector\\DowngradePhp71\\": "rules/downgrade-php71/src",
|
||||
"Rector\\DowngradePhp72\\": "rules/downgrade-php72/src",
|
||||
"Rector\\DowngradePhp73\\": "rules/downgrade-php73/src",
|
||||
|
@ -215,7 +217,6 @@
|
|||
"Rector\\DoctrineCodeQuality\\Tests\\": "rules/doctrine-code-quality/tests",
|
||||
"Rector\\DoctrineGedmoToKnplabs\\Tests\\": "rules/doctrine-gedmo-to-knplabs/tests",
|
||||
"Rector\\Doctrine\\Tests\\": "rules/doctrine/tests",
|
||||
"Rector\\DocumentationGenerator\\Tests\\": "packages/documentation-generator/tests",
|
||||
"Rector\\DowngradePhp71\\Tests\\": "rules/downgrade-php71/tests",
|
||||
"Rector\\DowngradePhp72\\Tests\\": "rules/downgrade-php72/tests",
|
||||
"Rector\\DowngradePhp73\\Tests\\": "rules/downgrade-php73/tests",
|
||||
|
@ -284,7 +285,6 @@
|
|||
"Rector\\Twig\\Tests\\": "rules/twig/tests",
|
||||
"Rector\\TypeDeclaration\\Tests\\": "rules/type-declaration/tests",
|
||||
"Rector\\Utils\\DoctrineAnnotationParserSyncer\\": "utils/doctrine-annotation-parser-syncer/src",
|
||||
"Rector\\Utils\\DocumentationGenerator\\": "utils/node-documentation-generator/src",
|
||||
"Rector\\Utils\\NodeDocumentationGenerator\\": "utils/node-documentation-generator/src",
|
||||
"Rector\\Utils\\NodeDocumentationGenerator\\Tests\\": "utils/node-documentation-generator/tests",
|
||||
"Rector\\Utils\\PHPStanAttributeTypeSyncer\\": "utils/phpstan-attribute-type-syncer/src",
|
||||
|
@ -316,9 +316,9 @@
|
|||
"vendor/bin/changelog-linker cleanup --ansi"
|
||||
],
|
||||
"docs": [
|
||||
"bin/rector dump-rectors --output-file docs/rector_rules_overview.md --ansi",
|
||||
"vendor/bin/ecs check-markdown docs/rector_rules_overview.md --ansi --fix",
|
||||
"bin/rector dump-nodes --output-file docs/nodes_overview.md --ansi"
|
||||
"vendor/bin/rule-doc-generator generate packages rules --output-file docs/rector_rules_overview.md --ansi",
|
||||
"bin/rector dump-nodes --output-file docs/nodes_overview.md --ansi",
|
||||
"vendor/bin/ecs check-markdown docs/rector_rules_overview.md docs/nodes_overview.md --ansi --fix"
|
||||
],
|
||||
"rector-ci": "bin/rector process --config rector-ci.php --dry-run --ansi",
|
||||
"rector": "bin/rector process --config rector-ci.php --ansi",
|
||||
|
@ -338,5 +338,7 @@
|
|||
"patches/nette-application-src-application-ui-presenter-php.patch"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
$services->load('Rector\Core\\', __DIR__ . '/../src')
|
||||
->exclude([
|
||||
__DIR__ . '/../src/Rector',
|
||||
__DIR__ . '/../src/RectorDefinition',
|
||||
__DIR__ . '/../src/Exception',
|
||||
__DIR__ . '/../src/DependencyInjection/CompilerPass',
|
||||
__DIR__ . '/../src/DependencyInjection/Loader',
|
||||
|
|
|
@ -70,7 +70,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
$services->set(RenameMethodRector::class)
|
||||
->call('configure', [[
|
||||
RenameMethodRector::METHOD_CALL_RENAMES => inline_value_objects([
|
||||
// class loader
|
||||
|
||||
new MethodCallRename(
|
||||
'Symfony\Component\ClassLoader\UniversalClassLoader\UniversalClassLoader',
|
||||
'registerNamespaces',
|
||||
|
|
|
@ -28,7 +28,7 @@ use PhpParser\Node;
|
|||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
|
||||
final class MyFirstRector extends AbstractRector
|
||||
|
@ -67,11 +67,11 @@ final class MyFirstRector extends AbstractRector
|
|||
/**
|
||||
* From this method documentation is generated.
|
||||
*/
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition(
|
||||
'Change method calls from set* to change*.', [
|
||||
new CodeSample(
|
||||
new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(
|
||||
// code before
|
||||
'$user->setPassword("123456");',
|
||||
// code after
|
||||
|
|
|
@ -7,10 +7,6 @@ Here you can find overview of commonly used nodes and how to build PHP code from
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Const_;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
|
||||
|
@ -37,10 +33,6 @@ CONSTANT_NAME = 'default'
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
@ -71,10 +63,6 @@ $variableName[0]
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
|
@ -107,10 +95,6 @@ return new ArrayItem($value, $key);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
@ -143,10 +127,6 @@ return new Array_([$arrayItem]);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\ArrowFunction;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
||||
|
@ -179,10 +159,6 @@ fn() => 1
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
|
@ -213,10 +189,6 @@ $variableName = 'some value'
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\AssignOp\Coalesce;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
||||
|
@ -246,10 +218,6 @@ return new Coalesce($left, $right);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\AssignOp\Concat;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
||||
|
@ -279,10 +247,6 @@ return new Concat($left, $right);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
||||
|
@ -312,10 +276,6 @@ return new BooleanAnd($left, $right);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\BinaryOp\Coalesce;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
||||
|
@ -345,10 +305,6 @@ return new Coalesce($left, $right);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\BinaryOp\Concat;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
||||
|
@ -378,10 +334,6 @@ return new Concat($left, $right);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\BinaryOp\Equal;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
||||
|
@ -411,10 +363,6 @@ return new Equal($left, $right);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\BinaryOp\Identical;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
||||
|
@ -444,10 +392,6 @@ return new Identical($left, $right);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\BinaryOp\Minus;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
||||
|
@ -477,10 +421,6 @@ return new Minus($left, $right);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\BinaryOp\NotEqual;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
||||
|
@ -510,10 +450,6 @@ return new NotEqual($left, $right);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
||||
|
@ -543,10 +479,6 @@ return new NotIdentical($left, $right);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\BinaryOp\Spaceship;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
||||
|
@ -576,10 +508,6 @@ return new Spaceship($left, $right);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\BooleanNot;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -607,10 +535,6 @@ return new BooleanNot($variable);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Cast\Array_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -638,10 +562,6 @@ return new Array_($expr);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Cast\Bool_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -669,10 +589,6 @@ return new Bool_($expr);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Cast\Int_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -700,10 +616,6 @@ return new Int_($expr);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Cast\String_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -731,10 +643,6 @@ return new String_($expr);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
|
||||
|
@ -763,10 +671,6 @@ return new ClassConstFetch($class, 'SOME_CONSTANT');
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\ClosureUse;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -795,10 +699,6 @@ $variableName
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Name;
|
||||
|
||||
|
@ -826,10 +726,6 @@ true
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Empty_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -857,10 +753,6 @@ empty($variableName)
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Eval_;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
|
||||
|
@ -888,10 +780,6 @@ eval('Some php code')
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
@ -922,10 +810,6 @@ func_call($someVariable)
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Include_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -943,10 +827,6 @@ include $variableName
|
|||
<br>
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Include_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -975,10 +855,6 @@ require_once $variableName
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Instanceof_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
|
@ -1009,10 +885,6 @@ $variableName instanceof \SomeClassName
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Isset_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -1040,10 +912,6 @@ isset($variableName)
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\List_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
@ -1075,10 +943,6 @@ list($variableName, $anoterVariableName)
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Match_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\MatchArm;
|
||||
|
@ -1116,10 +980,6 @@ match ($variableName) {
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -1137,10 +997,6 @@ $someObject->methodName()
|
|||
<br>
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
@ -1176,10 +1032,6 @@ $someObject->methodName('yes', 'maybe')
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// anonymous class
|
||||
|
||||
use PhpParser\Node\Expr\New_;
|
||||
|
@ -1201,10 +1053,6 @@ new class
|
|||
<br>
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Name;
|
||||
|
||||
|
@ -1233,10 +1081,6 @@ new SomeClass()
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\NullsafeMethodCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -1266,10 +1110,6 @@ $variableName?->methodName()
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\NullsafePropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -1298,10 +1138,6 @@ $variableName?->someProperty
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
|
@ -1330,10 +1166,6 @@ $variableName->propertyName
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
|
||||
|
@ -1363,10 +1195,6 @@ return new StaticCall($fullyQualified, 'methodName');
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
|
||||
|
@ -1395,10 +1223,6 @@ return new StaticPropertyFetch($class, 'someProperty');
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\Ternary;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
@ -1433,10 +1257,6 @@ $variableName ? true : false
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Throw_;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
|
||||
|
@ -1464,10 +1284,6 @@ throw 'some string'
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
return new Variable('variableName');
|
||||
|
@ -1492,10 +1308,6 @@ $variableName
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\MatchArm;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
|
@ -1526,10 +1338,6 @@ return new MatchArm($conds, $body);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Name;
|
||||
|
||||
return new Name('shortName');
|
||||
|
@ -1555,10 +1363,6 @@ shortName
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
|
||||
return new FullyQualified('SomeNamespace\ShortName');
|
||||
|
@ -1583,10 +1387,6 @@ return new FullyQualified('SomeNamespace\ShortName');
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\NullableType;
|
||||
|
||||
return new NullableType('SomeType');
|
||||
|
@ -1611,10 +1411,6 @@ return new NullableType('SomeType');
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Param;
|
||||
|
||||
|
@ -1648,10 +1444,6 @@ $variableName
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Scalar\DNumber;
|
||||
|
||||
return new DNumber(10.5);
|
||||
|
@ -1676,10 +1468,6 @@ return new DNumber(10.5);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Scalar\Encapsed;
|
||||
|
||||
|
@ -1705,10 +1493,6 @@ return new Encapsed([new Variable('variableName')]);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
|
||||
return new LNumber(1000);
|
||||
|
@ -1733,10 +1517,6 @@ return new LNumber(1000);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
|
||||
return new String_('some string');
|
||||
|
@ -1762,10 +1542,6 @@ return new String_('some string');
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Const_;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
|
@ -1798,10 +1574,6 @@ public const SOME_CLASS_CONSTANT = 'default value';
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
|
||||
|
@ -1822,10 +1594,6 @@ public function methodName()
|
|||
<br>
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Param;
|
||||
|
@ -1870,10 +1638,6 @@ private function methodName($paramName): string
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
|
||||
return new Class_('ClassName');
|
||||
|
@ -1890,10 +1654,6 @@ class ClassName
|
|||
<br>
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
|
||||
|
@ -1908,7 +1668,7 @@ return $class;
|
|||
↓
|
||||
|
||||
```php
|
||||
final class ClassName extends \ParentClass
|
||||
final class ClassName extends ParentClass
|
||||
{
|
||||
}
|
||||
```
|
||||
|
@ -1931,10 +1691,6 @@ final class ClassName extends \ParentClass
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Const_;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Const_ as ConstStmt;
|
||||
|
@ -1963,10 +1719,6 @@ const CONSTANT_IN_CLASS = 'default value';
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Stmt\Declare_;
|
||||
use PhpParser\Node\Stmt\DeclareDeclare;
|
||||
|
@ -1979,7 +1731,6 @@ return new Declare_([$declareDeclare]);
|
|||
↓
|
||||
|
||||
```php
|
||||
declare(strict_types=1);
|
||||
```
|
||||
|
||||
<br>
|
||||
|
@ -1996,10 +1747,6 @@ declare(strict_types=1);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Do_;
|
||||
|
||||
|
@ -2029,10 +1776,6 @@ do {
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Echo_;
|
||||
|
||||
|
@ -2060,10 +1803,6 @@ echo 'hello';
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\ElseIf_;
|
||||
|
@ -2098,10 +1837,6 @@ elseif (true) {
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Foreach_;
|
||||
|
||||
|
@ -2135,10 +1870,6 @@ foreach ($foreachedVariableName as $asVariable) {
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
|
||||
return new Function_('some_function');
|
||||
|
@ -2147,7 +1878,7 @@ return new Function_('some_function');
|
|||
↓
|
||||
|
||||
```php
|
||||
function some_function()
|
||||
function some_function(): void
|
||||
{
|
||||
}
|
||||
```
|
||||
|
@ -2170,10 +1901,6 @@ function some_function()
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
|
@ -2206,10 +1933,6 @@ if (true) {
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Stmt\InlineHTML;
|
||||
|
||||
return new InlineHTML('<strong>feel</strong>');
|
||||
|
@ -2235,10 +1958,6 @@ return new InlineHTML('<strong>feel</strong>');
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
|
||||
|
@ -2269,10 +1988,6 @@ interface InterfaceName
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Stmt\Label;
|
||||
|
||||
return new Label('labelName');
|
||||
|
@ -2297,10 +2012,6 @@ labelName:
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\PropertyProperty;
|
||||
|
@ -2320,10 +2031,6 @@ public string $propertyName;
|
|||
<br>
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\PropertyProperty;
|
||||
|
@ -2343,10 +2050,6 @@ public $propertyName;
|
|||
<br>
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\PropertyProperty;
|
||||
|
@ -2378,10 +2081,6 @@ public static $firstProperty, $secondProperty;
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\StaticVar;
|
||||
|
||||
|
@ -2410,10 +2109,6 @@ $variableName
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Static_;
|
||||
use PhpParser\Node\Stmt\StaticVar;
|
||||
|
@ -2442,10 +2137,6 @@ static $static;
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Stmt\Case_;
|
||||
|
@ -2479,10 +2170,6 @@ switch ($variableName) {
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Throw_;
|
||||
|
||||
|
@ -2510,10 +2197,6 @@ throw 'some string';
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\TraitUse;
|
||||
|
||||
|
@ -2523,7 +2206,6 @@ return new TraitUse([new FullyQualified('TraitName')]);
|
|||
↓
|
||||
|
||||
```php
|
||||
use \TraitName;
|
||||
```
|
||||
|
||||
<br>
|
||||
|
@ -2540,10 +2222,6 @@ use \TraitName;
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\TraitUseAdaptation\Alias;
|
||||
|
@ -2575,10 +2253,6 @@ return new Alias($traitFullyQualified, 'method', Class_::MODIFIER_PUBLIC, 'alias
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Stmt\Trait_;
|
||||
|
||||
return new Trait_('TraitName');
|
||||
|
@ -2607,10 +2281,6 @@ trait TraitName
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Catch_;
|
||||
|
@ -2655,10 +2325,6 @@ try {
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Unset_;
|
||||
|
||||
|
@ -2686,10 +2352,6 @@ unset($variableName);
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Use_;
|
||||
use PhpParser\Node\Stmt\UseUse;
|
||||
|
@ -2702,7 +2364,6 @@ return new Use_([$useUse]);
|
|||
↓
|
||||
|
||||
```php
|
||||
use UsedNamespace;
|
||||
```
|
||||
|
||||
<br>
|
||||
|
@ -2719,10 +2380,6 @@ use UsedNamespace;
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\While_;
|
||||
|
||||
|
@ -2750,10 +2407,6 @@ while ($variableName) {
|
|||
### Example PHP Code
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\UnionType;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,7 +9,10 @@ use Rector\NodeTypeResolver\Node\AttributeKey;
|
|||
|
||||
final class MergedNodeCommentPreserver
|
||||
{
|
||||
public function keepComments(Node $newNode, Node ...$mergedNodes): void
|
||||
/**
|
||||
* @param Node[] $mergedNodes
|
||||
*/
|
||||
public function keepComments(Node $newNode, array $mergedNodes): void
|
||||
{
|
||||
$comments = [];
|
||||
|
||||
|
|
|
@ -81,7 +81,8 @@ final class PhpDocInfoFactory
|
|||
/** needed for @see PhpDocNodeFactoryInterface */
|
||||
$this->currentNodeProvider->setNode($node);
|
||||
|
||||
if ($node->getDocComment() === null) {
|
||||
$docComment = $node->getDocComment();
|
||||
if ($docComment === null) {
|
||||
if ($node->getComments() !== []) {
|
||||
return null;
|
||||
}
|
||||
|
@ -91,8 +92,7 @@ final class PhpDocInfoFactory
|
|||
$tokens = [];
|
||||
$phpDocNode = new AttributeAwarePhpDocNode([]);
|
||||
} else {
|
||||
$content = $node->getDocComment()
|
||||
->getText();
|
||||
$content = $docComment->getText();
|
||||
$tokens = $this->lexer->tokenize($content);
|
||||
$phpDocNode = $this->parseTokensToPhpDocNode($tokens);
|
||||
$this->setPositionOfLastToken($phpDocNode);
|
||||
|
|
|
@ -5,8 +5,8 @@ declare(strict_types=1);
|
|||
namespace Rector\BetterPhpDocParser\PhpDocManipulator;
|
||||
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\Naming\Contract\RenameValueObjectInterface;
|
||||
use Rector\Naming\ValueObject\ParamRename;
|
||||
use Rector\Naming\ValueObject\RenameValueObjectInterface;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
|
||||
final class PropertyDocBlockManipulator
|
||||
|
@ -16,9 +16,10 @@ final class PropertyDocBlockManipulator
|
|||
*/
|
||||
public function renameParameterNameInDocBlock(RenameValueObjectInterface $renameValueObject): void
|
||||
{
|
||||
$functionLike = $renameValueObject->getFunctionLike();
|
||||
|
||||
/** @var PhpDocInfo|null $phpDocInfo */
|
||||
$phpDocInfo = $renameValueObject->getFunctionLike()
|
||||
->getAttribute(AttributeKey::PHP_DOC_INFO);
|
||||
$phpDocInfo = $functionLike->getAttribute(AttributeKey::PHP_DOC_INFO);
|
||||
if ($phpDocInfo === null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode;
|
|||
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareNullableTypeNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory;
|
||||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
|
||||
final class AttributeAwareNodeFactoryTest extends AbstractKernelTestCase
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
|||
use Rector\BetterPhpDocParser\Printer\PhpDocInfoPrinter;
|
||||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileSystem;
|
||||
|
||||
final class PhpDocInfoTest extends AbstractKernelTestCase
|
||||
|
|
|
@ -13,7 +13,7 @@ use Rector\BetterPhpDocParser\Printer\PhpDocInfoPrinter;
|
|||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Symplify\EasyTesting\DataProvider\StaticFixtureFinder;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileSystem;
|
||||
|
||||
abstract class AbstractPhpDocInfoPrinterTest extends AbstractKernelTestCase
|
||||
|
|
|
@ -15,7 +15,7 @@ use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
|||
use Rector\FileSystemRector\Parser\FileInfoParser;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\EasyTesting\DataProvider\StaticFixtureFinder;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
abstract class AbstractPhpDocInfoTest extends AbstractKernelTestCase
|
||||
|
|
|
@ -13,7 +13,7 @@ use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
|||
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\TypeNodeAnalyzer;
|
||||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
|
||||
final class TypeNodeAnalyzerTest extends AbstractKernelTestCase
|
||||
{
|
||||
|
|
|
@ -29,8 +29,8 @@ final class FileHashComputer
|
|||
|
||||
$fileLoader->load($fileInfo->getRealPath());
|
||||
|
||||
return $this->arrayToHash($containerBuilder->getDefinitions()) .
|
||||
$this->arrayToHash($containerBuilder->getParameterBag()->all());
|
||||
$parameterBag = $containerBuilder->getParameterBag();
|
||||
return $this->arrayToHash($containerBuilder->getDefinitions()) . $this->arrayToHash($parameterBag->all());
|
||||
}
|
||||
|
||||
private function ensureIsYamlOrPhp(SmartFileInfo $fileInfo): void
|
||||
|
|
|
@ -8,7 +8,7 @@ use Iterator;
|
|||
use Rector\Caching\Config\FileHashComputer;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class FileHashComputerTest extends AbstractKernelTestCase
|
||||
|
|
|
@ -139,8 +139,7 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
|
|||
|
||||
$message = sprintf(
|
||||
'Could not process "%s" file%s, due to: %s"%s".',
|
||||
$error->getFileInfo()
|
||||
->getRelativeFilePathFromCwd(),
|
||||
$error->getRelativeFilePath(),
|
||||
$error->getRectorClass() ? ' by "' . $error->getRectorClass() . '"' : '',
|
||||
PHP_EOL,
|
||||
$errorMessage
|
||||
|
|
|
@ -83,8 +83,7 @@ final class JsonOutputFormatter implements OutputFormatterInterface
|
|||
foreach ($errors as $error) {
|
||||
$errorData = [
|
||||
'message' => $error->getMessage(),
|
||||
'file' => $error->getFileInfo()
|
||||
->getPathname(),
|
||||
'file' => $error->getRelativeFilePath(),
|
||||
];
|
||||
|
||||
if ($error->getRectorClass()) {
|
||||
|
|
|
@ -32,8 +32,8 @@ final class RectorWithFileAndLineChange
|
|||
|
||||
public function getRectorDefinitionsDescription(): string
|
||||
{
|
||||
return $this->rector->getDefinition()
|
||||
->getDescription();
|
||||
$ruleDefinition = $this->rector->getRuleDefinition();
|
||||
return $ruleDefinition->getDescription();
|
||||
}
|
||||
|
||||
public function getRectorClass(): string
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Migrify\PhpConfigPrinter\ValueObject\Option;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
$parameters->set(Option::INLINE_VALUE_OBJECT_FUNC_CALL_NAME, 'Rector\SymfonyPhpConfig\inline_value_object');
|
||||
$parameters->set(Option::INLINE_VALUE_OBJECTS_FUNC_CALL_NAME, 'Rector\SymfonyPhpConfig\inline_value_objects');
|
||||
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->defaults()
|
||||
->public()
|
||||
->autowire()
|
||||
->autoconfigure();
|
||||
|
||||
$services->load('Rector\DocumentationGenerator\\', __DIR__ . '/../src');
|
||||
};
|
|
@ -1,122 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DocumentationGenerator\Command;
|
||||
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\Console\Command\AbstractCommand;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\DocumentationGenerator\Printer\RectorsDocumentationPrinter;
|
||||
use Rector\Testing\Finder\RectorsFinder;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symplify\PackageBuilder\Console\Command\CommandNaming;
|
||||
use Symplify\PackageBuilder\Console\ShellCode;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
use Symplify\SmartFileSystem\SmartFileSystem;
|
||||
|
||||
final class DumpRectorsCommand extends AbstractCommand
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const OUTPUT_FILE = 'output-file';
|
||||
|
||||
/**
|
||||
* @var RectorsFinder
|
||||
*/
|
||||
private $rectorsFinder;
|
||||
|
||||
/**
|
||||
* @var RectorsDocumentationPrinter
|
||||
*/
|
||||
private $rectorsDocumentationPrinter;
|
||||
|
||||
/**
|
||||
* @var SymfonyStyle
|
||||
*/
|
||||
private $symfonyStyle;
|
||||
|
||||
/**
|
||||
* @var SmartFileSystem
|
||||
*/
|
||||
private $smartFileSystem;
|
||||
|
||||
public function __construct(
|
||||
RectorsDocumentationPrinter $rectorsDocumentationPrinter,
|
||||
RectorsFinder $rectorsFinder,
|
||||
SymfonyStyle $symfonyStyle,
|
||||
SmartFileSystem $smartFileSystem
|
||||
) {
|
||||
parent::__construct();
|
||||
|
||||
$this->rectorsFinder = $rectorsFinder;
|
||||
$this->rectorsDocumentationPrinter = $rectorsDocumentationPrinter;
|
||||
$this->symfonyStyle = $symfonyStyle;
|
||||
$this->smartFileSystem = $smartFileSystem;
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName(CommandNaming::classToName(self::class));
|
||||
$this->setDescription('[DOCS] Dump overview of all Rectors');
|
||||
|
||||
$this->addArgument(
|
||||
Option::SOURCE,
|
||||
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
|
||||
'Directories with Rector rules'
|
||||
);
|
||||
|
||||
$this->addOption(
|
||||
self::OUTPUT_FILE,
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Where to output the file',
|
||||
getcwd() . '/docs/rector_rules_overview.md'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$source = (array) $input->getArgument(Option::SOURCE);
|
||||
$isRectorProject = $source === [];
|
||||
|
||||
$rectors = $this->findRectorClassesInDirectoriesAndCreateRectorObjects($isRectorProject, $source);
|
||||
|
||||
$outputFile = (string) $input->getOption(self::OUTPUT_FILE);
|
||||
$printedContent = $this->rectorsDocumentationPrinter->print($rectors, $isRectorProject);
|
||||
$this->smartFileSystem->dumpFile($outputFile, $printedContent);
|
||||
|
||||
$outputFileFileInfo = new SmartFileInfo($outputFile);
|
||||
$message = sprintf(
|
||||
'Documentation for "%d" Rector rules was generated to "%s"',
|
||||
count($rectors),
|
||||
$outputFileFileInfo->getRelativeFilePathFromCwd()
|
||||
);
|
||||
$this->symfonyStyle->success($message);
|
||||
|
||||
return ShellCode::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $source
|
||||
* @return RectorInterface[]
|
||||
*/
|
||||
private function findRectorClassesInDirectoriesAndCreateRectorObjects(bool $isRectorProject, array $source): array
|
||||
{
|
||||
if ($isRectorProject) {
|
||||
// fallback to core Rectors
|
||||
return $this->rectorsFinder->findInDirectoriesAndCreate([
|
||||
__DIR__ . '/../../../../rules',
|
||||
__DIR__ . '/../../../../packages',
|
||||
]);
|
||||
}
|
||||
|
||||
// custom directory
|
||||
return $this->rectorsFinder->findInDirectoriesAndCreate($source);
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DocumentationGenerator\Guard;
|
||||
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
|
||||
final class PrePrintRectorGuard
|
||||
{
|
||||
public function ensureRectorRefinitionHasContent(RectorInterface $rector): void
|
||||
{
|
||||
$this->ensureRectorDefinitionExists($rector);
|
||||
$this->ensureCodeSampleExists($rector);
|
||||
}
|
||||
|
||||
private function ensureRectorDefinitionExists(RectorInterface $rector): void
|
||||
{
|
||||
$rectorDefinition = $rector->getDefinition();
|
||||
if ($rectorDefinition->getDescription() !== '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
'Rector "%s" is missing description. Complete it in "%s()" method.',
|
||||
get_class($rector),
|
||||
'getDefinition'
|
||||
);
|
||||
throw new ShouldNotHappenException($message);
|
||||
}
|
||||
|
||||
private function ensureCodeSampleExists(RectorInterface $rector): void
|
||||
{
|
||||
$rectorDefinition = $rector->getDefinition();
|
||||
if (count($rectorDefinition->getCodeSamples()) !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new ShouldNotHappenException(sprintf(
|
||||
'Rector "%s" must have at least one code sample. Complete it in "%s()" method.',
|
||||
get_class($rector),
|
||||
'getDefinition'
|
||||
));
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DocumentationGenerator;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use Rector\NodeTypeResolver\ClassExistenceStaticHelper;
|
||||
|
||||
final class PhpKeywordHighlighter
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private const TEXT_WORDS = [
|
||||
'Rename',
|
||||
'EventDispatcher',
|
||||
'current',
|
||||
'defined',
|
||||
'rename',
|
||||
'next',
|
||||
'file',
|
||||
'constant',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @see https://regex101.com/r/uxtJDA/3
|
||||
*/
|
||||
private const VARIABLE_CALL_OR_VARIABLE_REGEX = '#^\$([A-Za-z\-\>]+)[^\]](\(\))?#';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @see https://regex101.com/r/uxtJDA/1
|
||||
*/
|
||||
private const STATIC_CALL_REGEX = '#([A-Za-z::\-\>]+)(\(\))$#';
|
||||
|
||||
public function highlight(string $content): string
|
||||
{
|
||||
$words = Strings::split($content, '# #');
|
||||
foreach ($words as $key => $word) {
|
||||
if (! $this->isKeywordToHighlight($word)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$words[$key] = '`' . $word . '`';
|
||||
}
|
||||
|
||||
return implode(' ', $words);
|
||||
}
|
||||
|
||||
private function isKeywordToHighlight(string $word): bool
|
||||
{
|
||||
// already in code quotes
|
||||
if (Strings::startsWith($word, '`') || Strings::endsWith($word, '`')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// part of normal text
|
||||
if (in_array($word, self::TEXT_WORDS, true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (function_exists($word) || function_exists(trim($word, '()'))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ClassExistenceStaticHelper::doesClassLikeExist($word)) {
|
||||
// not a class
|
||||
if (! Strings::contains($word, '\\')) {
|
||||
return in_array($word, ['Throwable', 'Exception'], true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($word === 'composer.json') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((bool) Strings::match($word, self::VARIABLE_CALL_OR_VARIABLE_REGEX)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (bool) Strings::match($word, self::STATIC_CALL_REGEX);
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DocumentationGenerator\Printer;
|
||||
|
||||
use Migrify\PhpConfigPrinter\Printer\SmartPhpConfigPrinter;
|
||||
use Rector\ConsoleDiffer\MarkdownDifferAndFormatter;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\Contract\RectorDefinition\CodeSampleInterface;
|
||||
use Rector\Core\RectorDefinition\ComposerJsonAwareCodeSample;
|
||||
use Rector\Core\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DocumentationGenerator\Tests\Printer\CodeSamplePrinter\CodeSamplePrinterTest
|
||||
*/
|
||||
final class CodeSamplePrinter
|
||||
{
|
||||
/**
|
||||
* @var MarkdownDifferAndFormatter
|
||||
*/
|
||||
private $markdownDifferAndFormatter;
|
||||
|
||||
/**
|
||||
* @var SmartPhpConfigPrinter
|
||||
*/
|
||||
private $smartPhpConfigPrinter;
|
||||
|
||||
public function __construct(
|
||||
MarkdownDifferAndFormatter $markdownDifferAndFormatter,
|
||||
SmartPhpConfigPrinter $smartPhpConfigPrinter
|
||||
) {
|
||||
$this->markdownDifferAndFormatter = $markdownDifferAndFormatter;
|
||||
$this->smartPhpConfigPrinter = $smartPhpConfigPrinter;
|
||||
}
|
||||
|
||||
public function printCodeSamples(RectorDefinition $rectorDefinition, RectorInterface $rector): string
|
||||
{
|
||||
$content = '';
|
||||
|
||||
foreach ($rectorDefinition->getCodeSamples() as $codeSample) {
|
||||
$content .= $this->printConfiguration($rector, $codeSample);
|
||||
$content .= $this->printCodeSample($codeSample);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
private function printConfiguration(RectorInterface $rector, CodeSampleInterface $codeSample): string
|
||||
{
|
||||
if (! $codeSample instanceof ConfiguredCodeSample) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$configuration = [
|
||||
get_class($rector) => $codeSample->getConfiguration(),
|
||||
];
|
||||
|
||||
$phpConfigContent = $this->smartPhpConfigPrinter->printConfiguredServices($configuration);
|
||||
$wrappedPhpConfigContent = $this->printCodeWrapped($phpConfigContent, 'php');
|
||||
|
||||
return $wrappedPhpConfigContent . PHP_EOL . '↓' . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
|
||||
private function printCodeSample(CodeSampleInterface $codeSample): string
|
||||
{
|
||||
$diff = $this->markdownDifferAndFormatter->bareDiffAndFormatWithoutColors(
|
||||
$codeSample->getCodeBefore(),
|
||||
$codeSample->getCodeAfter()
|
||||
);
|
||||
|
||||
$content = $this->printCodeWrapped($diff, 'diff');
|
||||
|
||||
$extraFileContent = $codeSample->getExtraFileContent();
|
||||
if ($extraFileContent !== null) {
|
||||
$content .= PHP_EOL . '**New file**' . PHP_EOL;
|
||||
$content .= $this->printCodeWrapped($extraFileContent, 'php');
|
||||
}
|
||||
|
||||
return $content . $this->printComposerJsonAwareCodeSample($codeSample);
|
||||
}
|
||||
|
||||
private function printCodeWrapped(string $content, string $format): string
|
||||
{
|
||||
$message = sprintf('```%s%s%s%s```', $format, PHP_EOL, rtrim($content), PHP_EOL);
|
||||
return $message . PHP_EOL;
|
||||
}
|
||||
|
||||
private function printComposerJsonAwareCodeSample(CodeSampleInterface $codeSample): string
|
||||
{
|
||||
if (! $codeSample instanceof ComposerJsonAwareCodeSample) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$composerJsonContent = $codeSample->getComposerJsonContent();
|
||||
|
||||
return PHP_EOL . 'composer.json' . PHP_EOL . $this->printCodeWrapped($composerJsonContent, 'json') . PHP_EOL;
|
||||
}
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DocumentationGenerator\Printer;
|
||||
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\DocumentationGenerator\Guard\PrePrintRectorGuard;
|
||||
use Rector\DocumentationGenerator\PhpKeywordHighlighter;
|
||||
use Rector\PHPUnit\TestClassResolver\TestClassResolver;
|
||||
use ReflectionClass;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
/**
|
||||
* @see \Rector\DocumentationGenerator\Tests\Printer\RectorPrinter\RectorPrinterTest
|
||||
*/
|
||||
final class RectorPrinter
|
||||
{
|
||||
/**
|
||||
* @var TestClassResolver
|
||||
*/
|
||||
private $testClassResolver;
|
||||
|
||||
/**
|
||||
* @var CodeSamplePrinter
|
||||
*/
|
||||
private $rectorCodeSamplePrinter;
|
||||
|
||||
/**
|
||||
* @var PhpKeywordHighlighter
|
||||
*/
|
||||
private $phpKeywordHighlighter;
|
||||
|
||||
/**
|
||||
* @var PrePrintRectorGuard
|
||||
*/
|
||||
private $prePrintRectorGuard;
|
||||
|
||||
public function __construct(
|
||||
TestClassResolver $testClassResolver,
|
||||
CodeSamplePrinter $rectorCodeSamplePrinter,
|
||||
PhpKeywordHighlighter $phpKeywordHighlighter,
|
||||
PrePrintRectorGuard $prePrintRectorGuard
|
||||
) {
|
||||
$this->testClassResolver = $testClassResolver;
|
||||
$this->rectorCodeSamplePrinter = $rectorCodeSamplePrinter;
|
||||
$this->phpKeywordHighlighter = $phpKeywordHighlighter;
|
||||
$this->prePrintRectorGuard = $prePrintRectorGuard;
|
||||
}
|
||||
|
||||
public function printRector(RectorInterface $rector, bool $isRectorProject): string
|
||||
{
|
||||
$content = '';
|
||||
$headline = $this->getRectorClassWithoutNamespace($rector);
|
||||
|
||||
if ($isRectorProject) {
|
||||
$content .= sprintf('### `%s`', $headline) . PHP_EOL;
|
||||
} else {
|
||||
$content .= sprintf('## `%s`', $headline) . PHP_EOL;
|
||||
}
|
||||
|
||||
$rectorClass = get_class($rector);
|
||||
|
||||
$content .= PHP_EOL;
|
||||
$content .= $this->createRectorFileLink($rector, $rectorClass) . PHP_EOL;
|
||||
|
||||
$rectorTestClass = $this->testClassResolver->resolveFromClassName($rectorClass);
|
||||
if ($rectorTestClass !== null) {
|
||||
$fixtureDirectoryPath = $this->resolveFixtureDirectoryPathOnGitHub($rectorTestClass);
|
||||
if ($fixtureDirectoryPath !== null) {
|
||||
$message = sprintf('- [test fixtures](%s)', $fixtureDirectoryPath);
|
||||
$content .= $message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
$this->prePrintRectorGuard->ensureRectorRefinitionHasContent($rector);
|
||||
|
||||
$content .= PHP_EOL;
|
||||
|
||||
$rectorDefinition = $rector->getDefinition();
|
||||
$description = $rectorDefinition->getDescription();
|
||||
$codeHighlightedDescription = $this->phpKeywordHighlighter->highlight($description);
|
||||
|
||||
$content .= $codeHighlightedDescription . PHP_EOL . PHP_EOL;
|
||||
|
||||
$content .= $this->rectorCodeSamplePrinter->printCodeSamples($rectorDefinition, $rector);
|
||||
$content .= PHP_EOL . '<br><br>' . PHP_EOL;
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
private function getRectorClassWithoutNamespace(RectorInterface $rector): string
|
||||
{
|
||||
$rectorClass = get_class($rector);
|
||||
$rectorClassParts = explode('\\', $rectorClass);
|
||||
|
||||
return $rectorClassParts[count($rectorClassParts) - 1];
|
||||
}
|
||||
|
||||
private function createRectorFileLink(RectorInterface $rector, string $rectorClass): string
|
||||
{
|
||||
return sprintf(
|
||||
'- class: [`%s`](%s)',
|
||||
get_class($rector),
|
||||
$this->resolveClassFilePathOnGitHub($rectorClass)
|
||||
);
|
||||
}
|
||||
|
||||
private function resolveFixtureDirectoryPathOnGitHub(string $className): ?string
|
||||
{
|
||||
$classRelativePath = $this->getClassRelativePath($className);
|
||||
|
||||
$fixtureDirectory = dirname($classRelativePath) . '/Fixture';
|
||||
if (is_dir($fixtureDirectory)) {
|
||||
return '/' . ltrim($fixtureDirectory, '/');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function resolveClassFilePathOnGitHub(string $className): string
|
||||
{
|
||||
$classRelativePath = $this->getClassRelativePath($className);
|
||||
return '/' . ltrim($classRelativePath, '/');
|
||||
}
|
||||
|
||||
private function getClassRelativePath(string $className): string
|
||||
{
|
||||
$rectorReflectionClass = new ReflectionClass($className);
|
||||
$rectorSmartFileInfo = new SmartFileInfo($rectorReflectionClass->getFileName());
|
||||
|
||||
return $rectorSmartFileInfo->getRelativeFilePathFromCwd();
|
||||
}
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DocumentationGenerator\Printer;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\DocumentationGenerator\RectorMetadataResolver;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @see \Rector\DocumentationGenerator\Tests\Printer\RectorsDocumentationPrinter\RectorsDocumentationPrinterTest
|
||||
*/
|
||||
final class RectorsDocumentationPrinter
|
||||
{
|
||||
/**
|
||||
* @var RectorMetadataResolver
|
||||
*/
|
||||
private $rectorMetadataResolver;
|
||||
|
||||
/**
|
||||
* @var RectorPrinter
|
||||
*/
|
||||
private $rectorPrinter;
|
||||
|
||||
public function __construct(RectorMetadataResolver $rectorMetadataResolver, RectorPrinter $rectorPrinter)
|
||||
{
|
||||
$this->rectorMetadataResolver = $rectorMetadataResolver;
|
||||
$this->rectorPrinter = $rectorPrinter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RectorInterface[] $rectors
|
||||
*/
|
||||
public function print(array $rectors, bool $isRectorProject): string
|
||||
{
|
||||
Assert::allIsInstanceOf($rectors, RectorInterface::class);
|
||||
|
||||
$totalRectorCount = count($rectors);
|
||||
$message = sprintf('# All %d Rectors Overview', $totalRectorCount) . PHP_EOL;
|
||||
|
||||
$content = $message;
|
||||
$content .= PHP_EOL;
|
||||
|
||||
if ($isRectorProject) {
|
||||
$content .= '- [Projects](#projects)';
|
||||
$content .= PHP_EOL;
|
||||
|
||||
$content .= $this->printRectorsWithHeadline($rectors, 'Projects');
|
||||
} else {
|
||||
$content .= $this->printRectors($rectors, $isRectorProject);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RectorInterface[] $rectors
|
||||
*/
|
||||
public function printRectors(array $rectors, bool $isRectorProject): string
|
||||
{
|
||||
$groupedRectors = $this->groupRectorsByPackage($rectors);
|
||||
|
||||
$content = '';
|
||||
if ($isRectorProject) {
|
||||
$content .= $this->printGroupsMenu($groupedRectors);
|
||||
}
|
||||
|
||||
foreach ($groupedRectors as $group => $rectors) {
|
||||
if ($isRectorProject) {
|
||||
$content .= '## ' . $group . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
|
||||
foreach ($rectors as $rector) {
|
||||
$rectorContent = $this->rectorPrinter->printRector($rector, $isRectorProject);
|
||||
$content .= $rectorContent . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RectorInterface[] $rectors
|
||||
*/
|
||||
private function printRectorsWithHeadline(array $rectors, string $headline): string
|
||||
{
|
||||
if ($rectors === []) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$content = '---' . PHP_EOL . PHP_EOL;
|
||||
$content .= '## ' . $headline . PHP_EOL . PHP_EOL;
|
||||
|
||||
$content .= $this->printRectors($rectors, true);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RectorInterface[] $rectors
|
||||
* @return array<string, RectorInterface[]>
|
||||
*/
|
||||
private function groupRectorsByPackage(array $rectors): array
|
||||
{
|
||||
$rectorsByPackage = [];
|
||||
foreach ($rectors as $rector) {
|
||||
$rectorClass = get_class($rector);
|
||||
$package = $this->rectorMetadataResolver->resolvePackageFromRectorClass($rectorClass);
|
||||
$rectorsByPackage[$package][] = $rector;
|
||||
}
|
||||
|
||||
// sort groups by name to make them more readable
|
||||
ksort($rectorsByPackage);
|
||||
|
||||
return $rectorsByPackage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RectorInterface[][] $rectorsByGroup
|
||||
*/
|
||||
private function printGroupsMenu(array $rectorsByGroup): string
|
||||
{
|
||||
$content = '';
|
||||
foreach ($rectorsByGroup as $group => $rectors) {
|
||||
$escapedGroup = str_replace('\\', '', $group);
|
||||
$escapedGroup = Strings::webalize($escapedGroup, '_');
|
||||
$message = sprintf('- [%s](#%s) (%d)', $group, $escapedGroup, count($rectors));
|
||||
$content .= $message . PHP_EOL;
|
||||
}
|
||||
|
||||
return $content . PHP_EOL;
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DocumentationGenerator;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
|
||||
final class RectorMetadataResolver
|
||||
{
|
||||
public function resolvePackageFromRectorClass(string $rectorClass): string
|
||||
{
|
||||
$rectorClassParts = explode('\\', $rectorClass);
|
||||
|
||||
// basic Rectors
|
||||
if (Strings::startsWith($rectorClass, 'Rector\Rector\\')) {
|
||||
return 'Core';
|
||||
}
|
||||
|
||||
// Rector/<PackageGroup>/Rector/SomeRector
|
||||
return $rectorClassParts[1];
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DocumentationGenerator\Tests\Printer\CodeSamplePrinter;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Autodiscovery\Rector\FileNode\MoveValueObjectsToValueObjectDirectoryRector;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Rector\DocumentationGenerator\Printer\CodeSamplePrinter;
|
||||
use Rector\Php74\Rector\Property\TypedPropertyRector;
|
||||
use ReflectionClass;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class CodeSamplePrinterTest extends AbstractKernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var CodeSamplePrinter
|
||||
*/
|
||||
private $codeSamplePrinter;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->bootKernel(RectorKernel::class);
|
||||
$this->codeSamplePrinter = self::$container->get(CodeSamplePrinter::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(string $rectorClass, string $expectedPrintedCodeSampleFilePath): void
|
||||
{
|
||||
$reflectionClass = new ReflectionClass($rectorClass);
|
||||
$rector = $reflectionClass->newInstanceWithoutConstructor();
|
||||
|
||||
/** @var RectorInterface $rector */
|
||||
$this->assertInstanceOf(RectorInterface::class, $rector);
|
||||
|
||||
$printedCodeSamples = $this->codeSamplePrinter->printCodeSamples($rector->getDefinition(), $rector);
|
||||
|
||||
$expectedFileInfo = new SmartFileInfo($expectedPrintedCodeSampleFilePath);
|
||||
$this->assertStringEqualsFile(
|
||||
$expectedPrintedCodeSampleFilePath,
|
||||
$printedCodeSamples,
|
||||
$expectedFileInfo->getRelativeFilePathFromCwd()
|
||||
);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
yield [TypedPropertyRector::class, __DIR__ . '/Fixture/expected_typed_property_code_sample.txt'];
|
||||
yield [
|
||||
MoveValueObjectsToValueObjectDirectoryRector::class,
|
||||
__DIR__ . '/Fixture/expected_value_object_rector.txt',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Php74\Rector\Property\TypedPropertyRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(TypedPropertyRector::class)
|
||||
->call('configure', [[TypedPropertyRector::CLASS_LIKE_TYPE_ONLY => false]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
final class SomeClass
|
||||
{
|
||||
- /**
|
||||
- * @var int
|
||||
- */
|
||||
- private count;
|
||||
+ private int count;
|
||||
}
|
||||
```
|
|
@ -1,36 +0,0 @@
|
|||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Autodiscovery\Rector\FileNode\MoveValueObjectsToValueObjectDirectoryRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(MoveValueObjectsToValueObjectDirectoryRector::class)
|
||||
->call('configure', [[MoveValueObjectsToValueObjectDirectoryRector::TYPES => ['ValueObjectInterfaceClassName'], MoveValueObjectsToValueObjectDirectoryRector::SUFFIXES => ['Search'], MoveValueObjectsToValueObjectDirectoryRector::ENABLE_VALUE_OBJECT_GUESSING => true]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
-// app/Exception/Name.php
|
||||
+// app/ValueObject/Name.php
|
||||
class Name
|
||||
{
|
||||
private $name;
|
||||
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
```
|
|
@ -1,37 +0,0 @@
|
|||
## `TypedPropertyRector`
|
||||
|
||||
- class: [`Rector\Php74\Rector\Property\TypedPropertyRector`](/rules/php74/src/Rector/Property/TypedPropertyRector.php)
|
||||
- [test fixtures](/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture)
|
||||
|
||||
Changes property `@var` annotations from annotation to type.
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Php74\Rector\Property\TypedPropertyRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(TypedPropertyRector::class)
|
||||
->call('configure', [[TypedPropertyRector::CLASS_LIKE_TYPE_ONLY => false]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
final class SomeClass
|
||||
{
|
||||
- /**
|
||||
- * @var int
|
||||
- */
|
||||
- private count;
|
||||
+ private int count;
|
||||
}
|
||||
```
|
||||
|
||||
<br><br>
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DocumentationGenerator\Tests\Printer\RectorPrinter;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Rector\DocumentationGenerator\Printer\RectorPrinter;
|
||||
use Rector\Php74\Rector\Property\TypedPropertyRector;
|
||||
use ReflectionClass;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
|
||||
final class RectorPrinterTest extends AbstractKernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var RectorPrinter
|
||||
*/
|
||||
private $rectorPrinter;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->bootKernel(RectorKernel::class);
|
||||
$this->rectorPrinter = self::$container->get(RectorPrinter::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(string $rectorClass, string $expectedContentFilePath): void
|
||||
{
|
||||
$reflectionClass = new ReflectionClass($rectorClass);
|
||||
|
||||
/** @var RectorInterface $rector */
|
||||
$rector = $reflectionClass->newInstanceWithoutConstructor();
|
||||
|
||||
$printedContent = $this->rectorPrinter->printRector($rector, false);
|
||||
$this->assertStringEqualsFile($expectedContentFilePath, $printedContent);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
yield [TypedPropertyRector::class, __DIR__ . '/Fixture/expected_typed_property_rector.txt'];
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
# All 2 Rectors Overview
|
||||
|
||||
## `TypedPropertyRector`
|
||||
|
||||
- class: [`Rector\Php74\Rector\Property\TypedPropertyRector`](/rules/php74/src/Rector/Property/TypedPropertyRector.php)
|
||||
- [test fixtures](/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture)
|
||||
|
||||
Changes property `@var` annotations from annotation to type.
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Php74\Rector\Property\TypedPropertyRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(TypedPropertyRector::class)
|
||||
->call('configure', [[TypedPropertyRector::CLASS_LIKE_TYPE_ONLY => false]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
final class SomeClass
|
||||
{
|
||||
- /**
|
||||
- * @var int
|
||||
- */
|
||||
- private count;
|
||||
+ private int count;
|
||||
}
|
||||
```
|
||||
|
||||
<br><br>
|
||||
|
||||
## `RenamePropertyRector`
|
||||
|
||||
- class: [`Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector`](/rules/renaming/src/Rector/PropertyFetch/RenamePropertyRector.php)
|
||||
- [test fixtures](/rules/renaming/tests/Rector/PropertyFetch/RenamePropertyRector/Fixture)
|
||||
|
||||
Replaces defined old properties by new ones.
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
|
||||
use Rector\Renaming\ValueObject\RenameProperty;
|
||||
use function Rector\SymfonyPhpConfig\inline_value_objects;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(RenamePropertyRector::class)
|
||||
->call('configure', [[RenamePropertyRector::RENAMED_PROPERTIES => inline_value_objects([new RenameProperty('SomeClass', 'someOldProperty', 'someNewProperty')])]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
-$someObject->someOldProperty;
|
||||
+$someObject->someNewProperty;
|
||||
```
|
||||
|
||||
<br><br>
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DocumentationGenerator\Tests\Printer\RectorsDocumentationPrinter;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Rector\DocumentationGenerator\Printer\RectorsDocumentationPrinter;
|
||||
use Rector\Php74\Rector\Property\TypedPropertyRector;
|
||||
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
|
||||
use ReflectionClass;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class RectorsDocumentationPrinterTest extends AbstractKernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var RectorsDocumentationPrinter
|
||||
*/
|
||||
private $rectorsDocumentationPrinter;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->bootKernel(RectorKernel::class);
|
||||
$this->rectorsDocumentationPrinter = self::$container->get(RectorsDocumentationPrinter::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $rectorClasses
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(array $rectorClasses, bool $isRectorProject, string $expectedContentFilePath): void
|
||||
{
|
||||
$rectors = $this->createRectorsFromRectorClasses($rectorClasses);
|
||||
|
||||
$printedContent = $this->rectorsDocumentationPrinter->print($rectors, $isRectorProject);
|
||||
$expectedFileInfo = new SmartFileInfo($expectedContentFilePath);
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
$expectedContentFilePath,
|
||||
$printedContent,
|
||||
$expectedFileInfo->getRelativeFilePathFromCwd()
|
||||
);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
yield [
|
||||
[TypedPropertyRector::class, RenamePropertyRector::class],
|
||||
false,
|
||||
__DIR__ . '/Fixture/expected_rectors.txt',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $rectorClasses
|
||||
* @return RectorInterface[]
|
||||
*/
|
||||
private function createRectorsFromRectorClasses(array $rectorClasses): array
|
||||
{
|
||||
$rectors = [];
|
||||
|
||||
foreach ($rectorClasses as $rectorClass) {
|
||||
$reflectionClass = new ReflectionClass($rectorClass);
|
||||
$rector = $reflectionClass->newInstanceWithoutConstructor();
|
||||
if (! $rector instanceof RectorInterface) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$rectors[] = $rector;
|
||||
}
|
||||
|
||||
return $rectors;
|
||||
}
|
||||
}
|
|
@ -9,9 +9,9 @@ use PhpParser\Node;
|
|||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\PhpParser\Node\CustomNode\FileNode;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
|
@ -30,9 +30,9 @@ final class RemoveProjectFileRector extends AbstractRector implements Configurab
|
|||
*/
|
||||
private $filePathsToRemove = [];
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Remove file relative to project directory', [
|
||||
return new RuleDefinition('Remove file relative to project directory', [
|
||||
new ConfiguredCodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
// someFile/ToBeRemoved.txt
|
||||
|
|
|
@ -275,9 +275,9 @@ final class NodeRepository
|
|||
{
|
||||
$methodName = $methodReflection->getName();
|
||||
|
||||
/** @var string $className */
|
||||
$className = $methodReflection->getDeclaringClass()
|
||||
->getName();
|
||||
$classReflection = $methodReflection->getDeclaringClass();
|
||||
$className = $classReflection->getName();
|
||||
|
||||
return $this->findClassMethod($className, $methodName);
|
||||
}
|
||||
|
||||
|
|
63
packages/node-removal/src/AssignRemover.php
Normal file
63
packages/node-removal/src/AssignRemover.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\NodeRemoval;
|
||||
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\ChangesReporting\Collector\RectorChangeCollector;
|
||||
use Rector\DeadCode\NodeManipulator\LivingCodeManipulator;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PostRector\Collector\NodesToReplaceCollector;
|
||||
|
||||
final class AssignRemover
|
||||
{
|
||||
/**
|
||||
* @var NodesToReplaceCollector
|
||||
*/
|
||||
private $nodesToReplaceCollector;
|
||||
|
||||
/**
|
||||
* @var RectorChangeCollector
|
||||
*/
|
||||
private $rectorChangeCollector;
|
||||
|
||||
/**
|
||||
* @var NodeRemover
|
||||
*/
|
||||
private $nodeRemover;
|
||||
|
||||
/**
|
||||
* @var LivingCodeManipulator
|
||||
*/
|
||||
private $livingCodeManipulator;
|
||||
|
||||
public function __construct(
|
||||
NodesToReplaceCollector $nodesToReplaceCollector,
|
||||
RectorChangeCollector $rectorChangeCollector,
|
||||
NodeRemover $nodeRemover,
|
||||
LivingCodeManipulator $livingCodeManipulator
|
||||
) {
|
||||
$this->nodesToReplaceCollector = $nodesToReplaceCollector;
|
||||
$this->rectorChangeCollector = $rectorChangeCollector;
|
||||
$this->nodeRemover = $nodeRemover;
|
||||
$this->livingCodeManipulator = $livingCodeManipulator;
|
||||
}
|
||||
|
||||
public function removeAssignNode(Assign $assign): void
|
||||
{
|
||||
$currentStatement = $assign->getAttribute(AttributeKey::CURRENT_STATEMENT);
|
||||
$this->livingCodeManipulator->addLivingCodeBeforeNode($assign->var, $currentStatement);
|
||||
|
||||
/** @var Assign $assign */
|
||||
$parent = $assign->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parent instanceof Expression) {
|
||||
$this->livingCodeManipulator->addLivingCodeBeforeNode($assign->expr, $currentStatement);
|
||||
$this->nodeRemover->removeNode($assign);
|
||||
} else {
|
||||
$this->nodesToReplaceCollector->addReplaceNodeWithAnotherNode($assign, $assign->expr);
|
||||
$this->rectorChangeCollector->notifyNodeFileInfo($assign->expr);
|
||||
}
|
||||
}
|
||||
}
|
69
packages/node-removal/src/ClassMethodRemover.php
Normal file
69
packages/node-removal/src/ClassMethodRemover.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\NodeRemoval;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\DeadCode\NodeManipulator\LivingCodeManipulator;
|
||||
use Rector\NodeCollector\NodeCollector\NodeRepository;
|
||||
use Rector\NodeCollector\ValueObject\ArrayCallable;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
|
||||
final class ClassMethodRemover
|
||||
{
|
||||
/**
|
||||
* @var NodeRepository
|
||||
*/
|
||||
private $nodeRepository;
|
||||
|
||||
/**
|
||||
* @var NodeRemover
|
||||
*/
|
||||
private $nodeRemover;
|
||||
|
||||
/**
|
||||
* @var LivingCodeManipulator
|
||||
*/
|
||||
private $livingCodeManipulator;
|
||||
|
||||
public function __construct(
|
||||
NodeRepository $nodeRepository,
|
||||
NodeRemover $nodeRemover,
|
||||
LivingCodeManipulator $livingCodeManipulator
|
||||
) {
|
||||
$this->nodeRepository = $nodeRepository;
|
||||
$this->nodeRemover = $nodeRemover;
|
||||
$this->livingCodeManipulator = $livingCodeManipulator;
|
||||
}
|
||||
|
||||
public function removeClassMethodAndUsages(ClassMethod $classMethod): void
|
||||
{
|
||||
$this->nodeRemover->removeNode($classMethod);
|
||||
|
||||
$calls = $this->nodeRepository->findCallsByClassMethod($classMethod);
|
||||
foreach ($calls as $classMethodCall) {
|
||||
if ($classMethodCall instanceof ArrayCallable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->removeMethodCall($classMethodCall);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MethodCall|StaticCall $node
|
||||
*/
|
||||
private function removeMethodCall(Node $node): void
|
||||
{
|
||||
$currentStatement = $node->getAttribute(AttributeKey::CURRENT_STATEMENT);
|
||||
foreach ($node->args as $arg) {
|
||||
$this->livingCodeManipulator->addLivingCodeBeforeNode($arg->value, $currentStatement);
|
||||
}
|
||||
|
||||
$this->nodeRemover->removeNode($node);
|
||||
}
|
||||
}
|
43
packages/node-removal/src/NodeRemover.php
Normal file
43
packages/node-removal/src/NodeRemover.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\NodeRemoval;
|
||||
|
||||
use PhpParser\Node;
|
||||
use Rector\ChangesReporting\Collector\RectorChangeCollector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PostRector\Collector\NodesToRemoveCollector;
|
||||
|
||||
final class NodeRemover
|
||||
{
|
||||
/**
|
||||
* @var NodesToRemoveCollector
|
||||
*/
|
||||
private $nodesToRemoveCollector;
|
||||
|
||||
/**
|
||||
* @var RectorChangeCollector
|
||||
*/
|
||||
private $rectorChangeCollector;
|
||||
|
||||
public function __construct(
|
||||
NodesToRemoveCollector $nodesToRemoveCollector,
|
||||
RectorChangeCollector $rectorChangeCollector
|
||||
) {
|
||||
$this->nodesToRemoveCollector = $nodesToRemoveCollector;
|
||||
$this->rectorChangeCollector = $rectorChangeCollector;
|
||||
}
|
||||
|
||||
public function removeNode(Node $node): void
|
||||
{
|
||||
// this make sure to keep just added nodes, e.g. added class constant, that doesn't have analysis of full code in this run
|
||||
// if this is missing, there are false positive e.g. for unused private constant
|
||||
$isJustAddedNode = ! (bool) $node->getAttribute(AttributeKey::ORIGINAL_NODE);
|
||||
if ($isJustAddedNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->nodesToRemoveCollector->addNodeToRemove($node);
|
||||
$this->rectorChangeCollector->notifyNodeFileInfo($node);
|
||||
}
|
||||
}
|
|
@ -134,8 +134,8 @@ final class PHPStanNodeScopeResolver
|
|||
|
||||
// traversing trait inside class that is using it scope (from referenced) - the trait traversed by Rector is different (directly from parsed file)
|
||||
if ($scope->isInTrait()) {
|
||||
$traitName = $scope->getTraitReflection()
|
||||
->getName();
|
||||
$classReflection = $scope->getTraitReflection();
|
||||
$traitName = $classReflection->getName();
|
||||
$this->traitNodeScopeCollector->addForTraitAndNode($traitName, $node, $scope);
|
||||
|
||||
return;
|
||||
|
|
|
@ -9,7 +9,7 @@ use Rector\Core\HttpKernel\RectorKernel;
|
|||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\Testing\TestingParser\TestingParser;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
|
||||
abstract class AbstractNodeTypeResolverTest extends AbstractKernelTestCase
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@ use PHPStan\Type\IterableType;
|
|||
use PHPStan\Type\MixedType;
|
||||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
|
||||
final class StaticTypeMapperTest extends AbstractKernelTestCase
|
||||
{
|
||||
|
|
|
@ -12,7 +12,7 @@ use PHPStan\Type\StringType;
|
|||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Rector\PHPStanStaticTypeMapper\TypeMapper\ArrayTypeMapper;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
|
||||
final class ArrayTypeMapperTest extends AbstractKernelTestCase
|
||||
{
|
||||
|
|
|
@ -15,6 +15,7 @@ use PHPStan\Type\Type;
|
|||
use PHPStan\Type\UnionType;
|
||||
use Rector\ChangesReporting\Collector\RectorChangeCollector;
|
||||
use Rector\Naming\Naming\PropertyNaming;
|
||||
use Rector\NodeRemoval\NodeRemover;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\AliasedObjectType;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
|
@ -65,6 +66,11 @@ trait NodeCommandersTrait
|
|||
*/
|
||||
private $propertyNaming;
|
||||
|
||||
/**
|
||||
* @var NodeRemover
|
||||
*/
|
||||
private $nodeRemover;
|
||||
|
||||
/**
|
||||
* @required
|
||||
*/
|
||||
|
@ -75,7 +81,8 @@ trait NodeCommandersTrait
|
|||
NodesToAddCollector $nodesToAddCollector,
|
||||
NodesToReplaceCollector $nodesToReplaceCollector,
|
||||
RectorChangeCollector $rectorChangeCollector,
|
||||
PropertyNaming $propertyNaming
|
||||
PropertyNaming $propertyNaming,
|
||||
NodeRemover $nodeRemover
|
||||
): void {
|
||||
$this->nodesToRemoveCollector = $nodesToRemoveCollector;
|
||||
$this->propertyToAddCollector = $propertyToAddCollector;
|
||||
|
@ -84,6 +91,7 @@ trait NodeCommandersTrait
|
|||
$this->nodesToAddCollector = $nodesToAddCollector;
|
||||
$this->rectorChangeCollector = $rectorChangeCollector;
|
||||
$this->propertyNaming = $propertyNaming;
|
||||
$this->nodeRemover = $nodeRemover;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,15 +183,7 @@ trait NodeCommandersTrait
|
|||
|
||||
protected function removeNode(Node $node): void
|
||||
{
|
||||
// this make sure to keep just added nodes, e.g. added class constant, that doesn't have analysis of full code in this run
|
||||
// if this is missing, there are false positive e.g. for unused private constant
|
||||
$isJustAddedNode = ! (bool) $node->getAttribute(AttributeKey::ORIGINAL_NODE);
|
||||
if ($isJustAddedNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->nodesToRemoveCollector->addNodeToRemove($node);
|
||||
$this->rectorChangeCollector->notifyNodeFileInfo($node);
|
||||
$this->nodeRemover->removeNode($node);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,9 +5,10 @@ declare(strict_types=1);
|
|||
namespace Rector\PostRector\Rector;
|
||||
|
||||
use PhpParser\Node;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\PSR4\Collector\RenamedClassesCollector;
|
||||
use Rector\Renaming\NodeManipulator\ClassRenamer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
final class ClassRenamingPostRector extends AbstractPostRector
|
||||
{
|
||||
|
@ -43,8 +44,18 @@ final class ClassRenamingPostRector extends AbstractPostRector
|
|||
return $this->classRenamer->renameNode($node, $oldToNewClasses);
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Post Rector that renames classes');
|
||||
return new RuleDefinition('Post Rector that renames classes', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
$someClass = new SomeClass();
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
$someClass = new AnotherClass();
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,11 @@ use PhpParser\Node\Name;
|
|||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\CodingStyle\Node\NameImporter;
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockNameImporter;
|
||||
use Symplify\PackageBuilder\Parameter\ParameterProvider;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
final class NameImportingPostRector extends AbstractPostRector
|
||||
{
|
||||
|
@ -81,10 +82,23 @@ final class NameImportingPostRector extends AbstractPostRector
|
|||
return 600;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
'Imports fully qualified class names in parameter types, return types, extended classes, implemented, interfaces and even docblocks'
|
||||
return new RuleDefinition(
|
||||
'Imports fully qualified class names in parameter types, return types, extended classes, implemented, interfaces and even docblocks',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
$someClass = new \Some\FullyQualified\SomeClass();
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
use Some\FullyQualified\SomeClass;
|
||||
|
||||
$someClass = new SomeClass();
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,9 @@ declare(strict_types=1);
|
|||
namespace Rector\PostRector\Rector;
|
||||
|
||||
use PhpParser\Node;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\PostRector\Collector\NodesToAddCollector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* This class collects all to-be-added expresssions (= 1 line in code)
|
||||
|
@ -62,8 +63,20 @@ final class NodeAddingPostRector extends AbstractPostRector
|
|||
return $newNodes;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Post Rector that adds nodes');
|
||||
return new RuleDefinition('Post Rector that adds nodes',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
$value = 1000;
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
$string = new String_(...);
|
||||
$value = 1000;
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,10 @@ use PhpParser\Node\Expr\BinaryOp;
|
|||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\NodeTraverser;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PostRector\Collector\NodesToRemoveCollector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
final class NodeRemovingRector extends AbstractPostRector
|
||||
{
|
||||
|
@ -31,9 +32,20 @@ final class NodeRemovingRector extends AbstractPostRector
|
|||
$this->nodeFactory = $nodeFactory;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('PostRector that removes nodes');
|
||||
return new RuleDefinition('PostRector that removes nodes', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
$value = 1000;
|
||||
$string = new String_(...);
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
$value = 1000;
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getPriority(): int
|
||||
|
|
|
@ -5,8 +5,9 @@ declare(strict_types=1);
|
|||
namespace Rector\PostRector\Rector;
|
||||
|
||||
use PhpParser\Node;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\PostRector\Collector\NodesToReplaceCollector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
final class NodeToReplacePostRector extends AbstractPostRector
|
||||
{
|
||||
|
@ -36,8 +37,18 @@ final class NodeToReplacePostRector extends AbstractPostRector
|
|||
return null;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Post Rector that replaces one nodes with another');
|
||||
return new RuleDefinition('Post Rector that replaces one nodes with another', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
$string = new String_(...);
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
$value = 1000;
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,10 @@ use PhpParser\Node;
|
|||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Core\PhpParser\Node\Manipulator\ClassDependencyManipulator;
|
||||
use Rector\Core\PhpParser\Node\Manipulator\ClassInsertManipulator;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\PostRector\Collector\PropertyToAddCollector;
|
||||
use Rector\PostRector\NodeAnalyzer\NetteInjectDetector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* Adds new private properties to class + to constructor
|
||||
|
@ -67,9 +68,24 @@ final class PropertyAddingPostRector extends AbstractPostRector
|
|||
return $node;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Post Rector that adds properties');
|
||||
return new RuleDefinition('Post Rector that adds properties', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public $someProperty;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
private function addConstants(Class_ $class): void
|
||||
|
|
|
@ -11,11 +11,12 @@ use PhpParser\Node\Stmt\Namespace_;
|
|||
use Rector\CodingStyle\Application\UseImportsAdder;
|
||||
use Rector\CodingStyle\Application\UseImportsRemover;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PostRector\Collector\UseNodesToAddCollector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class UseAddingPostRector extends AbstractPostRector
|
||||
|
@ -115,9 +116,21 @@ final class UseAddingPostRector extends AbstractPostRector
|
|||
return 500;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Post Rector that adds use statements');
|
||||
return new RuleDefinition('Post Rector that adds use statements', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
$someClass = new SomeClass();
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
use App\SomeClass;
|
||||
|
||||
$someClass = new SomeClass();
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,10 +14,10 @@ use PhpParser\Node\Identifier;
|
|||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\RectorGenerator\Contract\InternalRectorInterface;
|
||||
use Rector\SymfonyPhpConfig\NodeAnalyzer\SymfonyPhpConfigClosureAnalyzer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
final class AddNewServiceToSymfonyPhpConfigRector extends AbstractRector implements InternalRectorInterface
|
||||
{
|
||||
|
@ -68,9 +68,9 @@ final class AddNewServiceToSymfonyPhpConfigRector extends AbstractRector impleme
|
|||
return $node;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Adds a new $services->set(...) call to PHP Config', [
|
||||
return new RuleDefinition('Adds a new $services->set(...) call to PHP Config', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
|
|
@ -20,10 +20,10 @@ final class __Name__ extends AbstractRector implements ConfigurableRectorInterfa
|
|||
|
||||
__ConfigurationProperties__
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('__Description__', [
|
||||
new ConfiguredCodeSample(
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('__Description__', [
|
||||
new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(
|
||||
__CodeBeforeExample__,
|
||||
__CodeAfterExample__,
|
||||
__RuleConfiguration__
|
||||
|
|
|
@ -6,8 +6,8 @@ namespace Rector\__Package__\Rector\__Category__;
|
|||
|
||||
use PhpParser\Node;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
__Resources__
|
||||
|
@ -15,9 +15,9 @@ __Resources__
|
|||
*/
|
||||
final class __Name__ extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('__Description__', [
|
||||
return new RuleDefinition('__Description__', [
|
||||
new CodeSample(
|
||||
__CodeBeforeExample__
|
||||
,
|
||||
|
|
|
@ -26,10 +26,10 @@ public const CLASS_TYPE_TO_METHOD_NAME = 'class_type_to_method_name';
|
|||
*/
|
||||
private $classTypeToMethodName = [];
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Change $service->arg(...) to $service->call(...)', [
|
||||
new ConfiguredCodeSample(
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Change $service->arg(...) to $service->call(...)', [
|
||||
new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(
|
||||
<<<'PHP'
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
|
|
|
@ -26,10 +26,10 @@ public const CLASS_TYPE_TO_METHOD_NAME = 'class_type_to_method_name';
|
|||
*/
|
||||
private $classTypeToMethodName = [];
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Change $service->arg(...) to $service->call(...)', [
|
||||
new ConfiguredCodeSample(
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Change $service->arg(...) to $service->call(...)', [
|
||||
new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(
|
||||
<<<'PHP'
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ use Rector\RectorGenerator\TemplateVariablesFactory;
|
|||
use Rector\RectorGenerator\Tests\RectorGenerator\Source\StaticRectorRecipeFactory;
|
||||
use Rector\RectorGenerator\ValueObject\RectorRecipe;
|
||||
use Symplify\EasyTesting\PHPUnit\Behavior\DirectoryAssertableTrait;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileSystem;
|
||||
|
||||
final class RectorGeneratorTest extends AbstractKernelTestCase
|
||||
|
|
|
@ -55,7 +55,8 @@ final class RectorSetProvider extends AbstractSetProvider
|
|||
}
|
||||
|
||||
$desiredSetFileInfo = new SmartFileInfo($desiredSetName);
|
||||
if ($set->getSetFileInfo()->getRealPath() !== $desiredSetFileInfo->getRealPath()) {
|
||||
$setFileInfo = $set->getSetFileInfo();
|
||||
if ($setFileInfo->getRealPath() !== $desiredSetFileInfo->getRealPath()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace Rector\SimplePhpDocParser\Tests\SimplePhpDocParser;
|
|||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Rector\SimplePhpDocParser\SimplePhpDocParser;
|
||||
use Rector\SimplePhpDocParser\ValueObject\Ast\PhpDoc\SimplePhpDocNode;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class SimplePhpDocParserTest extends AbstractKernelTestCase
|
||||
|
|
|
@ -8,7 +8,7 @@ use PHPStan\Type\UnionType;
|
|||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Rector\SymfonyPhpConfig\Tests\Functions\Source\ServiceWithValueObject;
|
||||
use Rector\SymfonyPhpConfig\Tests\Functions\Source\WithType;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
|
||||
final class ConfigFactoryNestedTest extends AbstractKernelTestCase
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@ use PHPStan\Type\StringType;
|
|||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Rector\SymfonyPhpConfig\Tests\Functions\Source\ServiceWithValueObject;
|
||||
use Rector\SymfonyPhpConfig\Tests\Functions\Source\WithType;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
|
||||
final class ConfigFactoryTest extends AbstractKernelTestCase
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@ use Rector\Core\HttpKernel\RectorKernel;
|
|||
use Rector\Core\PhpParser\Parser\Parser;
|
||||
use Rector\Testing\Contract\NodeTraversableInterface;
|
||||
use Rector\Testing\Node\NodeAttributeExtractor;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,7 +37,7 @@ use Symplify\EasyTesting\DataProvider\StaticFixtureFinder;
|
|||
use Symplify\EasyTesting\DataProvider\StaticFixtureUpdater;
|
||||
use Symplify\EasyTesting\StaticFixtureSplitter;
|
||||
use Symplify\PackageBuilder\Parameter\ParameterProvider;
|
||||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
use Symplify\SmartFileSystem\SmartFileSystem;
|
||||
|
||||
|
|
110
phpstan.neon
110
phpstan.neon
|
@ -4,25 +4,37 @@ includes:
|
|||
- vendor/symplify/phpstan-extensions/config/config.neon
|
||||
|
||||
# see https://github.com/symplify/coding-standard
|
||||
- vendor/symplify/coding-standard/config/symplify-rules.neon
|
||||
- vendor/symplify/coding-standard/packages/cognitive-complexity/config/cognitive-complexity-services.neon
|
||||
# - vendor/symplify/phpstan-rules/config/configurable-rules.neon
|
||||
- vendor/symplify/phpstan-rules/config/static-rules.neon
|
||||
- vendor/symplify/phpstan-rules/packages/cognitive-complexity/config/cognitive-complexity-services.neon
|
||||
|
||||
- vendor/symplify/phpstan-rules/config/symplify-rules/array-rules.neon
|
||||
- vendor/symplify/phpstan-rules/config/symplify-rules/code-complexity-rules.neon
|
||||
- vendor/symplify/phpstan-rules/config/symplify-rules/static-rules.neon
|
||||
- vendor/symplify/phpstan-rules/config/symplify-rules/doctrine-rules.neon
|
||||
- vendor/symplify/phpstan-rules/config/symplify-rules/naming-rules.neon
|
||||
- vendor/symplify/phpstan-rules/config/symplify-rules/regex-rules.neon
|
||||
- vendor/symplify/phpstan-rules/config/symplify-rules/symfony-rules.neon
|
||||
- vendor/symplify/phpstan-rules/config/symplify-rules/test-rules.neon
|
||||
- vendor/symplify/phpstan-rules/config/symplify-rules/services-rules.neon
|
||||
- vendor/symplify/phpstan-rules/config/symplify-rules/string-to-constant-rules.neon
|
||||
|
||||
services:
|
||||
-
|
||||
class: Symplify\CodingStandard\CognitiveComplexity\Rules\FunctionLikeCognitiveComplexityRule
|
||||
class: Symplify\PHPStanRules\CognitiveComplexity\Rules\FunctionLikeCognitiveComplexityRule
|
||||
tags: [phpstan.rules.rule]
|
||||
arguments:
|
||||
maxMethodCognitiveComplexity: 9
|
||||
|
||||
-
|
||||
class: Symplify\CodingStandard\CognitiveComplexity\Rules\ClassLikeCognitiveComplexityRule
|
||||
class: Symplify\PHPStanRules\CognitiveComplexity\Rules\ClassLikeCognitiveComplexityRule
|
||||
tags: [phpstan.rules.rule]
|
||||
arguments:
|
||||
maxClassCognitiveComplexity: 50
|
||||
|
||||
# require constant in argument position
|
||||
-
|
||||
class: Symplify\CodingStandard\Rules\RequireMethodCallArgumentConstantRule
|
||||
class: Symplify\PHPStanRules\Rules\RequireMethodCallArgumentConstantRule
|
||||
tags: [phpstan.rules.rule]
|
||||
arguments:
|
||||
constantArgByMethodByType:
|
||||
|
@ -37,7 +49,7 @@ services:
|
|||
setAttribute: [0]
|
||||
|
||||
-
|
||||
class: Symplify\CodingStandard\Rules\SeeAnnotationToTestRule
|
||||
class: Symplify\PHPStanRules\Rules\SeeAnnotationToTestRule
|
||||
tags: [phpstan.rules.rule]
|
||||
arguments:
|
||||
requiredSeeTypes:
|
||||
|
@ -46,7 +58,7 @@ services:
|
|||
- Rector\FileSystemRector\Rector\AbstractFileSystemRector
|
||||
|
||||
-
|
||||
class: Symplify\CodingStandard\Rules\NoStaticCallRule
|
||||
class: Symplify\PHPStanRules\Rules\NoStaticCallRule
|
||||
tags: [phpstan.rules.rule]
|
||||
arguments:
|
||||
allowedStaticCallClasses:
|
||||
|
@ -55,7 +67,7 @@ services:
|
|||
|
||||
# this rule prevents bug in phar like these: https://github.com/rectorphp/rector/pull/3692/files
|
||||
-
|
||||
class: Symplify\CodingStandard\Rules\RequireStringArgumentInMethodCallRule
|
||||
class: Symplify\PHPStanRules\Rules\RequireStringArgumentInMethodCallRule
|
||||
tags: [phpstan.rules.rule]
|
||||
arguments:
|
||||
stringArgByMethodByType:
|
||||
|
@ -63,38 +75,37 @@ services:
|
|||
isObjectType: [1]
|
||||
|
||||
-
|
||||
class: Symplify\CodingStandard\Rules\ClassNameRespectsParentSuffixRule
|
||||
class: Symplify\PHPStanRules\Rules\ClassNameRespectsParentSuffixRule
|
||||
tags: [phpstan.rules.rule]
|
||||
arguments:
|
||||
parentClasses:
|
||||
- Rector
|
||||
|
||||
-
|
||||
class: Symplify\CodingStandard\Rules\PreferredClassRule
|
||||
tags: [phpstan.rules.rule]
|
||||
arguments:
|
||||
oldToPrefferedClasses:
|
||||
# prevent PHPStorm autocomplete mess
|
||||
'Symfony\Component\DependencyInjection\Variable': 'PhpParser\Node\Expr\Variable'
|
||||
'phpDocumentor\Reflection\Types\Expression': 'PhpParser\Node\Stmt\Expression'
|
||||
'phpDocumentor\Reflection\DocBlock\Tags\Param': 'PhpParser\Node\Param'
|
||||
'phpDocumentor\Reflection\DocBlock\Tags\Return_': 'PhpParser\Node\Stmt\Return_'
|
||||
'Closure': 'PhpParser\Node\Expr\Closure'
|
||||
'PHPUnit\TextUI\Configuration\Variable': 'PhpParser\Node\Expr\Variable'
|
||||
'PhpCsFixer\FixerDefinition\CodeSample': 'Rector\Core\RectorDefinition\CodeSample'
|
||||
'SebastianBergmann\Type\MixedType': 'PHPStan\Type\MixedType'
|
||||
'Hoa\Protocol\Node\Node': 'PhpParser\Node'
|
||||
'Nette\Utils\FileSystem': 'Symplify\SmartFileSystem\SmartFileSystem'
|
||||
'Symfony\Component\Filesystem\Filesystem': 'Symplify\SmartFileSystem\SmartFileSystem'
|
||||
# builder typo nodes
|
||||
PhpParser\Builder\Use_: Rector\Core\PhpParser\Builder\UseBuilder
|
||||
PhpParser\Builder\Class_: Rector\Core\PhpParser\Builder\ClassBuilder
|
||||
PhpParser\Builder\Method: Rector\Core\PhpParser\Builder\MethodBuilder
|
||||
PhpParser\Builder\Namespace_: Rector\Core\PhpParser\Builder\NamespaceBuilder
|
||||
PhpParser\Builder\Param: Rector\Core\PhpParser\Builder\ParamBuilder
|
||||
PhpParser\Builder\Property: Rector\Core\PhpParser\Builder\PropertyBuilder
|
||||
PhpParser\Builder\TraitUse: Rector\Core\PhpParser\Builder\TraitUseBuilder
|
||||
|
||||
# -
|
||||
# class: Symplify\PHPStanRules\Rules\PreferredClassRule
|
||||
# tags: [phpstan.rules.rule]
|
||||
# arguments:
|
||||
# oldToPrefferedClasses:
|
||||
# # prevent PHPStorm autocomplete mess
|
||||
# 'Symfony\Component\DependencyInjection\Variable': 'PhpParser\Node\Expr\Variable'
|
||||
# 'phpDocumentor\Reflection\Types\Expression': 'PhpParser\Node\Stmt\Expression'
|
||||
# 'phpDocumentor\Reflection\DocBlock\Tags\Param': 'PhpParser\Node\Param'
|
||||
# 'phpDocumentor\Reflection\DocBlock\Tags\Return_': 'PhpParser\Node\Stmt\Return_'
|
||||
# 'Closure': 'PhpParser\Node\Expr\Closure'
|
||||
# 'PHPUnit\TextUI\Configuration\Variable': 'PhpParser\Node\Expr\Variable'
|
||||
# 'PhpCsFixer\FixerDefinition\CodeSample': 'Rector\Core\RectorDefinition\CodeSample'
|
||||
# 'SebastianBergmann\Type\MixedType': 'PHPStan\Type\MixedType'
|
||||
# 'Hoa\Protocol\Node\Node': 'PhpParser\Node'
|
||||
# 'Nette\Utils\FileSystem': 'Symplify\SmartFileSystem\SmartFileSystem'
|
||||
# 'Symfony\Component\Filesystem\Filesystem': 'Symplify\SmartFileSystem\SmartFileSystem'
|
||||
# # builder typo nodes
|
||||
# PhpParser\Builder\Use_: Rector\Core\PhpParser\Builder\UseBuilder
|
||||
# PhpParser\Builder\Class_: Rector\Core\PhpParser\Builder\ClassBuilder
|
||||
# PhpParser\Builder\Method: Rector\Core\PhpParser\Builder\MethodBuilder
|
||||
# PhpParser\Builder\Namespace_: Rector\Core\PhpParser\Builder\NamespaceBuilder
|
||||
# PhpParser\Builder\Param: Rector\Core\PhpParser\Builder\ParamBuilder
|
||||
# PhpParser\Builder\Property: Rector\Core\PhpParser\Builder\PropertyBuilder
|
||||
# PhpParser\Builder\TraitUse: Rector\Core\PhpParser\Builder\TraitUseBuilder
|
||||
|
||||
parameters:
|
||||
level: max
|
||||
|
@ -132,7 +143,6 @@ parameters:
|
|||
- packages/node-type-resolver/tests/NodeVisitor/FunctionMethodAndClassNodeVisitor/FunctionMethodAndClassNodeVisitorTest.php
|
||||
|
||||
# phsptan bug
|
||||
- utils/phpstan-extensions/src/Rule/PreventParentMethodVisibilityOverrideRule.php
|
||||
- utils/phpstan-extensions/src/Rule/KeepRectorNamespaceForRectorRule.php
|
||||
- packages/rector-generator/templates/*
|
||||
# this invalidates whole cache everytime
|
||||
|
@ -686,7 +696,7 @@ parameters:
|
|||
# finder type
|
||||
- '#Method Rector\\SOLID\\Rector\\Assign\\MoveVariableDeclarationNearReferenceRector\:\:findFirstVariableUsageInScope\(\) should return PhpParser\\Node\\Expr\\Variable\|null but returns PhpParser\\Node\|null#'
|
||||
|
||||
- '#Class with base "NodeNameResolver" name is already used in "Symplify\\CodingStandard\\PhpParser\\NodeNameResolver", "Rector\\NodeNameResolver\\NodeNameResolver"\. Use unique name to make classes easy to recognize#'
|
||||
- '#Class with base "NodeNameResolver" name is already used in "Symplify\\PHPStanRules\\PhpParser\\NodeNameResolver", "Rector\\NodeNameResolver\\NodeNameResolver"\. Use unique name to make classes easy to recognize#'
|
||||
- '#Static property Rector\\Testing\\PHPUnit\\AbstractGenericRectorTestCase\:\:\$allRectorContainer \(Rector\\Naming\\Tests\\Rector\\Class_\\RenamePropertyToMatchTypeRector\\Source\\ContainerInterface\|Symfony\\Component\\DependencyInjection\\Container\|null\) does not accept Psr\\Container\\ContainerInterface#'
|
||||
|
||||
- '#Class with base "Application" name is already used in "(.*?)\\Symfony\\Component\\Console\\Application", "Symfony\\Component\\Console\\Application", "Rector\\Core\\Console\\Application"\. Use unique name to make classes easy to recognize#'
|
||||
|
@ -700,3 +710,29 @@ parameters:
|
|||
# trait in trait call
|
||||
- '#Call to an undefined method Rector\\PostRector\\Rector\\AbstractPostRector\:\:isObjectType\(\)#'
|
||||
- '#Parameter \#1 \$expr of class PhpParser\\Node\\Stmt\\Expression constructor expects PhpParser\\Node\\Expr, PhpParser\\Node\\Expr\|PhpParser\\Node\\Stmt given#'
|
||||
|
||||
-
|
||||
message: '#Class cognitive complexity is \d+, keep it under 50#'
|
||||
paths:
|
||||
- rules/php70/src/EregToPcreTransformer.php
|
||||
- packages/node-collector/src/NodeCollector/NodeRepository.php
|
||||
- packages/node-type-resolver/src/NodeTypeResolver.php
|
||||
|
||||
# symplify 9
|
||||
- '#Use decoupled factory service to create "(.*?)" object#'
|
||||
- '#Use "\$class\-\>namespaceName" instead of "\$class\-\>name" that only returns short class name#'
|
||||
- '#Method call on new expression is not allowed#'
|
||||
- '#Constant string value need to only have small letters, _, \-, \. and numbers#'
|
||||
- '#Method nor static call in if \(\) or elseif \(\) is not allowed\. Extract expression to a new variable assign on line before#'
|
||||
- '#Use another value object over array with string\-keys and objects, array<string, ValueObject\>#'
|
||||
- '#SymfonyStyle usage is unneeded for only newline, write, and/or writeln, use PHP_EOL and concatenation instead#'
|
||||
- '#Method nor static call in foreach is not allowed\. Extract expression to a new variable assign on line before#'
|
||||
- '#Trait method "(.*?)" should not contain any logic, but only delegate to other class call#'
|
||||
- '#Do not use factory/method call in constructor\. Put factory in config and get service with dependency injection#'
|
||||
- '#Property with protected modifier is not allowed\. Use interface contract method instead#'
|
||||
|
||||
-
|
||||
message: '#Use explicit names over dynamic ones#'
|
||||
paths:
|
||||
- packages/doctrine-annotation-generated/src/PhpDocNode/ConstantReferenceIdentifierRestorer.php # 61
|
||||
- packages/doctrine-annotation-generated/src/PhpDocNode/ConstantReferenceIdentifierRestorer.php # 122
|
||||
|
|
|
@ -8,9 +8,9 @@ use PhpParser\Node;
|
|||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DoctrineCodeQuality\Tests\Rector\DoctrineRepositoryAsService\DoctrineRepositoryAsServiceTest
|
||||
|
@ -33,9 +33,9 @@ final class ReplaceParentRepositoryCallsByRepositoryPropertyRector extends Abstr
|
|||
'matching',
|
||||
];
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
return new RuleDefinition(
|
||||
'Handles method calls in child of Doctrine EntityRepository and moves them to $this->repository property.',
|
||||
[
|
||||
new CodeSample(
|
||||
|
|
|
@ -16,11 +16,11 @@ use PHPStan\Type\ObjectType;
|
|||
use Rector\Core\Exception\Bridge\RectorProviderException;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\Doctrine\Contract\Mapper\DoctrineEntityAndRepositoryMapperInterface;
|
||||
use Rector\Naming\Naming\PropertyNaming;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DoctrineCodeQuality\Tests\Rector\DoctrineRepositoryAsService\DoctrineRepositoryAsServiceTest
|
||||
|
@ -45,9 +45,9 @@ final class ServiceLocatorToDIRector extends AbstractRector
|
|||
$this->propertyNaming = $propertyNaming;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
return new RuleDefinition(
|
||||
'Turns $this->getRepository() in Symfony Controller to constructor injection and private property access.',
|
||||
[
|
||||
new CodeSample(
|
||||
|
|
|
@ -9,8 +9,8 @@ use PhpParser\Node;
|
|||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Core\PhpParser\Node\CustomNode\FileNode;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
|
@ -27,9 +27,10 @@ final class MoveEntitiesToEntityDirectoryRector extends AbstractRector
|
|||
*/
|
||||
private const ENTITY_PATH_REGEX = '#\bEntity\b#';
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Move entities to Entity namespace', [new CodeSample(
|
||||
return new RuleDefinition('Move entities to Entity namespace', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
// file: app/Controller/Product.php
|
||||
|
||||
|
@ -59,7 +60,8 @@ class Product
|
|||
{
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,9 +8,9 @@ use PhpParser\Node;
|
|||
use PhpParser\Node\Stmt\Interface_;
|
||||
use Rector\Core\PhpParser\Node\CustomNode\FileNode;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NetteToSymfony\Analyzer\NetteControlFactoryInterfaceAnalyzer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
|
@ -31,9 +31,10 @@ final class MoveInterfacesToContractNamespaceDirectoryRector extends AbstractRec
|
|||
$this->netteControlFactoryInterfaceAnalyzer = $netteControlFactoryInterfaceAnalyzer;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Move interface to "Contract" namespace', [new CodeSample(
|
||||
return new RuleDefinition('Move interface to "Contract" namespace', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
// file: app/Exception/Rule.php
|
||||
|
||||
|
@ -53,7 +54,8 @@ interface Rule
|
|||
{
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,8 +10,8 @@ use Rector\Autodiscovery\FileLocation\ExpectedFileLocationResolver;
|
|||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\PhpParser\Node\CustomNode\FileNode;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
|
@ -45,9 +45,9 @@ final class MoveServicesBySuffixToDirectoryRector extends AbstractRector impleme
|
|||
$this->expectedFileLocationResolver = $expectedFileLocationResolver;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Move classes by their suffix to their own group/directory', [
|
||||
return new RuleDefinition('Move classes by their suffix to their own group/directory', [
|
||||
new ConfiguredCodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
// file: app/Entity/ProductRepository.php
|
||||
|
|
|
@ -11,9 +11,9 @@ use Rector\Autodiscovery\Analyzer\ClassAnalyzer;
|
|||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\PhpParser\Node\CustomNode\FileNode;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* Inspiration @see https://github.com/rectorphp/rector/pull/1865/files#diff-0d18e660cdb626958662641b491623f8
|
||||
|
@ -73,9 +73,9 @@ final class MoveValueObjectsToValueObjectDirectoryRector extends AbstractRector
|
|||
$this->classAnalyzer = $classAnalyzer;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Move value object to ValueObject namespace/directory', [
|
||||
return new RuleDefinition('Move value object to ValueObject namespace/directory', [
|
||||
new ConfiguredCodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
// app/Exception/Name.php
|
||||
|
|
|
@ -10,9 +10,9 @@ use PhpParser\Node\Name;
|
|||
use Rector\CakePHP\ImplicitNameResolver;
|
||||
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see https://github.com/cakephp/upgrade/blob/05d85c147bb1302b576b818cabb66a40462aaed0/src/Shell/Task/AppUsesTask.php#L183
|
||||
|
@ -31,9 +31,9 @@ final class ImplicitShortClassNameUseStatementRector extends AbstractRector
|
|||
$this->implicitNameResolver = $implicitNameResolver;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Collect implicit class names and add imports', [
|
||||
return new RuleDefinition('Collect implicit class names and add imports', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
use App\Foo\Plugin;
|
||||
|
|
|
@ -14,8 +14,8 @@ use Rector\CakePHP\ValueObject\ArrayToFluentCall;
|
|||
use Rector\CakePHP\ValueObject\FactoryMethod;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
|
@ -43,9 +43,9 @@ final class ArrayToFluentCallRector extends AbstractRector implements Configurab
|
|||
*/
|
||||
private $factoryMethods = [];
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Moves array options to fluent setter method calls.', [
|
||||
return new RuleDefinition('Moves array options to fluent setter method calls.', [
|
||||
new ConfiguredCodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
use Cake\ORM\Table;
|
||||
|
|
|
@ -11,8 +11,8 @@ use PhpParser\Node\Identifier;
|
|||
use Rector\CakePHP\ValueObject\ModalToGetSet;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
|
@ -33,9 +33,9 @@ final class ModalToGetSetRector extends AbstractRector implements ConfigurableRe
|
|||
*/
|
||||
private $unprefixedMethodsToGetSet = [];
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
return new RuleDefinition(
|
||||
'Changes combined set/get `value()` to specific `getValue()` or `setValue(x)`.',
|
||||
[
|
||||
new ConfiguredCodeSample(
|
||||
|
|
|
@ -10,8 +10,8 @@ use PhpParser\Node\Identifier;
|
|||
use Rector\CakePHP\ValueObject\RenameMethodCallBasedOnParameter;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ final class RenameMethodCallBasedOnParameterRector extends AbstractRector implem
|
|||
*/
|
||||
private $callsWithParamRenames = [];
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
$configuration = [
|
||||
self::CALLS_WITH_PARAM_RENAMES => [
|
||||
|
@ -40,7 +40,7 @@ final class RenameMethodCallBasedOnParameterRector extends AbstractRector implem
|
|||
new RenameMethodCallBasedOnParameter('ServerRequest', 'withParam', 'paging', 'withAttribute'),
|
||||
],
|
||||
];
|
||||
return new RectorDefinition(
|
||||
return new RuleDefinition(
|
||||
'Changes method calls based on matching the first parameter value.',
|
||||
[
|
||||
new ConfiguredCodeSample(
|
||||
|
|
|
@ -12,8 +12,8 @@ use PhpParser\Node\Stmt\Use_;
|
|||
use Rector\CakePHP\Naming\CakePHPFullyQualifiedClassNameResolver;
|
||||
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see https://github.com/cakephp/upgrade/blob/756410c8b7d5aff9daec3fa1fe750a3858d422ac/src/Shell/Task/AppUsesTask.php
|
||||
|
@ -33,9 +33,9 @@ final class AppUsesStaticCallToUseStatementRector extends AbstractRector
|
|||
$this->cakePHPFullyQualifiedClassNameResolver = $cakePHPFullyQualifiedClassNameResolver;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Change App::uses() to use imports', [
|
||||
return new RuleDefinition('Change App::uses() to use imports', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
App::uses('NotificationListener', 'Event');
|
||||
|
|
|
@ -9,10 +9,10 @@ use PhpParser\Node\Expr\Array_;
|
|||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\Core\Util\StaticRectorStrings;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CakePHP\Tests\Rector\Property\ChangeSnakedFixtureNameToPascal\ChangeSnakedFixtureNameToPascalTest
|
||||
|
@ -21,9 +21,9 @@ use Rector\NodeTypeResolver\Node\AttributeKey;
|
|||
*/
|
||||
final class ChangeSnakedFixtureNameToPascalRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Changes $fixtues style from snake_case to PascalCase.', [
|
||||
return new RuleDefinition('Changes $fixtues style from snake_case to PascalCase.', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeTest
|
||||
|
|
|
@ -8,8 +8,8 @@ use PhpParser\Node;
|
|||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see https://carbon.nesbot.com/docs/#api-carbon-2
|
||||
|
@ -38,11 +38,13 @@ final class ChangeCarbonSingularMethodCallToPluralRector extends AbstractRector
|
|||
'subYear' => 'subYears',
|
||||
];
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Change setter methods with args to their plural names on Carbon\Carbon', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Change setter methods with args to their plural names on Carbon\Carbon',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
use Carbon\Carbon;
|
||||
|
||||
final class SomeClass
|
||||
|
@ -54,8 +56,8 @@ final class SomeClass
|
|||
}
|
||||
CODE_SAMPLE
|
||||
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
use Carbon\Carbon;
|
||||
|
||||
final class SomeClass
|
||||
|
@ -67,8 +69,9 @@ final class SomeClass
|
|||
}
|
||||
CODE_SAMPLE
|
||||
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,8 +7,8 @@ namespace Rector\Carbon\Rector\MethodCall;
|
|||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see https://carbon.nesbot.com/docs/#api-carbon-2
|
||||
|
@ -17,11 +17,13 @@ use Rector\Core\RectorDefinition\RectorDefinition;
|
|||
*/
|
||||
final class ChangeDiffForHumansArgsRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Change methods arguments of diffForHumans() on Carbon\Carbon', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Change methods arguments of diffForHumans() on Carbon\Carbon',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
use Carbon\Carbon;
|
||||
|
||||
final class SomeClass
|
||||
|
@ -35,8 +37,8 @@ final class SomeClass
|
|||
}
|
||||
CODE_SAMPLE
|
||||
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
use Carbon\Carbon;
|
||||
|
||||
final class SomeClass
|
||||
|
@ -50,8 +52,9 @@ final class SomeClass
|
|||
}
|
||||
CODE_SAMPLE
|
||||
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,10 +14,10 @@ use PhpParser\Node\Expr\PropertyFetch;
|
|||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeCollector\NodeAnalyzer\ArrayCallableMethodReferenceAnalyzer;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CodeQuality\Tests\Rector\Array_\ArrayThisCallToThisMethodCallRector\ArrayThisCallToThisMethodCallRectorTest
|
||||
|
@ -34,11 +34,13 @@ final class ArrayThisCallToThisMethodCallRector extends AbstractRector
|
|||
$this->arrayCallableMethodReferenceAnalyzer = $arrayCallableMethodReferenceAnalyzer;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Change `[$this, someMethod]` without any args to $this->someMethod()', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Change `[$this, someMethod]` without any args to $this->someMethod()',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
|
@ -53,7 +55,7 @@ class SomeClass
|
|||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
|
@ -67,8 +69,9 @@ class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,9 +24,9 @@ use PHPStan\Type\Type;
|
|||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see https://www.php.net/manual/en/language.types.callable.php#117260
|
||||
|
@ -37,11 +37,13 @@ use Rector\NodeTypeResolver\Node\AttributeKey;
|
|||
*/
|
||||
final class CallableThisArrayToAnonymousFunctionRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Convert [$this, "method"] to proper anonymous function', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Convert [$this, "method"] to proper anonymous function',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
|
@ -58,8 +60,8 @@ class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
|
@ -78,8 +80,9 @@ class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,8 +9,8 @@ use PhpParser\Node\Expr\Assign;
|
|||
use PhpParser\Node\Expr\BinaryOp;
|
||||
use Rector\Core\PhpParser\Node\AssignAndBinaryMap;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CodeQuality\Tests\Rector\Assign\CombinedAssignRector\CombinedAssignRectorTest
|
||||
|
@ -27,9 +27,9 @@ final class CombinedAssignRector extends AbstractRector
|
|||
$this->assignAndBinaryMap = $assignAndBinaryMap;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
return new RuleDefinition(
|
||||
'Simplify $value = $value + 5; assignments to shorter ones',
|
||||
[new CodeSample('$value = $value + 5;', '$value += 5;')]
|
||||
);
|
||||
|
|
|
@ -9,8 +9,8 @@ use PhpParser\Node\Expr\Array_;
|
|||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\List_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see https://mobile.twitter.com/ivanhoe011/status/1246376872931401728
|
||||
|
@ -19,11 +19,13 @@ use Rector\Core\RectorDefinition\RectorDefinition;
|
|||
*/
|
||||
final class SplitListAssignToSeparateLineRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Splits `[$a, $b] = [5, 10]` scalar assign to standalone lines', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Splits `[$a, $b] = [5, 10]` scalar assign to standalone lines',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function run(): void
|
||||
|
@ -33,7 +35,7 @@ final class SomeClass
|
|||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function run(): void
|
||||
|
@ -43,8 +45,9 @@ final class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,8 +11,8 @@ use PhpParser\Node\Expr\BinaryOp\Identical;
|
|||
use PhpParser\Node\Expr\Empty_;
|
||||
use Rector\Core\PhpParser\Node\Manipulator\BinaryOpManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see https://3v4l.org/EZ2P4
|
||||
|
@ -31,9 +31,9 @@ final class SimplifyEmptyArrayCheckRector extends AbstractRector
|
|||
$this->binaryOpManipulator = $binaryOpManipulator;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
return new RuleDefinition(
|
||||
'Simplify `is_array` and `empty` functions combination into a simple identical check for an empty array',
|
||||
[new CodeSample('is_array($values) && empty($values)', '$values === []')]
|
||||
);
|
||||
|
|
|
@ -10,8 +10,8 @@ use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
|
|||
use PhpParser\Node\Expr\BooleanNot;
|
||||
use Rector\Core\PhpParser\Node\Manipulator\BinaryOpManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see https://robots.thoughtbot.com/clearer-conditionals-using-de-morgans-laws
|
||||
|
@ -30,27 +30,30 @@ final class SimplifyDeMorganBinaryRector extends AbstractRector
|
|||
$this->binaryOpManipulator = $binaryOpManipulator;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Simplify negated conditions with de Morgan theorem', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Simplify negated conditions with de Morgan theorem',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
<?php
|
||||
|
||||
$a = 5;
|
||||
$b = 10;
|
||||
$result = !($a > 20 || $b <= 50);
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
<?php
|
||||
|
||||
$a = 5;
|
||||
$b = 10;
|
||||
$result = $a <= 20 && $b > 50;
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,12 +15,12 @@ use PhpParser\Node\Stmt\Catch_;
|
|||
use PhpParser\Node\Stmt\Throw_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use ReflectionNamedType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
|
@ -34,9 +34,9 @@ final class ThrowWithPreviousExceptionRector extends AbstractRector
|
|||
*/
|
||||
private const DEFAULT_EXCEPTION_ARGUMENT_POSITION = 2;
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
return new RuleDefinition(
|
||||
'When throwing into a catch block, checks that the previous exception is passed to the new throw clause',
|
||||
[
|
||||
new CodeSample(
|
||||
|
|
|
@ -11,8 +11,8 @@ use Rector\CodeQuality\NodeAnalyzer\ClassLikeAnalyzer;
|
|||
use Rector\CodeQuality\NodeAnalyzer\LocalPropertyAnalyzer;
|
||||
use Rector\CodeQuality\NodeFactory\MissingPropertiesFactory;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see https://3v4l.org/GL6II
|
||||
|
@ -48,9 +48,9 @@ final class CompleteDynamicPropertiesRector extends AbstractRector
|
|||
$this->classLikeAnalyzer = $classLikeAnalyzer;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Add missing dynamic properties', [
|
||||
return new RuleDefinition('Add missing dynamic properties', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
|
|
|
@ -9,9 +9,9 @@ use PhpParser\Node;
|
|||
use PhpParser\Node\Expr\BinaryOp\Concat;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CodeQuality\Tests\Rector\Concat\JoinStringConcatRector\JoinStringConcatRectorTest
|
||||
|
@ -28,11 +28,13 @@ final class JoinStringConcatRector extends AbstractRector
|
|||
*/
|
||||
private $nodeReplacementIsRestricted = false;
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Joins concat of 2 strings, unless the lenght is too long', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Joins concat of 2 strings, unless the lenght is too long',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
|
@ -41,8 +43,8 @@ class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
|
@ -51,8 +53,9 @@ class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,19 +12,21 @@ use PhpParser\Node\Expr\BinaryOp\NotIdentical;
|
|||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CodeQuality\Tests\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector\UseIdenticalOverEqualWithSameTypeRectorTest
|
||||
*/
|
||||
final class UseIdenticalOverEqualWithSameTypeRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Use ===/!== over ==/!=, it values have the same type', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Use ===/!== over ==/!=, it values have the same type',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run(int $firstValue, int $secondValue)
|
||||
|
@ -34,8 +36,8 @@ class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run(int $firstValue, int $secondValue)
|
||||
|
@ -45,8 +47,9 @@ class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,8 +11,8 @@ use PhpParser\Node\Stmt\Expression;
|
|||
use PhpParser\Node\Stmt\If_;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see https://3v4l.org/dmHCC
|
||||
|
@ -21,9 +21,9 @@ use Rector\Core\RectorDefinition\RectorDefinition;
|
|||
*/
|
||||
final class InlineIfToExplicitIfRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Change inline if to explicit if', [
|
||||
return new RuleDefinition('Change inline if to explicit if', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
|
|
|
@ -10,10 +10,10 @@ use PhpParser\Node\Expr\FuncCall;
|
|||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\For_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NetteKdyby\Naming\VariableNaming;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CodeQuality\Tests\Rector\For_\ForRepeatedCountToOwnVariableRector\ForRepeatedCountToOwnVariableRectorTest
|
||||
|
@ -30,11 +30,13 @@ final class ForRepeatedCountToOwnVariableRector extends AbstractRector
|
|||
$this->variableNaming = $variableNaming;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Change count() in for function to own variable', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Change count() in for function to own variable',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run($items)
|
||||
|
@ -46,7 +48,7 @@ class SomeClass
|
|||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run($items)
|
||||
|
@ -58,8 +60,9 @@ class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,9 +23,9 @@ use PhpParser\Node\Stmt\Unset_;
|
|||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\PhpParser\Node\Manipulator\AssignManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CodeQuality\Tests\Rector\For_\ForToForeachRector\ForToForeachRectorTest
|
||||
|
@ -73,9 +73,9 @@ final class ForToForeachRector extends AbstractRector
|
|||
$this->inflector = $inflector;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Change for() to foreach() where useful', [
|
||||
return new RuleDefinition('Change for() to foreach() where useful', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
|
|
|
@ -10,9 +10,9 @@ use PhpParser\Node\Stmt\Foreach_;
|
|||
use Rector\CodeQuality\NodeAnalyzer\ForeachNodeAnalyzer;
|
||||
use Rector\Core\NodeFinder\NodeUsageFinder;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CodeQuality\Tests\Rector\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector\ForeachItemsAssignToEmptyArrayToAssignRectorTest
|
||||
|
@ -35,11 +35,13 @@ final class ForeachItemsAssignToEmptyArrayToAssignRector extends AbstractRector
|
|||
$this->foreachNodeAnalyzer = $foreachNodeAnalyzer;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Change foreach() items assign to empty array to direct assign', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Change foreach() items assign to empty array to direct assign',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run($items)
|
||||
|
@ -53,7 +55,7 @@ class SomeClass
|
|||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run($items)
|
||||
|
@ -64,8 +66,9 @@ class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,10 +19,10 @@ use PHPStan\Type\ObjectType;
|
|||
use Rector\Core\PhpDoc\CommentCombiner;
|
||||
use Rector\Core\PhpParser\Node\Manipulator\BinaryOpManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Php71\ValueObject\TwoNodeMatch;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CodeQuality\Tests\Rector\Foreach_\ForeachToInArrayRector\ForeachToInArrayRectorTest
|
||||
|
@ -45,9 +45,9 @@ final class ForeachToInArrayRector extends AbstractRector
|
|||
$this->commentCombiner = $commentCombiner;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
return new RuleDefinition(
|
||||
'Simplify `foreach` loops into `in_array` when possible',
|
||||
[
|
||||
new CodeSample(
|
||||
|
|
|
@ -15,19 +15,21 @@ use PhpParser\Node\Stmt\Expression;
|
|||
use PhpParser\Node\Stmt\Foreach_;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CodeQuality\Tests\Rector\Foreach_\SimplifyForeachToArrayFilterRector\SimplifyForeachToArrayFilterRectorTest
|
||||
*/
|
||||
final class SimplifyForeachToArrayFilterRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Simplify foreach with function filtering to array filter', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Simplify foreach with function filtering to array filter',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
$directories = [];
|
||||
$possibleDirectories = [];
|
||||
foreach ($possibleDirectories as $possibleDirectory) {
|
||||
|
@ -36,13 +38,14 @@ foreach ($possibleDirectories as $possibleDirectory) {
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
$possibleDirectories = [];
|
||||
$directories = array_filter($possibleDirectories, 'file_exists');
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,10 +15,10 @@ use PhpParser\Node\Stmt\If_;
|
|||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\Core\PhpParser\Node\Manipulator\ForeachManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see https://3v4l.org/bfsdY
|
||||
|
@ -42,11 +42,13 @@ final class SimplifyForeachToCoalescingRector extends AbstractRector
|
|||
$this->foreachManipulator = $foreachManipulator;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Changes foreach that returns set value to ??', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Changes foreach that returns set value to ??',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
foreach ($this->oldToNewFunctions as $oldFunction => $newFunction) {
|
||||
if ($currentFunction === $oldFunction) {
|
||||
return $newFunction;
|
||||
|
@ -55,12 +57,13 @@ foreach ($this->oldToNewFunctions as $oldFunction => $newFunction) {
|
|||
|
||||
return null;
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
return $this->oldToNewFunctions[$currentFunction] ?? null;
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,19 +9,21 @@ use PhpParser\Node\Expr\Array_;
|
|||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Foreach_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CodeQuality\Tests\Rector\Foreach_\UnusedForeachValueToArrayKeysRector\UnusedForeachValueToArrayKeysRectorTest
|
||||
*/
|
||||
final class UnusedForeachValueToArrayKeysRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Change foreach with unused $value but only $key, to array_keys()', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Change foreach with unused $value but only $key, to array_keys()',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
|
@ -34,7 +36,7 @@ class SomeClass
|
|||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
|
@ -46,8 +48,9 @@ class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,9 +11,9 @@ use PhpParser\Node\Expr\BinaryOp\Concat;
|
|||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CodeQuality\Tests\Rector\FuncCall\AddPregQuoteDelimiterRector\AddPregQuoteDelimiterRectorTest
|
||||
|
@ -26,9 +26,9 @@ final class AddPregQuoteDelimiterRector extends AbstractRector
|
|||
*/
|
||||
private const ALL_MODIFIERS = 'imsxeADSUXJu';
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Add preg_quote delimiter when missing', [
|
||||
return new RuleDefinition('Add preg_quote delimiter when missing', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
'#' . preg_quote('name') . '#';
|
||||
|
|
|
@ -10,19 +10,21 @@ use PhpParser\Node\Expr\FuncCall;
|
|||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Name;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\CodeQuality\Tests\Rector\FuncCall\ArrayKeysAndInArrayToArrayKeyExistsRector\ArrayKeysAndInArrayToArrayKeyExistsRectorTest
|
||||
*/
|
||||
final class ArrayKeysAndInArrayToArrayKeyExistsRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Replace array_keys() and in_array() to array_key_exists()', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Replace array_keys() and in_array() to array_key_exists()',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run($packageName, $values)
|
||||
|
@ -33,7 +35,7 @@ class SomeClass
|
|||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run($packageName, $values)
|
||||
|
@ -42,8 +44,9 @@ class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,8 +9,8 @@ use PhpParser\Node\Expr\Array_;
|
|||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see https://3v4l.org/aLf96
|
||||
|
@ -21,11 +21,13 @@ use Rector\Core\RectorDefinition\RectorDefinition;
|
|||
*/
|
||||
final class ArrayMergeOfNonArraysToSimpleArrayRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RectorDefinition('Change array_merge of non arrays to array directly', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition(
|
||||
'Change array_merge of non arrays to array directly',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function go()
|
||||
|
@ -38,7 +40,7 @@ class SomeClass
|
|||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function go()
|
||||
|
@ -50,8 +52,9 @@ class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user