diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index d128eb474fb..ee8c6bb4a1f 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -43,6 +43,13 @@ jobs: name: 'Validate Max File Length' run: vendor/bin/easy-ci validate-file-length packages rules src tests + # see https://github.com/rectorphp/rector-generator + - + name: 'Rector Generate From Recipe' + run: | + bin/rector init-recipe --ansi + bin/rector generate --ansi + name: ${{ matrix.actions.name }} runs-on: ubuntu-latest diff --git a/.github/workflows/code_analysis_no_dev.yaml b/.github/workflows/code_analysis_no_dev.yaml index 1e7e7a77fa0..4fb86ca32e6 100644 --- a/.github/workflows/code_analysis_no_dev.yaml +++ b/.github/workflows/code_analysis_no_dev.yaml @@ -9,12 +9,6 @@ jobs: fail-fast: false matrix: actions: - - - name: 'Rector Recipe' - run: | - bin/rector init-recipe --ansi - bin/rector generate --ansi - - name: 'Rector List' run: bin/rector list diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml index c3cc9ecb2e9..4efdbb50a2f 100644 --- a/.github/workflows/rector.yaml +++ b/.github/workflows/rector.yaml @@ -16,7 +16,7 @@ on: pull_request: null jobs: - rector-ci: + rector: strategy: fail-fast: false matrix: diff --git a/composer.json b/composer.json index f67e919250d..59023eb7134 100644 --- a/composer.json +++ b/composer.json @@ -30,15 +30,15 @@ "ext-json": "*", "composer/semver": "^3.2", "composer/xdebug-handler": "^1.4", - "doctrine/annotations": "^1.11", + "doctrine/annotations": "^1.12", "doctrine/inflector": "^2.0", "jean85/pretty-package-versions": "^1.5.1|^2.0.1", "nette/robot-loader": "^3.2 <=3.3.1", "nette/utils": "^3.2", "nikic/php-parser": "^4.10.4", - "phpstan/phpdoc-parser": "^0.4.9", + "phpstan/phpdoc-parser": "^0.4.12", "phpstan/phpstan": "^0.12.81", - "phpstan/phpstan-phpunit": "^0.12.17", + "phpstan/phpstan-phpunit": "^0.12.18", "psr/simple-cache": "^1.0", "sebastian/diff": "^4.0.4", "symfony/cache": "^4.4.8|^5.1", @@ -59,16 +59,17 @@ "symplify/skipper": "^9.2.4", "symplify/smart-file-system": "^9.2.4", "symplify/symfony-php-config": "^9.2.4", - "webmozart/assert": "^1.9" + "webmozart/assert": "^1.10" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.18.2", + "friendsofphp/php-cs-fixer": "^2.18.3", "nette/application": "^3.0.7", "nette/di": "^3.0", "nette/forms": "^3.0", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-nette": "^0.12.14", + "phpstan/phpstan-nette": "^0.12.16", "phpunit/phpunit": "^9.5", + "rector/rector-generator": "^0.1.1", "symfony/security-core": "^5.2", "symfony/security-http": "^5.2", "symplify/coding-standard": "^9.2.4", @@ -138,7 +139,6 @@ "Rector\\Visibility\\": "rules/visibility/src", "Rector\\Removing\\": "rules/removing/src", "Rector\\Privatization\\": "rules/privatization/src", - "Rector\\RectorGenerator\\": "packages/rector-generator/src", "Rector\\RemovingStatic\\": "rules/removing-static/src", "Rector\\Renaming\\": "rules/renaming/src", "Rector\\Restoration\\": "rules/restoration/src", @@ -243,7 +243,6 @@ "Rector\\Php80\\Tests\\": "rules/php80/tests", "Rector\\PhpSpecToPHPUnit\\Tests\\": "rules/php-spec-to-phpunit/tests", "Rector\\Privatization\\Tests\\": "rules/privatization/tests", - "Rector\\RectorGenerator\\Tests\\": "packages/rector-generator/tests", "Rector\\RemovingStatic\\Tests\\": "rules/removing-static/tests", "Rector\\Renaming\\Tests\\": "rules/renaming/tests", "Rector\\Restoration\\Tests\\": "rules/restoration/tests", @@ -285,7 +284,6 @@ "vendor/bin/rule-doc-generator generate packages rules --output-file docs/rector_rules_overview.md --ansi --categorize", "vendor/bin/ecs check-markdown docs/rector_rules_overview.md docs/nodes_overview.md --ansi --fix" ], - "rector-ci": "bin/rector process --dry-run --ansi", "rector": "bin/rector process --ansi" }, "config": { diff --git a/config/services.php b/config/services.php index da2140a08d5..28babc099b0 100644 --- a/config/services.php +++ b/config/services.php @@ -49,6 +49,7 @@ use Symplify\PackageBuilder\Reflection\PrivatesAccessor; use Symplify\PackageBuilder\Reflection\PrivatesCaller; use Symplify\PackageBuilder\Strings\StringFormatConverter; use Symplify\SmartFileSystem\FileSystemFilter; +use Symplify\SmartFileSystem\FileSystemGuard; use Symplify\SmartFileSystem\Finder\FinderSanitizer; use Symplify\SmartFileSystem\Json\JsonFileSystem; use Symplify\SmartFileSystem\SmartFileSystem; @@ -84,11 +85,12 @@ return static function (ContainerConfigurator $containerConfigurator): void { __DIR__ . '/../packages/NodeTypeResolver/Reflection/BetterReflection/RectorBetterReflectionSourceLocatorFactory.php', __DIR__ . '/../packages/Testing/PHPUnit/Runnable/NodeVisitor', __DIR__ . '/../packages/Testing/PHPUnit', - __DIR__ . '/../packages/rector-generator', ]); $services->alias(SymfonyApplication::class, ConsoleApplication::class); + $services->set(FileSystemGuard::class); + $services->set(NoRectorsLoadedReporter::class); $services->set(SimpleCallableNodeTraverser::class); diff --git a/docs/create_own_rule.md b/docs/create_own_rule.md index 4f5d20d23df..8499d36363d 100644 --- a/docs/create_own_rule.md +++ b/docs/create_own_rule.md @@ -145,4 +145,4 @@ That's it! Do you want to save time with making rules and tests? -Use [the `create` command](/docs/rector_recipe.md). +Use [the `generate` command](https://github.com/rectorphp/rector-generator). diff --git a/docs/rector_recipe.md b/docs/rector_recipe.md deleted file mode 100644 index 1b8593e0c10..00000000000 --- a/docs/rector_recipe.md +++ /dev/null @@ -1,45 +0,0 @@ -# Generate a new Rector Rule - -Creating a new Rector rule means many small steps. You need to create rule file, test file, test fixtures, put it into right category, bla bla bla... - -How can we **remove repeated work** and let us focus only on `refactor()` method? - -## What `generate` Command is Does? - -It creates a bare structured Rule. -Don't worry, also generates a test case, which is required to contribute. - -## How to Generate Rector rule? - -There are two possibilities to Generate a Rector rule. - -### Generate using Interactive Mode - -**Important**: using this approach will generate Rector rule with placeholder Code Samples, which should be changed -by hand to reflect what the rule does - -1. Run Generate command in Interactive Mode - - ```bash - vendor/bin/rector generate --interactive - ``` - -2. Provide an answer to questions asked by the command - -### Generate using configuration file - -1. Initialize `rector-recipe.php` config - - ```bash - vendor/bin/rector init-recipe - ``` - -2. Complete parameters in `rector-recipe.php` to design your new rule - -3. Run command - - ```bash - vendor/bin/rector generate - ``` - -That's it :) diff --git a/ecs.php b/ecs.php index f82d3544fef..b08b0d0a302 100644 --- a/ecs.php +++ b/ecs.php @@ -60,8 +60,6 @@ return static function (ContainerConfigurator $containerConfigurator): void { # generated from /vendor __DIR__ . '/packages/DoctrineAnnotationGenerated/ConstantPreservingDocParser.php', __DIR__ . '/packages/DoctrineAnnotationGenerated/ConstantPreservingAnnotationReader.php', - // template files - __DIR__ . '/packages/rector-generator/templates', UnaryOperatorSpacesFixer::class, // buggy with specific markdown snippet file in docs/rules_overview.md diff --git a/packages-tests/BetterPhpDocParser/Attributes/Ast/AttributeAwareNodeFactoryTest.php b/packages-tests/BetterPhpDocParser/Attributes/Ast/AttributeAwareNodeFactoryTest.php index 30b85fa926c..0aaae87f0e4 100644 --- a/packages-tests/BetterPhpDocParser/Attributes/Ast/AttributeAwareNodeFactoryTest.php +++ b/packages-tests/BetterPhpDocParser/Attributes/Ast/AttributeAwareNodeFactoryTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\Attributes\Ast; +namespace Rector\Tests\BetterPhpDocParser\Attributes\Ast; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfo/PhpDocInfoTest.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfo/PhpDocInfoTest.php index ff373cffa25..a1ec6dde542 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfo/PhpDocInfoTest.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfo/PhpDocInfoTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfo; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use PhpParser\Comment\Doc; use PhpParser\Node; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/AbstractPhpDocInfoPrinterTest.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/AbstractPhpDocInfoPrinterTest.php index 7235ee4e4e8..072eb103143 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/AbstractPhpDocInfoPrinterTest.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/AbstractPhpDocInfoPrinterTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter; use Iterator; use PhpParser\Comment\Doc; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/DoctrineTest.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/DoctrineTest.php index 99155e7b78b..866a01eae95 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/DoctrineTest.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/DoctrineTest.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter; use Iterator; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; -use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\CaseSensitive; -use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\IndexInTable; -use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\Short; +use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\CaseSensitive; +use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\IndexInTable; +use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\Short; use Symplify\SmartFileSystem\SmartFileInfo; final class DoctrineTest extends AbstractPhpDocInfoPrinterTest diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/MultilineTest.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/MultilineTest.php index ed6d3dba5fa..d5b8792baf3 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/MultilineTest.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/MultilineTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter; use Iterator; use PhpParser\BuilderFactory; @@ -11,13 +11,13 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Nop; use PhpParser\Node\Stmt\Property; -use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\AnotherPropertyClass; -use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Class_\SomeEntityClass; -use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\DoctrinePropertyClass; -use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\ManyToPropertyClass; -use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\RoutePropertyClass; -use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\SinglePropertyClass; -use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\TableClass; +use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\AnotherPropertyClass; +use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\Class_\SomeEntityClass; +use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\DoctrinePropertyClass; +use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\ManyToPropertyClass; +use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\RoutePropertyClass; +use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\SinglePropertyClass; +use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\TableClass; use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\SmartFileSystem\SmartFileInfo; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/PhpDocInfoPrinterTest.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/PhpDocInfoPrinterTest.php index dcff2260178..a1801185ebe 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/PhpDocInfoPrinterTest.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/PhpDocInfoPrinterTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter; use Iterator; use PhpParser\Node\Stmt\Nop; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/AnotherPropertyClass.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/AnotherPropertyClass.php index 7c297c8cdc7..d0835e49995 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/AnotherPropertyClass.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/AnotherPropertyClass.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source; use JMS\Serializer\Annotation as Serializer; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Class_/SomeEntityClass.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Class_/SomeEntityClass.php index ac50eba8ced..36782bd635f 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Class_/SomeEntityClass.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Class_/SomeEntityClass.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Class_; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\Class_; use Doctrine\ORM\Mapping as ORM; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Collection.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Collection.php index 060f303e5b9..ea5de0a120a 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Collection.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Collection.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source; final class Collection { diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Doctrine/CaseSensitive.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Doctrine/CaseSensitive.php index 30d5d5e6f0e..885e09fdd31 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Doctrine/CaseSensitive.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Doctrine/CaseSensitive.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine; use Doctrine\ORM\Mapping as ORM; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Doctrine/IndexInTable.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Doctrine/IndexInTable.php index 5316f31422d..7b04c5f9274 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Doctrine/IndexInTable.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Doctrine/IndexInTable.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine; use Doctrine\ORM\Mapping as ORM; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Doctrine/Short.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Doctrine/Short.php index 2b2af361478..99526edf18c 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Doctrine/Short.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/Doctrine/Short.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine; use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping\UniqueConstraint; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/DoctrinePropertyClass.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/DoctrinePropertyClass.php index 60acd8c228f..ce309188b27 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/DoctrinePropertyClass.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/DoctrinePropertyClass.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source; use Doctrine\ORM\Mapping as ORM; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/ManyToPropertyClass.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/ManyToPropertyClass.php index 9447d912d29..3848e513be2 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/ManyToPropertyClass.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/ManyToPropertyClass.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source; use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation as Serializer; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/RoutePropertyClass.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/RoutePropertyClass.php index 1bdc0db8c4c..62432544286 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/RoutePropertyClass.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/RoutePropertyClass.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source; use Symfony\Component\Routing\Annotation\Route; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/SinglePropertyClass.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/SinglePropertyClass.php index 15f51ca937e..d7f42561ac6 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/SinglePropertyClass.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/SinglePropertyClass.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/TableClass.php b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/TableClass.php index db3679206bd..3d6a504aefe 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/TableClass.php +++ b/packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/Source/TableClass.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source; +namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source; use Doctrine\ORM\Mapping as ORM; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/AbstractPhpDocInfoTest.php b/packages-tests/BetterPhpDocParser/PhpDocParser/AbstractPhpDocInfoTest.php index e2f511a6f3d..1c197a626c1 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/AbstractPhpDocInfoTest.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/AbstractPhpDocInfoTest.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser; use Iterator; use PhpParser\Comment\Doc; use PhpParser\Node; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\BetterPhpDocParser\Printer\PhpDocInfoPrinter; -use Rector\BetterPhpDocParser\Tests\PhpDocParser\Helper\TagValueToPhpParserNodeMap; +use Rector\Tests\BetterPhpDocParser\PhpDocParser\Helper\TagValueToPhpParserNodeMap; use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\HttpKernel\RectorKernel; use Rector\Core\PhpParser\Node\BetterNodeFinder; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/Helper/TagValueToPhpParserNodeMap.php b/packages-tests/BetterPhpDocParser/PhpDocParser/Helper/TagValueToPhpParserNodeMap.php index b60824bc0a2..f4704ac50c7 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/Helper/TagValueToPhpParserNodeMap.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/Helper/TagValueToPhpParserNodeMap.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\Helper; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\Helper; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoice.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoice.php index 23e354e2fd2..62cdbdd86e6 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoice.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoice.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceNonQuoteValues.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceNonQuoteValues.php index 90ef2c48024..b146d11b897 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceNonQuoteValues.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceNonQuoteValues.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceQuoteValues.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceQuoteValues.php index 7a3a39818d5..afacf48b4a7 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceQuoteValues.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceQuoteValues.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceWithCeroOnOptions.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceWithCeroOnOptions.php index 430594f542c..aafe9d0783a 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceWithCeroOnOptions.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceWithCeroOnOptions.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceWithManyGroups.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceWithManyGroups.php index c785e72b260..7ee0a6a979d 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceWithManyGroups.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceWithManyGroups.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceWithMessage.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceWithMessage.php index 859698506a1..4e8ea476201 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceWithMessage.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertChoiceWithMessage.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertQuoteChoice.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertQuoteChoice.php index f631c3dc814..0acca2caff2 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertQuoteChoice.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertChoice/AssertQuoteChoice.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\AssertChoice; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertArrayType.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertArrayType.php index b5d6dd3ace0..419f4e2d0d9 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertArrayType.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertArrayType.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\AssertType; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\AssertType; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertStringQuotedType.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertStringQuotedType.php index 6d4fe76fc9d..1957b62531f 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertStringQuotedType.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertStringQuotedType.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\AssertType; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\AssertType; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertStringType.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertStringType.php index 70746d1b564..96752739e58 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertStringType.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertStringType.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\AssertType; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\AssertType; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertType.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertType.php index f4b93f09b6c..8a0b96db3e2 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertType.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertType.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\AssertType; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\AssertType; use Doctrine\Common\Collections\Collection; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertTypeWithMessage.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertTypeWithMessage.php index 54bb7a5733c..c59efee9489 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertTypeWithMessage.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/AssertType/AssertTypeWithMessage.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\AssertType; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\AssertType; use Symfony\Component\Validator\Constraints as Assert; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/Blameable/BlameableTag.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/Blameable/BlameableTag.php index cf4072dfba5..40016027104 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/Blameable/BlameableTag.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/Blameable/BlameableTag.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\Blameable; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\Blameable; use Gedmo\Mapping\Annotation as Gedmo; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/ConstantReference/Book.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/ConstantReference/Book.php index 4138386ddb2..c1dcfda7671 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/ConstantReference/Book.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/ConstantReference/Book.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\ConstantReference; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\ConstantReference; -use Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Source\ApiFilter; +use Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Source\ApiFilter; use Doctrine\ORM\Mapping as ORM; final class Book diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/FromOfficialDocs.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/FromOfficialDocs.php index 6b69ea1f937..c7a2dac738f 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/FromOfficialDocs.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/FromOfficialDocs.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineColumn; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineColumn; use Doctrine\ORM\Mapping as ORM; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/InlinedColumn.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/InlinedColumn.php index 5493b5485f6..d9d4531afa6 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/InlinedColumn.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/InlinedColumn.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineColumn; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineColumn; use Doctrine\ORM\Mapping as ORM; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/PropertyWithName.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/PropertyWithName.php index d172295a1b8..bf9a9ec69ca 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/PropertyWithName.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/PropertyWithName.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineColumn; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineColumn; use Doctrine\ORM\Mapping as ORM; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/QuotesInNestedArray.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/QuotesInNestedArray.php index 479d6d6fc21..797f5a289ef 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/QuotesInNestedArray.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/QuotesInNestedArray.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineColumn; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineColumn; use Doctrine\ORM\Mapping as ORM; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/SomeProperty.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/SomeProperty.php index 5b9428a9c1d..210f0dbcddf 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/SomeProperty.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineColumn/SomeProperty.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineColumn; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineColumn; use Doctrine\ORM\Mapping as ORM; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineCustomIdGenerator/CustomIdGenerator.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineCustomIdGenerator/CustomIdGenerator.php index 8efc681d373..91a6338c1f4 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineCustomIdGenerator/CustomIdGenerator.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineCustomIdGenerator/CustomIdGenerator.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineCustomIdGenerator; +namespace Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineCustomIdGenerator; use Doctrine\ORM\Mapping as ORM; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineEmbedded/AnEntityWithAnEmbedded.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineEmbedded/AnEntityWithAnEmbedded.php index c04decb67a9..e203108f552 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineEmbedded/AnEntityWithAnEmbedded.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineEmbedded/AnEntityWithAnEmbedded.php @@ -1,10 +1,10 @@ PHPStan <=> PHPStan doc <=> string type nodes between all possible formats - * @see \Rector\NodeTypeResolver\Tests\StaticTypeMapper\StaticTypeMapperTest + * @see \Rector\Tests\NodeTypeResolver\StaticTypeMapper\StaticTypeMapperTest */ final class StaticTypeMapper { diff --git a/packages/Testing/Finder/RectorsFinder.php b/packages/Testing/Finder/RectorsFinder.php index 4a239e5fce4..e62cc4d4cd0 100644 --- a/packages/Testing/Finder/RectorsFinder.php +++ b/packages/Testing/Finder/RectorsFinder.php @@ -101,7 +101,6 @@ final class RectorsFinder $robotLoader->setTempDirectory(sys_get_temp_dir() . '/_rector_finder'); $robotLoader->acceptFiles = [$name]; - $robotLoader->excludeDirectory(__DIR__ . '/../../../packages/rector-generator'); $robotLoader->refresh(); $robotLoader->rebuild(); diff --git a/packages/rector-generator/config/config.php b/packages/rector-generator/config/config.php deleted file mode 100644 index a6cdefc32a5..00000000000 --- a/packages/rector-generator/config/config.php +++ /dev/null @@ -1,26 +0,0 @@ -services(); - - $services->defaults() - ->public() - ->autowire() - ->autoconfigure() - ->bind(AddNewServiceToSymfonyPhpConfigRector::class, service(AddNewServiceToSymfonyPhpConfigRector::class)); - - $services->load('Rector\RectorGenerator\\', __DIR__ . '/../src') - ->exclude([__DIR__ . '/../src/Exception', __DIR__ . '/../src/ValueObject', __DIR__ . '/../src/Rector']); - - $services->set(AddNewServiceToSymfonyPhpConfigRector::class) - ->autowire(false); - - $services->set(FileSystemGuard::class); -}; diff --git a/packages/rector-generator/src/Command/GenerateCommand.php b/packages/rector-generator/src/Command/GenerateCommand.php deleted file mode 100644 index b7866efcdd1..00000000000 --- a/packages/rector-generator/src/Command/GenerateCommand.php +++ /dev/null @@ -1,216 +0,0 @@ -templateVariablesFactory = $templateVariablesFactory; - $this->composerPackageAutoloadUpdater = $composerPackageAutoloadUpdater; - $this->templateFinder = $templateFinder; - $this->configFilesystem = $configFilesystem; - $this->overrideGuard = $overrideGuard; - $this->symfonyStyle = $symfonyStyle; - $this->fileGenerator = $fileGenerator; - $this->rectorRecipeProvider = $rectorRecipeProvider; - $this->rectorRecipeInteractiveFactory = $rectorRecipeInteractiveFactory; - } - - protected function configure(): void - { - $this->setAliases(['c', 'create', 'g']); - $this->setDescription('[DEV] Create a new Rector, in a proper location, with new tests'); - $this->addOption( - self::INTERACTIVE_MODE_NAME, - 'i', - InputOption::VALUE_NONE, - 'Turns on Interactive Mode - Rector will be generated based on responses to questions instead of using rector-recipe.php', - ); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $rectorRecipe = $this->getRectorRecipe($input); - - $templateVariables = $this->templateVariablesFactory->createFromRectorRecipe($rectorRecipe); - - // setup psr-4 autoload, if not already in - $this->composerPackageAutoloadUpdater->processComposerAutoload($rectorRecipe); - - $templateFileInfos = $this->templateFinder->find($rectorRecipe); - - $targetDirectory = getcwd(); - - $isUnwantedOverride = $this->overrideGuard->isUnwantedOverride( - $templateFileInfos, - $templateVariables, - $rectorRecipe, - $targetDirectory - ); - if ($isUnwantedOverride) { - $this->symfonyStyle->warning('No files were changed'); - - return ShellCode::SUCCESS; - } - - $generatedFilePaths = $this->fileGenerator->generateFiles( - $templateFileInfos, - $templateVariables, - $rectorRecipe, - $targetDirectory - ); - - $this->configFilesystem->appendRectorServiceToSet($rectorRecipe, $templateVariables); - $testCaseDirectoryPath = $this->resolveTestCaseDirectoryPath($generatedFilePaths); - - $this->printSuccess($rectorRecipe->getName(), $generatedFilePaths, $testCaseDirectoryPath); - - return ShellCode::SUCCESS; - } - - private function getRectorRecipe(InputInterface $input): RectorRecipe - { - $isInteractive = $input->getOption(self::INTERACTIVE_MODE_NAME); - if (! $isInteractive) { - return $this->rectorRecipeProvider->provide(); - } - - return $this->rectorRecipeInteractiveFactory->create(); - } - - /** - * @param string[] $generatedFilePaths - */ - private function resolveTestCaseDirectoryPath(array $generatedFilePaths): string - { - foreach ($generatedFilePaths as $generatedFilePath) { - if (! $this->isGeneratedFilePathTestCase($generatedFilePath)) { - continue; - } - - $generatedFileInfo = new SmartFileInfo($generatedFilePath); - return dirname($generatedFileInfo->getRelativeFilePathFromCwd()); - } - - throw new ShouldNotHappenException(); - } - - /** - * @param string[] $generatedFilePaths - */ - private function printSuccess(string $name, array $generatedFilePaths, string $testCaseFilePath): void - { - $message = sprintf('New files generated for "%s":', $name); - $this->symfonyStyle->title($message); - - sort($generatedFilePaths); - - foreach ($generatedFilePaths as $generatedFilePath) { - $fileInfo = new SmartFileInfo($generatedFilePath); - $relativeFilePath = $fileInfo->getRelativeFilePathFromCwd(); - $this->symfonyStyle->writeln(' * ' . $relativeFilePath); - } - - $message = sprintf('Make tests green again:%svendor/bin/phpunit %s', PHP_EOL . PHP_EOL, $testCaseFilePath); - - $this->symfonyStyle->success($message); - } - - private function isGeneratedFilePathTestCase(string $generatedFilePath): bool - { - if (Strings::endsWith($generatedFilePath, 'Test.php')) { - return true; - } - if (! Strings::endsWith($generatedFilePath, 'Test.php.inc')) { - return false; - } - return StaticPHPUnitEnvironment::isPHPUnitRun(); - } -} diff --git a/packages/rector-generator/src/Command/InitRecipeCommand.php b/packages/rector-generator/src/Command/InitRecipeCommand.php deleted file mode 100644 index 0fdc7dbd533..00000000000 --- a/packages/rector-generator/src/Command/InitRecipeCommand.php +++ /dev/null @@ -1,41 +0,0 @@ -templateInitializer = $templateInitializer; - } - - protected function configure(): void - { - $this->setDescription('[DEV] Initialize "rector-recipe.php" config'); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $this->templateInitializer->initialize( - __DIR__ . '/../../../../templates/rector-recipe.php.dist', - 'rector-recipe.php' - ); - - return ShellCode::SUCCESS; - } -} diff --git a/packages/rector-generator/src/Composer/ComposerPackageAutoloadUpdater.php b/packages/rector-generator/src/Composer/ComposerPackageAutoloadUpdater.php deleted file mode 100644 index d13c26b2649..00000000000 --- a/packages/rector-generator/src/Composer/ComposerPackageAutoloadUpdater.php +++ /dev/null @@ -1,106 +0,0 @@ -jsonFileSystem = $jsonFileSystem; - $this->symfonyStyle = $symfonyStyle; - } - - public function processComposerAutoload(RectorRecipe $rectorRecipe): void - { - $composerJsonFilePath = getcwd() . '/composer.json'; - $composerJson = $this->jsonFileSystem->loadFilePathToJson($composerJsonFilePath); - - $package = $this->resolvePackage($rectorRecipe); - - if ($this->isPackageAlreadyLoaded($composerJson, $package)) { - return; - } - - // ask user - $questionText = sprintf( - 'Should we update "composer.json" autoload with "%s" namespace?', - $package->getSrcNamespace() - ); - - $isConfirmed = $this->symfonyStyle->confirm($questionText); - if (! $isConfirmed) { - return; - } - - $srcAutoload = $rectorRecipe->isRectorRepository() ? ComposerJsonSection::AUTOLOAD : ComposerJsonSection::AUTOLOAD_DEV; - $composerJson[$srcAutoload][self::PSR_4][$package->getSrcNamespace()] = $package->getSrcDirectory(); - - $composerJson[ComposerJsonSection::AUTOLOAD_DEV][self::PSR_4][$package->getTestsNamespace()] = $package->getTestsDirectory(); - - $this->jsonFileSystem->writeJsonToFilePath($composerJson, $composerJsonFilePath); - - $this->rebuildAutoload(); - } - - private function resolvePackage(RectorRecipe $rectorRecipe): Package - { - if (! $rectorRecipe->isRectorRepository()) { - return new Package( - 'Utils\\Rector\\', - 'Utils\\Rector\\Tests\\', - 'utils/rector/src', - 'utils/rector/tests' - ); - } - - return new Package( - 'Rector\\' . $rectorRecipe->getPackage() . '\\', - 'Rector\\' . $rectorRecipe->getPackage() . '\\Tests\\', - 'rules/' . $rectorRecipe->getPackageDirectory() . '/src', - 'rules/' . $rectorRecipe->getPackageDirectory() . '/tests' - ); - } - - /** - * @param mixed[] $composerJson - */ - private function isPackageAlreadyLoaded(array $composerJson, Package $package): bool - { - foreach ([ComposerJsonSection::AUTOLOAD, ComposerJsonSection::AUTOLOAD_DEV] as $autoloadSection) { - if (isset($composerJson[$autoloadSection][self::PSR_4][$package->getSrcNamespace()])) { - return true; - } - } - - return false; - } - - private function rebuildAutoload(): void - { - // note: do not use shell_exec, this is only effective solution for better DX - shell_exec('composer dump'); - } -} diff --git a/packages/rector-generator/src/Config/ConfigFilesystem.php b/packages/rector-generator/src/Config/ConfigFilesystem.php deleted file mode 100644 index e0738067080..00000000000 --- a/packages/rector-generator/src/Config/ConfigFilesystem.php +++ /dev/null @@ -1,111 +0,0 @@ -templateFactory = $templateFactory; - $this->parser = $parser; - $this->addNewServiceToSymfonyPhpConfigRector = $addNewServiceToSymfonyPhpConfigRector; - $this->betterStandardPrinter = $betterStandardPrinter; - $this->smartFileSystem = $smartFileSystem; - } - - /** - * @param string[] $templateVariables - */ - public function appendRectorServiceToSet(RectorRecipe $rectorRecipe, array $templateVariables): void - { - if ($rectorRecipe->getSet() === null) { - return; - } - - $setFilePath = $rectorRecipe->getSet(); - $setFileInfo = new SmartFileInfo($setFilePath); - $setFileContents = $setFileInfo->getContents(); - - // already added? - $rectorFqnName = $this->templateFactory->create(self::RECTOR_FQN_NAME_PATTERN, $templateVariables); - if (Strings::contains($setFileContents, $rectorFqnName)) { - return; - } - - // 1. parse the file - $setConfigNodes = $this->parser->parseFileInfo($setFileInfo); - - // 2. add the set() call - $this->decorateNamesToFullyQualified($setConfigNodes); - - $nodeTraverser = new NodeTraverser(); - - $this->addNewServiceToSymfonyPhpConfigRector->setRectorClass($rectorFqnName); - $nodeTraverser->addVisitor($this->addNewServiceToSymfonyPhpConfigRector); - $setConfigNodes = $nodeTraverser->traverse($setConfigNodes); - - // 3. print the content back to file - $changedSetConfigContent = $this->betterStandardPrinter->prettyPrintFile($setConfigNodes); - $this->smartFileSystem->dumpFile($setFileInfo->getRealPath(), $changedSetConfigContent); - } - - /** - * @param Node[] $nodes - */ - private function decorateNamesToFullyQualified(array $nodes): void - { - // decorate nodes with names first - $nameResolverNodeTraverser = new NodeTraverser(); - $nameResolverNodeTraverser->addVisitor(new NameResolver()); - $nameResolverNodeTraverser->traverse($nodes); - } -} diff --git a/packages/rector-generator/src/Contract/InternalRectorInterface.php b/packages/rector-generator/src/Contract/InternalRectorInterface.php deleted file mode 100644 index 903b0f2c1dd..00000000000 --- a/packages/rector-generator/src/Contract/InternalRectorInterface.php +++ /dev/null @@ -1,9 +0,0 @@ -templateFactory = $templateFactory; - } - - /** - * @param array $templateVariables - */ - public function resolveDestination( - SmartFileInfo $smartFileInfo, - array $templateVariables, - RectorRecipe $rectorRecipe, - string $targetDirectory - ): string { - $destination = $smartFileInfo->getRelativeFilePathFromDirectory(TemplateFinder::TEMPLATES_DIRECTORY); - - // normalize core package - if (! $rectorRecipe->isRectorRepository()) { - // special keyword for 3rd party Rectors, not for core Github contribution - $destination = Strings::replace($destination, self::PACKAGE_RULES_PATH_REGEX, 'utils/rector'); - } - - // remove _Configured|_Extra prefix - $destination = $this->templateFactory->create($destination, $templateVariables); - - $destination = Strings::replace($destination, self::CONFIGURED_OR_EXTRA_REGEX, ''); - - // remove ".inc" protection from PHPUnit if not a test case - if ($this->isNonFixtureFileWithIncSuffix($destination)) { - $destination = Strings::before($destination, '.inc'); - } - - // special hack for tests, to PHPUnit doesn't load the generated file as test case - /** @var string $destination */ - if (Strings::endsWith($destination, 'Test.php') && StaticPHPUnitEnvironment::isPHPUnitRun()) { - $destination .= '.inc'; - } - - return $targetDirectory . DIRECTORY_SEPARATOR . $destination; - } - - private function isNonFixtureFileWithIncSuffix(string $filePath): bool - { - if (Strings::match($filePath, self::FIXTURE_SHORT_REGEX)) { - return false; - } - - return Strings::endsWith($filePath, '.inc'); - } -} diff --git a/packages/rector-generator/src/Finder/TemplateFinder.php b/packages/rector-generator/src/Finder/TemplateFinder.php deleted file mode 100644 index 453e8271ae3..00000000000 --- a/packages/rector-generator/src/Finder/TemplateFinder.php +++ /dev/null @@ -1,100 +0,0 @@ -finderSanitizer = $finderSanitizer; - $this->fileSystemGuard = $fileSystemGuard; - } - - /** - * @return SmartFileInfo[] - */ - public function find(RectorRecipe $rectorRecipe): array - { - $filePaths = []; - - if ($rectorRecipe->getExtraFileContent()) { - $filePaths[] = __DIR__ . '/../../templates/rules/__package__/tests/Rector/__Category__/__Name__/Source/extra_file.php.inc'; - } - - $filePaths = $this->addRuleAndTestCase($rectorRecipe, $filePaths); - $filePaths[] = $this->resolveFixtureFilePath(); - - $this->ensureFilePathsExists($filePaths); - - return $this->finderSanitizer->sanitize($filePaths); - } - - /** - * @param string[] $filePaths - * @return string[] - * - * @note the ".inc" suffix is needed, so PHPUnit doens't load it as a test case; - * unfortunately we haven't found a way to preven it - */ - private function addRuleAndTestCase(RectorRecipe $rectorRecipe, array $filePaths): array - { - if ($rectorRecipe->getConfiguration() !== []) { - $filePaths[] = __DIR__ . '/../../templates/rules/__package__/src/Rector/__Category__/__Configured__Name__.php'; - - if ($rectorRecipe->getExtraFileContent()) { - $filePaths[] = __DIR__ . '/../../templates/rules/__package__/tests/Rector/__Category__/__Name__/__Configured__Extra__Name__Test.php.inc'; - } else { - $filePaths[] = __DIR__ . '/../../templates/rules/__package__/tests/Rector/__Category__/__Name__/__Configured__Name__Test.php.inc'; - } - - return $filePaths; - } - - if ($rectorRecipe->getExtraFileContent()) { - $filePaths[] = __DIR__ . '/../../templates/rules/__package__/tests/Rector/__Category__/__Name__/__Extra__Name__Test.php.inc'; - } else { - $filePaths[] = __DIR__ . '/../../templates/rules/__package__/tests/Rector/__Category__/__Name__/__Name__Test.php.inc'; - } - - $filePaths[] = __DIR__ . '/../../templates/rules/__package__/src/Rector/__Category__/__Name__.php'; - - return $filePaths; - } - - private function resolveFixtureFilePath(): string - { - return __DIR__ . '/../../templates/rules/__package__/tests/Rector/__Category__/__Name__/Fixture/some_class.php.inc'; - } - - /** - * @param string[] $filePaths - */ - private function ensureFilePathsExists(array $filePaths): void - { - foreach ($filePaths as $filePath) { - $this->fileSystemGuard->ensureFileExists($filePath, __METHOD__); - } - } -} diff --git a/packages/rector-generator/src/Generator/FileGenerator.php b/packages/rector-generator/src/Generator/FileGenerator.php deleted file mode 100644 index 4ecd1194498..00000000000 --- a/packages/rector-generator/src/Generator/FileGenerator.php +++ /dev/null @@ -1,99 +0,0 @@ -templateFileSystem = $templateFileSystem; - $this->templateFactory = $templateFactory; - $this->smartFileSystem = $smartFileSystem; - } - - /** - * @param SmartFileInfo[] $templateFileInfos - * @param string[] $templateVariables - * @return string[] - */ - public function generateFiles( - array $templateFileInfos, - array $templateVariables, - RectorRecipe $rectorRecipe, - string $destinationDirectory - ): array { - $generatedFilePaths = []; - - foreach ($templateFileInfos as $templateFileInfo) { - $generatedFilePaths[] = $this->generateFileInfoWithTemplateVariables( - $templateFileInfo, - $templateVariables, - $rectorRecipe, - $destinationDirectory - ); - } - - return $generatedFilePaths; - } - - /** - * @param array $templateVariables - */ - private function generateFileInfoWithTemplateVariables( - SmartFileInfo $smartFileInfo, - array $templateVariables, - RectorRecipe $rectorRecipe, - string $targetDirectory - ): string { - $targetFilePath = $this->templateFileSystem->resolveDestination( - $smartFileInfo, - $templateVariables, - $rectorRecipe, - $targetDirectory - ); - - $content = $this->templateFactory->create($smartFileInfo->getContents(), $templateVariables); - - // replace "Rector\Utils\" with "Utils\Rector\" for 3rd party packages - if (! $rectorRecipe->isRectorRepository()) { - $content = Strings::replace($content, self::RECTOR_UTILS_REGEX, 'Utils\Rector'); - } - - $this->smartFileSystem->dumpFile($targetFilePath, $content); - - return $targetFilePath; - } -} diff --git a/packages/rector-generator/src/Generator/RectorRecipeGenerator.php b/packages/rector-generator/src/Generator/RectorRecipeGenerator.php deleted file mode 100644 index 5c3a8f315a9..00000000000 --- a/packages/rector-generator/src/Generator/RectorRecipeGenerator.php +++ /dev/null @@ -1,51 +0,0 @@ -templateFinder = $templateFinder; - $this->templateVariablesFactory = $templateVariablesFactory; - $this->fileGenerator = $fileGenerator; - } - - public function generate(RectorRecipe $rectorRecipe, string $destinationDirectory): void - { - // generate and compare - $templateFileInfos = $this->templateFinder->find($rectorRecipe); - $templateVariables = $this->templateVariablesFactory->createFromRectorRecipe($rectorRecipe); - - $this->fileGenerator->generateFiles( - $templateFileInfos, - $templateVariables, - $rectorRecipe, - $destinationDirectory - ); - } -} diff --git a/packages/rector-generator/src/Guard/OverrideGuard.php b/packages/rector-generator/src/Guard/OverrideGuard.php deleted file mode 100644 index fe332f0cea1..00000000000 --- a/packages/rector-generator/src/Guard/OverrideGuard.php +++ /dev/null @@ -1,76 +0,0 @@ -templateFileSystem = $templateFileSystem; - $this->symfonyStyle = $symfonyStyle; - } - - /** - * @param array $templateVariables - * @param SmartFileInfo[] $templateFileInfos - */ - public function isUnwantedOverride( - array $templateFileInfos, - array $templateVariables, - RectorRecipe $rectorRecipe, - string $targetDirectory - ): bool { - $message = sprintf('Files for "%s" rule already exist. Should we override them?', $rectorRecipe->getName()); - - foreach ($templateFileInfos as $templateFileInfo) { - if (! $this->doesFileInfoAlreadyExist( - $templateVariables, - $rectorRecipe, - $templateFileInfo, - $targetDirectory - )) { - continue; - } - - return ! $this->symfonyStyle->confirm($message); - } - - return false; - } - - /** - * @param array $templateVariables - */ - private function doesFileInfoAlreadyExist( - array $templateVariables, - RectorRecipe $rectorRecipe, - SmartFileInfo $templateFileInfo, - string $targetDirectory - ): bool { - $destination = $this->templateFileSystem->resolveDestination( - $templateFileInfo, - $templateVariables, - $rectorRecipe, - $targetDirectory - ); - - return file_exists($destination); - } -} diff --git a/packages/rector-generator/src/NodeFactory/ConfigurationNodeFactory.php b/packages/rector-generator/src/NodeFactory/ConfigurationNodeFactory.php deleted file mode 100644 index 42772a5cb00..00000000000 --- a/packages/rector-generator/src/NodeFactory/ConfigurationNodeFactory.php +++ /dev/null @@ -1,155 +0,0 @@ -nodeFactory = $nodeFactory; - $this->phpDocInfoFactory = $phpDocInfoFactory; - $this->parameterProvider = $parameterProvider; - } - - /** - * @param array $ruleConfiguration - * @return Property[] - */ - public function createProperties(array $ruleConfiguration): array - { - $this->lowerPhpVersion(); - - $properties = []; - foreach (array_keys($ruleConfiguration) as $constantName) { - $propertyName = StaticRectorStrings::uppercaseUnderscoreToCamelCase($constantName); - $type = new ArrayType(new MixedType(), new MixedType()); - - $property = $this->nodeFactory->createPrivatePropertyFromNameAndType($propertyName, $type); - $property->props[0]->default = new Array_([]); - $properties[] = $property; - } - - return $properties; - } - - /** - * @param array $ruleConfiguration - * @return ClassConst[] - */ - public function createConfigurationConstants(array $ruleConfiguration): array - { - $classConsts = []; - - foreach (array_keys($ruleConfiguration) as $constantName) { - $constantName = strtoupper($constantName); - $constantValue = strtolower($constantName); - $classConst = $this->nodeFactory->createPublicClassConst($constantName, $constantValue); - $classConsts[] = $classConst; - } - - return $classConsts; - } - - /** - * @param array $ruleConfiguration - */ - public function createConfigureClassMethod(array $ruleConfiguration): ClassMethod - { - $this->lowerPhpVersion(); - - $classMethod = $this->nodeFactory->createPublicMethod('configure'); - $classMethod->returnType = new Identifier('void'); - - $configurationVariable = new Variable('configuration'); - $configurationParam = new Param($configurationVariable); - $configurationParam->type = new Identifier('array'); - $classMethod->params[] = $configurationParam; - - $assigns = []; - foreach (array_keys($ruleConfiguration) as $constantName) { - $coalesce = $this->createConstantInConfigurationCoalesce($constantName, $configurationVariable); - - $propertyName = StaticRectorStrings::uppercaseUnderscoreToCamelCase($constantName); - $assign = $this->nodeFactory->createPropertyAssignmentWithExpr($propertyName, $coalesce); - $assigns[] = new Expression($assign); - } - - $classMethod->stmts = $assigns; - - $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod); - - $identifierTypeNode = new IdentifierTypeNode('mixed[]'); - $paramTagValueNode = new ParamTagValueNode($identifierTypeNode, false, '$configuration', ''); - $phpDocInfo->addTagValueNode($paramTagValueNode); - - return $classMethod; - } - - /** - * So types are PHP 7.2 compatible - */ - private function lowerPhpVersion(): void - { - $this->parameterProvider->changeParameter( - Option::PHP_VERSION_FEATURES, - PhpVersionFeature::TYPED_PROPERTIES - 1 - ); - } - - private function createConstantInConfigurationCoalesce( - string $constantName, - Variable $configurationVariable - ): Coalesce { - $constantName = strtoupper($constantName); - - $classConstFetch = new ClassConstFetch(new Name('self'), $constantName); - $arrayDimFetch = new ArrayDimFetch($configurationVariable, $classConstFetch); - - $emptyArray = new Array_([]); - - return new Coalesce($arrayDimFetch, $emptyArray); - } -} diff --git a/packages/rector-generator/src/Provider/NodeTypesProvider.php b/packages/rector-generator/src/Provider/NodeTypesProvider.php deleted file mode 100644 index 82d8590816c..00000000000 --- a/packages/rector-generator/src/Provider/NodeTypesProvider.php +++ /dev/null @@ -1,56 +0,0 @@ - - */ - public function provide(): array - { - $finder = new Finder(); - $finder = $finder->files() - ->in(self::PHP_PARSER_NODES_PATH); - - $fileInfos = iterator_to_array($finder->getIterator()); - - $nodeTypes = []; - foreach ($fileInfos as $fileInfo) { - /** @var SplFileInfo $fileInfo */ - $name = str_replace(['.php', '/'], ['', '\\'], $fileInfo->getRelativePathname()); - - $reflectionClass = new ReflectionClass(self::PHP_PARSER_NAMESPACE . $name); - if ($reflectionClass->isAbstract()) { - continue; - } - - if ($reflectionClass->isInterface()) { - continue; - } - - $nodeTypes[$name] = $name; - } - - return $nodeTypes; - } -} diff --git a/packages/rector-generator/src/Provider/PackageNamesProvider.php b/packages/rector-generator/src/Provider/PackageNamesProvider.php deleted file mode 100644 index 61be3b867b6..00000000000 --- a/packages/rector-generator/src/Provider/PackageNamesProvider.php +++ /dev/null @@ -1,38 +0,0 @@ -directories() - ->depth(0) - ->in(__DIR__ . '/../../../../rules') - ->sortByName(); - - $fileInfos = iterator_to_array($finder->getIterator()); - - $packageNames = []; - - foreach ($fileInfos as $fileInfo) { - /** @var SplFileInfo $fileInfo */ - $packageNames[] = StaticRectorStrings::dashesToCamelCase($fileInfo->getFilename()); - } - - return $packageNames; - } -} diff --git a/packages/rector-generator/src/Provider/RectorRecipeProvider.php b/packages/rector-generator/src/Provider/RectorRecipeProvider.php deleted file mode 100644 index a8c4fb2f704..00000000000 --- a/packages/rector-generator/src/Provider/RectorRecipeProvider.php +++ /dev/null @@ -1,38 +0,0 @@ -rectorRecipe = $rectorRecipe; - } - - public function provide(): RectorRecipe - { - if (! $this->rectorRecipe instanceof RectorRecipe) { - throw new ConfigurationException(self::MESSAGE); - } - - return $this->rectorRecipe; - } -} diff --git a/packages/rector-generator/src/Provider/SetsListProvider.php b/packages/rector-generator/src/Provider/SetsListProvider.php deleted file mode 100644 index a0a95902541..00000000000 --- a/packages/rector-generator/src/Provider/SetsListProvider.php +++ /dev/null @@ -1,22 +0,0 @@ -getConstants(); - - return array_keys($constants); - } -} diff --git a/packages/rector-generator/src/Rector/Closure/AddNewServiceToSymfonyPhpConfigRector.php b/packages/rector-generator/src/Rector/Closure/AddNewServiceToSymfonyPhpConfigRector.php deleted file mode 100644 index fdbd26a3a64..00000000000 --- a/packages/rector-generator/src/Rector/Closure/AddNewServiceToSymfonyPhpConfigRector.php +++ /dev/null @@ -1,103 +0,0 @@ -symfonyPhpConfigClosureAnalyzer = $symfonyPhpConfigClosureAnalyzer; - } - - public function setRectorClass(string $rectorClass): void - { - $this->rectorClass = $rectorClass; - } - - /** - * @return array> - */ - public function getNodeTypes(): array - { - return [Closure::class]; - } - - /** - * @param Closure $node - */ - public function refactor(Node $node): ?Node - { - if ($this->rectorClass === null) { - return null; - } - - if (! $this->symfonyPhpConfigClosureAnalyzer->isPhpConfigClosure($node)) { - return null; - } - - $methodCall = $this->createServicesSetMethodCall($this->rectorClass); - $node->stmts[] = new Expression($methodCall); - - return $node; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition('Adds a new $services->set(...) call to PHP Config', [ - new CodeSample( - <<<'CODE_SAMPLE' -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; - -return static function (ContainerConfigurator $containerConfigurator): void { - $services = $containerConfigurator->services(); -}; -CODE_SAMPLE - , -<<<'CODE_SAMPLE' -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; - -return static function (ContainerConfigurator $containerConfigurator): void { - $services = $containerConfigurator->services(); - $services->set(AddNewServiceToSymfonyPhpConfigRector::class); -}; -CODE_SAMPLE - ), - ]); - } - - private function createServicesSetMethodCall(string $className): MethodCall - { - $servicesVariable = new Variable('services'); - $referenceClassConstFetch = new ClassConstFetch(new FullyQualified($className), new Identifier('class')); - $args = [new Arg($referenceClassConstFetch)]; - - return new MethodCall($servicesVariable, 'set', $args); - } -} diff --git a/packages/rector-generator/src/TemplateFactory.php b/packages/rector-generator/src/TemplateFactory.php deleted file mode 100644 index d7f0b5b8e58..00000000000 --- a/packages/rector-generator/src/TemplateFactory.php +++ /dev/null @@ -1,19 +0,0 @@ -symfonyStyle = $symfonyStyle; - $this->smartFileSystem = $smartFileSystem; - $this->fileSystemGuard = $fileSystemGuard; - } - - public function initialize(string $templateFilePath, string $rootFileName): void - { - $this->fileSystemGuard->ensureFileExists($templateFilePath, __METHOD__); - - $targetFilePath = getcwd() . '/' . $rootFileName; - - $doesFileExist = $this->smartFileSystem->exists($targetFilePath); - if ($doesFileExist) { - $message = sprintf('Config file "%s" already exists', $rootFileName); - $this->symfonyStyle->warning($message); - } else { - $this->smartFileSystem->copy($templateFilePath, $targetFilePath); - $message = sprintf('"%s" config file was added', $rootFileName); - $this->symfonyStyle->success($message); - } - } -} diff --git a/packages/rector-generator/src/TemplateVariablesFactory.php b/packages/rector-generator/src/TemplateVariablesFactory.php deleted file mode 100644 index dc069f34408..00000000000 --- a/packages/rector-generator/src/TemplateVariablesFactory.php +++ /dev/null @@ -1,222 +0,0 @@ -betterStandardPrinter = $betterStandardPrinter; - $this->nodeFactory = $nodeFactory; - $this->configurationNodeFactory = $configurationNodeFactory; - $this->templateFactory = $templateFactory; - } - - /** - * @return array - */ - public function createFromRectorRecipe(RectorRecipe $rectorRecipe): array - { - $data = [ - self::VARIABLE_PACKAGE => $rectorRecipe->getPackage(), - self::VARIABLE_PACKAGE_LOWERCASE => $rectorRecipe->getPackageDirectory(), - '__Category__' => $rectorRecipe->getCategory(), - '__Description__' => $rectorRecipe->getDescription(), - '__Name__' => $rectorRecipe->getName(), - '__CodeBefore__' => trim($rectorRecipe->getCodeBefore()) . PHP_EOL, - '__CodeBeforeExample__' => $this->createCodeForDefinition($rectorRecipe->getCodeBefore()), - '__CodeAfter__' => trim($rectorRecipe->getCodeAfter()) . PHP_EOL, - '__CodeAfterExample__' => $this->createCodeForDefinition($rectorRecipe->getCodeAfter()), - '__Resources__' => $this->createSourceDocBlock($rectorRecipe->getResources()), - ]; - - $rectorClass = $this->templateFactory->create(ConfigFilesystem::RECTOR_FQN_NAME_PATTERN, $data); - - if ($rectorRecipe->getConfiguration() !== []) { - $data['__TestRuleConfiguration__'] = $this->createRuleConfiguration( - $rectorClass, - $rectorRecipe->getConfiguration() - ); - $data['__RuleConfiguration__'] = $this->createRuleConfiguration( - self::SELF, - $rectorRecipe->getConfiguration() - ); - - $data['__ConfigurationProperties__'] = $this->createConfigurationProperty( - $rectorRecipe->getConfiguration() - ); - - $data['__ConfigurationConstants__'] = $this->createConfigurationConstants( - $rectorRecipe->getConfiguration() - ); - - $data['__ConfigureClassMethod__'] = $this->createConfigureClassMethod( - $rectorRecipe->getConfiguration() - ); - } - - if ($rectorRecipe->getExtraFileContent() !== null && $rectorRecipe->getExtraFileName() !== null) { - $data['__ExtraFileName__'] = $rectorRecipe->getExtraFileName(); - $data['__ExtraFileContent__'] = trim($rectorRecipe->getExtraFileContent()) . PHP_EOL; - $data['__ExtraFileContentExample__'] = $this->createCodeForDefinition( - $rectorRecipe->getExtraFileContent() - ); - } - - $data['__NodeTypesPhp__'] = $this->createNodeTypePhp($rectorRecipe); - $data['__NodeTypesDoc__'] = '\\' . implode('|\\', $rectorRecipe->getNodeTypes()); - - return $data; - } - - private function createCodeForDefinition(string $code): string - { - if (Strings::contains($code, PHP_EOL)) { - // multi lines - return sprintf("<<<'CODE_SAMPLE'%s%s%sCODE_SAMPLE%s", PHP_EOL, $code, PHP_EOL, PHP_EOL); - } - - // single line - return "'" . str_replace("'", '"', $code) . "'"; - } - - /** - * @param string[] $source - */ - private function createSourceDocBlock(array $source): string - { - if ($source === []) { - return ''; - } - - $sourceAsString = ''; - foreach ($source as $singleSource) { - $sourceAsString .= ' * @see ' . $singleSource . PHP_EOL; - } - - $sourceAsString .= ' *'; - - return rtrim($sourceAsString); - } - - /** - * @param mixed[] $configuration - */ - private function createRuleConfiguration(string $rectorClass, array $configuration): string - { - $arrayItems = []; - foreach ($configuration as $constantName => $variableConfiguration) { - $constantName = strtoupper($constantName); - - if ($rectorClass === self::SELF) { - $class = new Name(self::SELF); - } else { - $class = new FullyQualified($rectorClass); - } - $classConstFetch = new ClassConstFetch($class, $constantName); - - if (is_array($variableConfiguration)) { - $variableConfiguration = $this->nodeFactory->createArray($variableConfiguration); - } else { - $variableConfiguration = BuilderHelpers::normalizeValue($variableConfiguration); - } - - $arrayItems[] = new ArrayItem($variableConfiguration, $classConstFetch); - } - - $array = new Array_($arrayItems); - return $this->betterStandardPrinter->print($array); - } - - /** - * @param array $ruleConfiguration - */ - private function createConfigurationProperty(array $ruleConfiguration): string - { - $properties = $this->configurationNodeFactory->createProperties($ruleConfiguration); - return $this->betterStandardPrinter->print($properties); - } - - /** - * @param array $ruleConfiguration - */ - private function createConfigurationConstants(array $ruleConfiguration): string - { - $configurationConstants = $this->configurationNodeFactory->createConfigurationConstants($ruleConfiguration); - return $this->betterStandardPrinter->print($configurationConstants); - } - - /** - * @param array $ruleConfiguration - */ - private function createConfigureClassMethod(array $ruleConfiguration): string - { - $classMethod = $this->configurationNodeFactory->createConfigureClassMethod($ruleConfiguration); - return $this->betterStandardPrinter->print($classMethod); - } - - private function createNodeTypePhp(RectorRecipe $rectorRecipe): string - { - $referencingClassConsts = []; - foreach ($rectorRecipe->getNodeTypes() as $nodeType) { - $referencingClassConsts[] = $this->nodeFactory->createClassConstReference($nodeType); - } - - $array = $this->nodeFactory->createArray($referencingClassConsts); - return $this->betterStandardPrinter->print($array); - } -} diff --git a/packages/rector-generator/src/Testing/ManualInteractiveInputProvider.php b/packages/rector-generator/src/Testing/ManualInteractiveInputProvider.php deleted file mode 100644 index a639acafb16..00000000000 --- a/packages/rector-generator/src/Testing/ManualInteractiveInputProvider.php +++ /dev/null @@ -1,67 +0,0 @@ -symfonyStyle = $symfonyStyle; - $this->privatesCaller = $privatesCaller; - $this->privatesAccessor = $privatesAccessor; - } - - /** - * Use an in-memory input stream even if no inputs are set so that QuestionHelper::ask() does not rely on the blocking STDIN - * @param string[]|null[] $manualInteractiveInput - */ - public function setInput(array $manualInteractiveInput): void - { - $arrayInput = new ArrayInput([]); - $inputStream = $this->createInputStream($manualInteractiveInput); - $arrayInput->setStream($inputStream); - - // use stream input as input for SymfonyStyle - $this->privatesAccessor->setPrivateProperty($this->symfonyStyle, 'input', $arrayInput); - } - - /** - * @param string[]|null[] $manualInteractiveInput - * @return resource - */ - private function createInputStream(array $manualInteractiveInput) - { - // mimics CommandTester, only with DI approach - return $this->privatesCaller->callPrivateMethod( - CommandTester::class, - 'createStream', - [$manualInteractiveInput] - ); - } -} diff --git a/packages/rector-generator/src/ValueObject/Package.php b/packages/rector-generator/src/ValueObject/Package.php deleted file mode 100644 index aec573855ed..00000000000 --- a/packages/rector-generator/src/ValueObject/Package.php +++ /dev/null @@ -1,65 +0,0 @@ -srcNamespace = $srcNamespace; - $this->testsNamespace = $testsNamespace; - $this->srcDirectory = $srcDirectory; - $this->testsDirectory = $testsDirectory; - } - - public function getSrcNamespace(): string - { - return $this->srcNamespace; - } - - public function getTestsNamespace(): string - { - return $this->testsNamespace; - } - - public function getSrcDirectory(): string - { - return $this->srcDirectory; - } - - public function getTestsDirectory(): string - { - return $this->testsDirectory; - } -} diff --git a/packages/rector-generator/src/ValueObject/RectorRecipe.php b/packages/rector-generator/src/ValueObject/RectorRecipe.php deleted file mode 100644 index bf09f11174d..00000000000 --- a/packages/rector-generator/src/ValueObject/RectorRecipe.php +++ /dev/null @@ -1,325 +0,0 @@ -isRectorRepository = file_exists(__DIR__ . '/../../../../vendor'); - - $this->setPackage($package); - $this->setName($name); - $this->setNodeTypes($nodeTypes); - - $this->description = $description; - - if ($codeBefore === $codeAfter) { - throw new ConfigurationException('Code before and after are identical. They have to be different'); - } - - $this->setCodeBefore($codeBefore); - $this->setCodeAfter($codeAfter); - - $this->resolveCategory($nodeTypes); - } - - public function getPackage(): string - { - return $this->package; - } - - public function getName(): string - { - return $this->name; - } - - /** - * @return class-string[] - */ - public function getNodeTypes(): array - { - return $this->nodeTypes; - } - - public function getDescription(): string - { - return $this->description; - } - - public function getCodeBefore(): string - { - return $this->codeBefore; - } - - public function getCodeAfter(): string - { - return $this->codeAfter; - } - - /** - * @return string[] - */ - public function getResources(): array - { - return $this->resources; - } - - public function setSet(string $set): void - { - $this->set = $set; - } - - public function getSet(): ?string - { - return $this->set; - } - - /** - * @return array - */ - public function getConfiguration(): array - { - return $this->configuration; - } - - public function getExtraFileName(): ?string - { - return $this->extraFileName; - } - - public function getExtraFileContent(): ?string - { - return $this->extraFileContent; - } - - public function isRectorRepository(): bool - { - return $this->isRectorRepository; - } - - public function getCategory(): string - { - return $this->category; - } - - public function getPackageDirectory(): string - { - if (! $this->isRectorRepository) { - return 'rector'; - } - - // special cases - if ($this->getPackage() === 'PHPUnit') { - return 'phpunit'; - } - - return StaticRectorStrings::camelCaseToDashes($this->getPackage()); - } - - /** - * @api - */ - public function addExtraFile(string $extraFileName, string $extraFileContent): void - { - $this->extraFileName = $extraFileName; - $this->extraFileContent = $this->normalizeCode($extraFileContent); - } - - /** - * @api - * @param mixed[] $configuration - */ - public function setConfiguration(array $configuration): void - { - $this->configuration = $configuration; - } - - /** - * @api - * @param string[] $resources - */ - public function setResources(array $resources): void - { - $this->resources = array_filter($resources); - } - - /** - * For testing purposes - * @api - */ - public function setIsRectorRepository(bool $isRectorRepository): void - { - $this->isRectorRepository = $isRectorRepository; - } - - /** - * For tests - * @api - */ - public function setPackage(string $package): void - { - if (is_file($package)) { - $message = sprintf( - 'The "%s()" method only accepts package name, file path "%s" given', - __METHOD__, - $package - ); - throw new ShouldNotHappenException($message); - } - - $this->package = $package; - } - - private function setName(string $name): void - { - if (! Strings::endsWith($name, 'Rector')) { - $message = sprintf('Rector name "%s" must end with "Rector"', $name); - throw new ConfigurationException($message); - } - - $this->name = $name; - } - - /** - * @param class-string[] $nodeTypes - */ - private function setNodeTypes(array $nodeTypes): void - { - foreach ($nodeTypes as $nodeType) { - if (is_a($nodeType, Node::class, true)) { - continue; - } - - $message = sprintf( - 'Node type "%s" does not exist, implement "%s" interface or is not imported in "rector-recipe.php"', - $nodeType, - Node::class - ); - throw new ShouldNotHappenException($message); - } - - if (count($nodeTypes) < 1) { - $message = sprintf('"$nodeTypes" argument requires at least one item, e.g. "%s"', FuncCall::class); - throw new ConfigurationException($message); - } - - $this->nodeTypes = $nodeTypes; - } - - private function setCodeBefore(string $codeBefore): void - { - $this->codeBefore = $this->normalizeCode($codeBefore); - } - - private function setCodeAfter(string $codeAfter): void - { - $this->codeAfter = $this->normalizeCode($codeAfter); - } - - /** - * @param string[] $nodeTypes - */ - private function resolveCategory(array $nodeTypes): void - { - $this->category = (string) Strings::after($nodeTypes[0], '\\', -1); - } - - private function normalizeCode(string $code): string - { - if (Strings::startsWith($code, 'something(); - } -} - -CODE_SAMPLE; - - /** - * @var string - */ - public const EXAMPLE_CODE_AFTER = <<<'CODE_SAMPLE' -somethingElse(); - } -} - -CODE_SAMPLE; - - /** - * @var SymfonyStyle - */ - private $symfonyStyle; - - /** - * @var PackageNamesProvider - */ - private $packageNamesProvider; - - /** - * @var NodeTypesProvider - */ - private $nodeTypesProvider; - - /** - * @var SetsListProvider - */ - private $setsListProvider; - - public function __construct( - PackageNamesProvider $packageNamesProvider, - NodeTypesProvider $nodeTypesProvider, - SetsListProvider $setsListProvider, - SymfonyStyle $symfonyStyle - ) { - $this->packageNamesProvider = $packageNamesProvider; - $this->nodeTypesProvider = $nodeTypesProvider; - $this->setsListProvider = $setsListProvider; - $this->symfonyStyle = $symfonyStyle; - } - - public function create(): RectorRecipe - { - $rectorRecipe = new RectorRecipe( - $this->askForPackageName(), - $this->askForRectorName(), - $this->askForNodeTypes(), - $this->askForRectorDescription(), - self::EXAMPLE_CODE_BEFORE, - self::EXAMPLE_CODE_AFTER, - ); - - $rectorRecipe->setResources($this->askForResources()); - - $set = $this->askForSet(); - if ($set !== null) { - $rectorRecipe->setSet($set); - } - - return $rectorRecipe; - } - - private function askForPackageName(): string - { - $question = new Question(sprintf( - 'Package name for which Rector should be created (e.g. %s)', - 'Naming' - )); - $question->setAutocompleterValues($this->packageNamesProvider->provide()); - - $packageName = $this->symfonyStyle->askQuestion($question); - - return $packageName ?? $this->askForPackageName(); - } - - private function askForRectorName(): string - { - $question = sprintf( - 'Class name of the Rector to create (e.g. %s)', - 'RenameMethodCallRector', - ); - $rectorName = $this->symfonyStyle->ask($question); - - return $rectorName ?? $this->askForRectorName(); - } - - /** - * @return array - */ - private function askForNodeTypes(): array - { - $choiceQuestion = new ChoiceQuestion(sprintf( - 'For what Nodes should the Rector be run (e.g. %s)', - 'Expr/MethodCall', - ), $this->nodeTypesProvider->provide()); - - $choiceQuestion->setMultiselect(true); - - $nodeTypes = $this->symfonyStyle->askQuestion($choiceQuestion); - - $classes = []; - foreach ($nodeTypes as $nodeType) { - /** @var class-string $class */ - $class = 'PhpParser\Node\\' . $nodeType; - $classes[] = $class; - } - - return $classes; - } - - private function askForRectorDescription(): string - { - $description = $this->symfonyStyle->ask('Short description of new Rector'); - - return $description ?? $this->askForRectorDescription(); - } - - /** - * @return array - */ - private function askForResources(): array - { - $resources = []; - - while (true) { - $question = sprintf( - 'Link to resource that explains why the change is needed (e.g. %s)', - 'https://github.com/symfony/symfony/blob/704c648ba53be38ef2b0105c97c6497744fef8d8/UPGRADE-6.0.md', - ); - $resource = $this->symfonyStyle->ask($question); - - if ($resource === null) { - break; - } - - $resources[] = $resource; - } - - return $resources; - } - - private function askForSet(): ?string - { - $question = new Question(sprintf('Set to which Rector should be added (e.g. %s)', 'SYMFONY_52')); - $question->setAutocompleterValues($this->setsListProvider->provide()); - - $setName = $this->symfonyStyle->askQuestion($question); - if ($setName === null) { - return null; - } - - return constant(SetList::class . $setName); - } -} diff --git a/packages/rector-generator/templates/rules/__package__/src/Rector/__Category__/__Configured__Name__.php b/packages/rector-generator/templates/rules/__package__/src/Rector/__Category__/__Configured__Name__.php deleted file mode 100644 index 7cac9ca4942..00000000000 --- a/packages/rector-generator/templates/rules/__package__/src/Rector/__Category__/__Configured__Name__.php +++ /dev/null @@ -1,53 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return __NodeTypesPhp__; - } - - /** - * @param __NodeTypesDoc__ $node - */ - public function refactor(Node $node): ?Node - { - // change the node - - return $node; - } - - __ConfigureClassMethod__ -} diff --git a/packages/rector-generator/templates/rules/__package__/src/Rector/__Category__/__Name__.php b/packages/rector-generator/templates/rules/__package__/src/Rector/__Category__/__Name__.php deleted file mode 100644 index 24e395ed4b6..00000000000 --- a/packages/rector-generator/templates/rules/__package__/src/Rector/__Category__/__Name__.php +++ /dev/null @@ -1,46 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return __NodeTypesPhp__; - } - - /** - * @param __NodeTypesDoc__ $node - */ - public function refactor(Node $node): ?Node - { - // change the node - - return $node; - } -} diff --git a/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/Fixture/some_class.php.inc b/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/Fixture/some_class.php.inc deleted file mode 100644 index 8a0db1893a2..00000000000 --- a/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/Fixture/some_class.php.inc +++ /dev/null @@ -1,13 +0,0 @@ - ------ - diff --git a/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/Source/extra_file.php.inc b/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/Source/extra_file.php.inc deleted file mode 100644 index a706c6bf5b3..00000000000 --- a/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/Source/extra_file.php.inc +++ /dev/null @@ -1,5 +0,0 @@ -doTestFileInfo($fileInfo); - $this->doTestExtraFile($expectedExtraFileName, $expectedExtraContentFilePath); - } - - public function provideData(): \Iterator - { - yield [new \Symplify\SmartFileSystem\SmartFileInfo(__DIR__ . '/Fixture/some_class.php.inc'), '__ExtraFileName__', __DIR__ . '/Source/extra_file.php']; - } - - protected function provideConfigFilePath(): string - { - return __DIR__ . '/configured_rule.php'; - } -} diff --git a/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/__Configured__Name__Test.php.inc b/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/__Configured__Name__Test.php.inc deleted file mode 100644 index f8be0954c23..00000000000 --- a/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/__Configured__Name__Test.php.inc +++ /dev/null @@ -1,28 +0,0 @@ -doTestFileInfo($fileInfo); - } - - public function provideData(): \Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - protected function provideConfigFilePath(): string - { - return __DIR__ . '/configured_rule.php'; - } -} diff --git a/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/__Extra__Name__Test.php.inc b/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/__Extra__Name__Test.php.inc deleted file mode 100644 index 2a21eb3b6b4..00000000000 --- a/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/__Extra__Name__Test.php.inc +++ /dev/null @@ -1,29 +0,0 @@ -doTestFileInfo($fileInfo); - $this->doTestExtraFile($expectedExtraFileName, $expectedExtraContentFilePath); - } - - public function provideData(): \Iterator - { - yield [new \Symplify\SmartFileSystem\SmartFileInfo(__DIR__ . '/Fixture/some_class.php.inc'), '__ExtraFileName__', __DIR__ . '/Source/extra_file.php']; - } - - protected function getRectorClass(): string - { - return \Rector\__Package__\Rector\__Category__\__Name__::class; - } -} diff --git a/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/__Name__Test.php.inc b/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/__Name__Test.php.inc deleted file mode 100644 index f9851812acf..00000000000 --- a/packages/rector-generator/templates/rules/__package__/tests/Rector/__Category__/__Name__/__Name__Test.php.inc +++ /dev/null @@ -1,28 +0,0 @@ -doTestFileInfo($fileInfo); - } - - public function provideData(): \Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - protected function getRectorClass(): string - { - return \Rector\__Package__\Rector\__Category__\__Name__::class; - } -} diff --git a/packages/rector-generator/tests/Provider/NodeTypesProviderTest.php b/packages/rector-generator/tests/Provider/NodeTypesProviderTest.php deleted file mode 100644 index 77b60e3fd70..00000000000 --- a/packages/rector-generator/tests/Provider/NodeTypesProviderTest.php +++ /dev/null @@ -1,33 +0,0 @@ -bootKernel(RectorKernel::class); - $this->nodeTypesProvider = $this->getService(NodeTypesProvider::class); - } - - public function test(): void - { - $nodeTypes = $this->nodeTypesProvider->provide(); - $nodeTypeCount = count($nodeTypes); - $this->assertGreaterThan(70, $nodeTypeCount); - - $this->assertContains('Expr\New_', $nodeTypes); - $this->assertContains('Param', $nodeTypes); - } -} diff --git a/packages/rector-generator/tests/Provider/PackageNamesProviderTest.php b/packages/rector-generator/tests/Provider/PackageNamesProviderTest.php deleted file mode 100644 index 9fa634aafe4..00000000000 --- a/packages/rector-generator/tests/Provider/PackageNamesProviderTest.php +++ /dev/null @@ -1,33 +0,0 @@ -bootKernel(RectorKernel::class); - $this->packageNamesProvider = $this->getService(PackageNamesProvider::class); - } - - public function test(): void - { - $packageNames = $this->packageNamesProvider->provide(); - $packageNameCount = count($packageNames); - $this->assertGreaterThan(60, $packageNameCount); - - $this->assertContains('DeadCode', $packageNames); - $this->assertContains('Symfony5', $packageNames); - } -} diff --git a/packages/rector-generator/tests/RectorGenerator/Fixture/expected/rules/moderate-package/src/Rector/MethodCall/WhateverRector.php b/packages/rector-generator/tests/RectorGenerator/Fixture/expected/rules/moderate-package/src/Rector/MethodCall/WhateverRector.php deleted file mode 100644 index e8b6451ef59..00000000000 --- a/packages/rector-generator/tests/RectorGenerator/Fixture/expected/rules/moderate-package/src/Rector/MethodCall/WhateverRector.php +++ /dev/null @@ -1,87 +0,0 @@ -arg(...) to $service->call(...)', [ - new ConfiguredCodeSample( - <<<'CODE_SAMPLE' -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; - -return static function (ContainerConfigurator $containerConfigurator): void { - $services = $containerConfigurator->services(); - - $services->set(SomeClass::class) - ->arg('$key', 'value'); -} -CODE_SAMPLE -, - <<<'CODE_SAMPLE' -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; - -return static function (ContainerConfigurator $containerConfigurator): void { - $services = $containerConfigurator->services(); - - $services->set(SomeClass::class) - ->call('configure', [[ - '$key' => 'value' - ]]); -} -CODE_SAMPLE -, - [self::CLASS_TYPE_TO_METHOD_NAME => ['SomeClass' => 'configure']] - ) - ]); - } - - /** - * @return array> - */ - public function getNodeTypes(): array - { - return [\PhpParser\Node\Expr\MethodCall::class]; - } - - /** - * @param \PhpParser\Node\Expr\MethodCall $node - */ - public function refactor(Node $node): ?Node - { - // change the node - - return $node; - } - - /** - * @param mixed[] $configuration - */ -public function configure(array $configuration): void -{ - $this->classTypeToMethodName = $configuration[self::CLASS_TYPE_TO_METHOD_NAME] ?? []; -} -} diff --git a/packages/rector-generator/tests/RectorGenerator/Fixture/expected/rules/moderate-package/tests/Rector/MethodCall/WhateverRector/Fixture/some_class.php.inc b/packages/rector-generator/tests/RectorGenerator/Fixture/expected/rules/moderate-package/tests/Rector/MethodCall/WhateverRector/Fixture/some_class.php.inc deleted file mode 100644 index f6728023b2a..00000000000 --- a/packages/rector-generator/tests/RectorGenerator/Fixture/expected/rules/moderate-package/tests/Rector/MethodCall/WhateverRector/Fixture/some_class.php.inc +++ /dev/null @@ -1,31 +0,0 @@ -services(); - - $services->set(SomeClass::class) - ->arg('$key', 'value'); -} - -?> ------ -services(); - - $services->set(SomeClass::class) - ->call('configure', [[ - '$key' => 'value' - ]]); -} - -?> diff --git a/packages/rector-generator/tests/RectorGenerator/Fixture/expected/rules/moderate-package/tests/Rector/MethodCall/WhateverRector/WhateverRectorTest.php.inc b/packages/rector-generator/tests/RectorGenerator/Fixture/expected/rules/moderate-package/tests/Rector/MethodCall/WhateverRector/WhateverRectorTest.php.inc deleted file mode 100644 index 47e49f64e8f..00000000000 --- a/packages/rector-generator/tests/RectorGenerator/Fixture/expected/rules/moderate-package/tests/Rector/MethodCall/WhateverRector/WhateverRectorTest.php.inc +++ /dev/null @@ -1,28 +0,0 @@ -doTestFileInfo($fileInfo); - } - - public function provideData(): \Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - protected function provideConfigFilePath(): string - { - return __DIR__ . '/configured_rule.php'; - } -} diff --git a/packages/rector-generator/tests/RectorGenerator/Fixture/expected_3rd_party/utils/rector/src/Rector/MethodCall/WhateverRector.php b/packages/rector-generator/tests/RectorGenerator/Fixture/expected_3rd_party/utils/rector/src/Rector/MethodCall/WhateverRector.php deleted file mode 100644 index 9fe28f35654..00000000000 --- a/packages/rector-generator/tests/RectorGenerator/Fixture/expected_3rd_party/utils/rector/src/Rector/MethodCall/WhateverRector.php +++ /dev/null @@ -1,87 +0,0 @@ -arg(...) to $service->call(...)', [ - new ConfiguredCodeSample( - <<<'CODE_SAMPLE' -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; - -return static function (ContainerConfigurator $containerConfigurator): void { - $services = $containerConfigurator->services(); - - $services->set(SomeClass::class) - ->arg('$key', 'value'); -} -CODE_SAMPLE -, - <<<'CODE_SAMPLE' -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; - -return static function (ContainerConfigurator $containerConfigurator): void { - $services = $containerConfigurator->services(); - - $services->set(SomeClass::class) - ->call('configure', [[ - '$key' => 'value' - ]]); -} -CODE_SAMPLE -, - [self::CLASS_TYPE_TO_METHOD_NAME => ['SomeClass' => 'configure']] - ) - ]); - } - - /** - * @return array> - */ - public function getNodeTypes(): array - { - return [\PhpParser\Node\Expr\MethodCall::class]; - } - - /** - * @param \PhpParser\Node\Expr\MethodCall $node - */ - public function refactor(Node $node): ?Node - { - // change the node - - return $node; - } - - /** - * @param mixed[] $configuration - */ -public function configure(array $configuration): void -{ - $this->classTypeToMethodName = $configuration[self::CLASS_TYPE_TO_METHOD_NAME] ?? []; -} -} diff --git a/packages/rector-generator/tests/RectorGenerator/Fixture/expected_3rd_party/utils/rector/tests/Rector/MethodCall/WhateverRector/Fixture/some_class.php.inc b/packages/rector-generator/tests/RectorGenerator/Fixture/expected_3rd_party/utils/rector/tests/Rector/MethodCall/WhateverRector/Fixture/some_class.php.inc deleted file mode 100644 index 91c81f7fc36..00000000000 --- a/packages/rector-generator/tests/RectorGenerator/Fixture/expected_3rd_party/utils/rector/tests/Rector/MethodCall/WhateverRector/Fixture/some_class.php.inc +++ /dev/null @@ -1,31 +0,0 @@ -services(); - - $services->set(SomeClass::class) - ->arg('$key', 'value'); -} - -?> ------ -services(); - - $services->set(SomeClass::class) - ->call('configure', [[ - '$key' => 'value' - ]]); -} - -?> diff --git a/packages/rector-generator/tests/RectorGenerator/Fixture/expected_3rd_party/utils/rector/tests/Rector/MethodCall/WhateverRector/WhateverRectorTest.php.inc b/packages/rector-generator/tests/RectorGenerator/Fixture/expected_3rd_party/utils/rector/tests/Rector/MethodCall/WhateverRector/WhateverRectorTest.php.inc deleted file mode 100644 index a0b298a72d0..00000000000 --- a/packages/rector-generator/tests/RectorGenerator/Fixture/expected_3rd_party/utils/rector/tests/Rector/MethodCall/WhateverRector/WhateverRectorTest.php.inc +++ /dev/null @@ -1,28 +0,0 @@ -doTestFileInfo($fileInfo); - } - - public function provideData(): \Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - protected function provideConfigFilePath(): string - { - return __DIR__ . '/configured_rule.php'; - } -} diff --git a/packages/rector-generator/tests/RectorGenerator/RectorGeneratorTest.php b/packages/rector-generator/tests/RectorGenerator/RectorGeneratorTest.php deleted file mode 100644 index 2f563e75e02..00000000000 --- a/packages/rector-generator/tests/RectorGenerator/RectorGeneratorTest.php +++ /dev/null @@ -1,68 +0,0 @@ -bootKernel(RectorKernel::class); - - $this->smartFileSystem = $this->getService(SmartFileSystem::class); - $this->rectorRecipeGenerator = $this->getService(RectorRecipeGenerator::class); - } - - protected function tearDown(): void - { - // cleanup temporary data - $this->smartFileSystem->remove(self::DESTINATION_DIRECTORY); - } - - public function test(): void - { - $rectorRecipe = $this->createConfiguration(true); - $this->rectorRecipeGenerator->generate($rectorRecipe, self::DESTINATION_DIRECTORY); - - $this->assertDirectoryEquals(__DIR__ . '/Fixture/expected', self::DESTINATION_DIRECTORY); - } - - public function test3rdParty(): void - { - $rectorRecipe = $this->createConfiguration(false); - $this->rectorRecipeGenerator->generate($rectorRecipe, self::DESTINATION_DIRECTORY); - - $this->assertDirectoryEquals(__DIR__ . '/Fixture/expected_3rd_party', self::DESTINATION_DIRECTORY); - } - - private function createConfiguration(bool $isRectorRepository): RectorRecipe - { - return StaticRectorRecipeFactory::createRectorRecipe($isRectorRepository); - } -} diff --git a/packages/rector-generator/tests/RectorGenerator/Source/StaticRectorRecipeFactory.php b/packages/rector-generator/tests/RectorGenerator/Source/StaticRectorRecipeFactory.php deleted file mode 100644 index 1110e49f2f4..00000000000 --- a/packages/rector-generator/tests/RectorGenerator/Source/StaticRectorRecipeFactory.php +++ /dev/null @@ -1,64 +0,0 @@ -arg(...) to $service->call(...)', - <<<'CODE_SAMPLE' -services(); - - $services->set(SomeClass::class) - ->arg('$key', 'value'); -} -CODE_SAMPLE - , <<<'CODE_SAMPLE' -services(); - - $services->set(SomeClass::class) - ->call('configure', [[ - '$key' => 'value' - ]]); -} -CODE_SAMPLE - ); - - $rectorRecipe->setConfiguration([ - 'CLASS_TYPE_TO_METHOD_NAME' => [ - 'SomeClass' => 'configure' - ] - ]); - - $rectorRecipe->setIsRectorRepository($isRectorRepository); - - if ($isRectorRepository) { - $rectorRecipe->setPackage('ModeratePackage'); - } - - $rectorRecipe->setSet(SetList::DEAD_CODE); - - return $rectorRecipe; - } -} diff --git a/packages/rector-generator/tests/ValueObjectFactory/Fixture/expected_interactive/rules/test-package-name/src/Rector/Arg/TestRector.php b/packages/rector-generator/tests/ValueObjectFactory/Fixture/expected_interactive/rules/test-package-name/src/Rector/Arg/TestRector.php deleted file mode 100644 index 28264f9cca2..00000000000 --- a/packages/rector-generator/tests/ValueObjectFactory/Fixture/expected_interactive/rules/test-package-name/src/Rector/Arg/TestRector.php +++ /dev/null @@ -1,64 +0,0 @@ -something(); - } -} -CODE_SAMPLE - - , - <<<'CODE_SAMPLE' -class SomeClass -{ - public function run() - { - $this->somethingElse(); - } -} -CODE_SAMPLE - - ) - ]); - } - - /** - * @return array> - */ - public function getNodeTypes(): array - { - return [\PhpParser\Node\Arg::class]; - } - - /** - * @param \PhpParser\Node\Arg $node - */ - public function refactor(Node $node): ?Node - { - // change the node - - return $node; - } -} diff --git a/packages/rector-generator/tests/ValueObjectFactory/Fixture/expected_interactive/rules/test-package-name/tests/Rector/Arg/TestRector/Fixture/some_class.php.inc b/packages/rector-generator/tests/ValueObjectFactory/Fixture/expected_interactive/rules/test-package-name/tests/Rector/Arg/TestRector/Fixture/some_class.php.inc deleted file mode 100644 index ba0ea21a10c..00000000000 --- a/packages/rector-generator/tests/ValueObjectFactory/Fixture/expected_interactive/rules/test-package-name/tests/Rector/Arg/TestRector/Fixture/some_class.php.inc +++ /dev/null @@ -1,27 +0,0 @@ -something(); - } -} - -?> ------ -somethingElse(); - } -} - -?> diff --git a/packages/rector-generator/tests/ValueObjectFactory/Fixture/expected_interactive/rules/test-package-name/tests/Rector/Arg/TestRector/TestRectorTest.php.inc b/packages/rector-generator/tests/ValueObjectFactory/Fixture/expected_interactive/rules/test-package-name/tests/Rector/Arg/TestRector/TestRectorTest.php.inc deleted file mode 100644 index bd81157b915..00000000000 --- a/packages/rector-generator/tests/ValueObjectFactory/Fixture/expected_interactive/rules/test-package-name/tests/Rector/Arg/TestRector/TestRectorTest.php.inc +++ /dev/null @@ -1,28 +0,0 @@ -doTestFileInfo($fileInfo); - } - - public function provideData(): \Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - protected function getRectorClass(): string - { - return \Rector\TestPackageName\Rector\Arg\TestRector::class; - } -} diff --git a/packages/rector-generator/tests/ValueObjectFactory/RectorRecipeInteractiveProviderTest.php b/packages/rector-generator/tests/ValueObjectFactory/RectorRecipeInteractiveProviderTest.php deleted file mode 100644 index ea37f592aac..00000000000 --- a/packages/rector-generator/tests/ValueObjectFactory/RectorRecipeInteractiveProviderTest.php +++ /dev/null @@ -1,81 +0,0 @@ -bootKernel(RectorKernel::class); - $this->rectorRecipeInteractiveFactory = $this->getService(RectorRecipeInteractiveFactory::class); - $this->rectorRecipeGenerator = $this->getService(RectorRecipeGenerator::class); - - $this->manualInteractiveInputProvider = $this->getService(ManualInteractiveInputProvider::class); - $this->smartFileSystem = $this->getService(SmartFileSystem::class); - } - - public function test(): void - { - $this->manualInteractiveInputProvider->setInput(['Naming', 'T', 'Arg', 'Description']); - - $this->expectException(ConfigurationException::class); - $this->expectExceptionMessage('Rector name "T" must end with "Rector"'); - - $this->rectorRecipeInteractiveFactory->create(); - } - - public function testGeneratesRectorRule(): void - { - $this->manualInteractiveInputProvider->setInput( - ['TestPackageName', 'TestRector', 'Arg', 'Description', null, null, 'no'] - ); - $rectorRecipe = $this->rectorRecipeInteractiveFactory->create(); - - // generate - $this->rectorRecipeGenerator->generate($rectorRecipe, self::DESTINATION_DIRECTORY); - - // compare it - $this->assertDirectoryEquals(__DIR__ . '/Fixture/expected_interactive', self::DESTINATION_DIRECTORY); - - // clear it - $this->smartFileSystem->remove(self::DESTINATION_DIRECTORY); - } -} diff --git a/phpstan.neon b/phpstan.neon index f05934d3bf9..9d934ad2253 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -632,3 +632,8 @@ parameters: - '#Do not use scalar or array as constructor parameter\. Use "Symplify\\PackageBuilder\\Parameter\\ParameterProvider" service instead#' - '#Content of method "getNextExpression\(\)" is duplicated with method "getNextExpression\(\)" in "Rector\\Php73\\Rector\\FuncCall\\ArrayKeyFirstLastRector" class\. Use unique content or service instead#' + + - + message: '#Function "class_exists\(\)" cannot be used/left in the code#' + paths: + - src/HttpKernel/RectorKernel.php diff --git a/phpunit.xml b/phpunit.xml index aeb5daa493c..e7d1119abac 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -5,33 +5,18 @@ bootstrap="tests/bootstrap.php" colors="true" > - - - ./packages - ./rules - ./src - ./utils - - - ./packages/*/tests - ./rules/*/tests - ./packages/rector-generator/templates - ./utils/*/tests - - + + + rules/*/tests + packages-tests + tests + utils/*/tests + rules/nette-tester-to-phpunit/tests/Rector/RenameTesterTestToPHPUnitToTestFileRector/Source/* + + + - - - rules/*/tests - packages/*/tests - tests - utils/*/tests - packages/rector-generator/templates/* - packages/rector-generator/tests/RectorGenerator/Fixture/expected - rules/nette-tester-to-phpunit/tests/Rector/RenameTesterTestToPHPUnitToTestFileRector/Source/* - - diff --git a/rector.php b/rector.php index 7e3eb1d30e9..8664ca1b904 100644 --- a/rector.php +++ b/rector.php @@ -84,9 +84,6 @@ return static function (ContainerConfigurator $containerConfigurator): void { '*/Expected/*', __DIR__ . '/packages/DoctrineAnnotationGenerated', - // template files - __DIR__ . '/packages/rector-generator/templates', - __DIR__ . '/packages/rector-generator/src/ValueObject/RectorRecipe.php', ]); $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_73); diff --git a/rules/restoration/src/ClassMap/ExistingClassesProvider.php b/rules/restoration/src/ClassMap/ExistingClassesProvider.php index 3717350c828..f9d617b265a 100644 --- a/rules/restoration/src/ClassMap/ExistingClassesProvider.php +++ b/rules/restoration/src/ClassMap/ExistingClassesProvider.php @@ -70,8 +70,6 @@ final class ExistingClassesProvider $robotLoader->addDirectory(getcwd() . '/' . $directory); } - $robotLoader->excludeDirectory(__DIR__ . '/../../../../packages/rector-generator'); - $classNames = []; foreach (array_keys($robotLoader->getIndexedClasses()) as $className) { if (! is_string($className)) { diff --git a/src/Application/ActiveRectorsProvider.php b/src/Application/ActiveRectorsProvider.php index b302e78dc31..b8c095e225c 100644 --- a/src/Application/ActiveRectorsProvider.php +++ b/src/Application/ActiveRectorsProvider.php @@ -6,7 +6,6 @@ namespace Rector\Core\Application; use Rector\Core\Contract\Rector\RectorInterface; use Rector\PostRector\Contract\Rector\PostRectorInterface; -use Rector\RectorGenerator\Contract\InternalRectorInterface; use Symplify\Skipper\Skipper\Skipper; use Symplify\SmartFileSystem\SmartFileInfo; @@ -64,11 +63,6 @@ final class ActiveRectorsProvider sort($rectors); $rectors = array_filter($rectors, function (RectorInterface $rector): bool { - // utils rules - if ($rector instanceof InternalRectorInterface) { - return false; - } - // skip as internal and always run return ! $rector instanceof PostRectorInterface; }); diff --git a/src/Console/Command/InitCommand.php b/src/Console/Command/InitCommand.php index a0bfc29e6fb..d204e04df2a 100644 --- a/src/Console/Command/InitCommand.php +++ b/src/Console/Command/InitCommand.php @@ -4,24 +4,41 @@ declare(strict_types=1); namespace Rector\Core\Console\Command; -use Rector\RectorGenerator\TemplateInitializer; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; use Symplify\PackageBuilder\Console\ShellCode; +use Symplify\SmartFileSystem\FileSystemGuard; +use Symplify\SmartFileSystem\SmartFileSystem; final class InitCommand extends Command { /** - * @var TemplateInitializer + * @var FileSystemGuard */ - private $templateInitializer; + private $fileSystemGuard; + + /** + * @var SmartFileSystem + */ + private $smartFileSystem; + + /** + * @var SymfonyStyle + */ + private $symfonyStyle; + + public function __construct( + FileSystemGuard $fileSystemGuard, + SmartFileSystem $smartFileSystem, + SymfonyStyle $symfonyStyle + ) { + $this->fileSystemGuard = $fileSystemGuard; + $this->smartFileSystem = $smartFileSystem; + $this->symfonyStyle = $symfonyStyle; - public function __construct(TemplateInitializer $templateInitializer) - { parent::__construct(); - - $this->templateInitializer = $templateInitializer; } protected function configure(): void @@ -31,7 +48,18 @@ final class InitCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { - $this->templateInitializer->initialize(__DIR__ . '/../../../templates/rector.php.dist', 'rector.php'); + $rectorTemplateFilePath = __DIR__ . '/../../../templates/rector.php.dist'; + $this->fileSystemGuard->ensureFileExists($rectorTemplateFilePath, __METHOD__); + + $rectorRootFilePath = getcwd() . '/rector.php'; + + $doesFileExist = $this->smartFileSystem->exists($rectorRootFilePath); + if ($doesFileExist) { + $this->symfonyStyle->warning('Config file "rector.php" already exists'); + } else { + $this->smartFileSystem->copy($rectorTemplateFilePath, $rectorRootFilePath); + $this->symfonyStyle->success('"rector.php" config file was added'); + } return ShellCode::SUCCESS; } diff --git a/src/HttpKernel/RectorKernel.php b/src/HttpKernel/RectorKernel.php index 783d7210af2..d340b70636e 100644 --- a/src/HttpKernel/RectorKernel.php +++ b/src/HttpKernel/RectorKernel.php @@ -9,6 +9,7 @@ use Rector\Core\DependencyInjection\Collector\ConfigureCallValuesCollector; use Rector\Core\DependencyInjection\CompilerPass\MakeRectorsPublicCompilerPass; use Rector\Core\DependencyInjection\CompilerPass\MergeImportedRectorConfigureCallValuesCompilerPass; use Rector\Core\DependencyInjection\Loader\ConfigurableCallValuesCollectingPhpFileLoader; +use Rector\RectorGenerator\Bundle\RectorGeneratorBundle; use Symfony\Component\Config\Loader\DelegatingLoader; use Symfony\Component\Config\Loader\GlobFileLoader; use Symfony\Component\Config\Loader\LoaderInterface; @@ -79,13 +80,20 @@ final class RectorKernel extends Kernel implements ExtraConfigAwareKernelInterfa */ public function registerBundles(): iterable { - return [ + $bundles = [ new ConsoleColorDiffBundle(), new PhpConfigPrinterBundle(), new ComposerJsonManipulatorBundle(), new SkipperBundle(), new SimplePhpDocParserBundle(), ]; + + // only for dev + if (class_exists(RectorGeneratorBundle::class)) { + $bundles[] = new RectorGeneratorBundle(); + } + + return $bundles; } protected function build(ContainerBuilder $containerBuilder): void diff --git a/src/PhpParser/Node/NodeFactory.php b/src/PhpParser/Node/NodeFactory.php index 4807bb7449f..36843839c68 100644 --- a/src/PhpParser/Node/NodeFactory.php +++ b/src/PhpParser/Node/NodeFactory.php @@ -221,7 +221,6 @@ final class NodeFactory public function createPropertyAssignmentWithExpr(string $propertyName, Expr $expr): Assign { $propertyFetch = $this->createPropertyFetch(self::THIS, $propertyName); - return new Assign($propertyFetch, $expr); } diff --git a/templates/rector-recipe.php.dist b/templates/rector-recipe.php.dist deleted file mode 100644 index 1f8ffaac761..00000000000 --- a/templates/rector-recipe.php.dist +++ /dev/null @@ -1,80 +0,0 @@ -/src`, use PascalCase - 'Naming', - - // name, basically short class name; use PascalCase - 'RenameMethodCallRector', - - // 1+ node types to change, pick from classes here https://github.com/nikic/PHP-Parser/tree/master/lib/PhpParser/Node - // the best practise is to have just 1 type here if possible, and make separated rule for other node types - [MethodCall::class], - - // describe what the rule does - '"something()" will be renamed to "somethingElse()"', - - // code before change - // this is used for documentation and first test fixture - <<<'CODE_SAMPLE' -something(); - } -} - -CODE_SAMPLE - - // code after change - , <<<'CODE_SAMPLE' -somethingElse(); - } -} -CODE_SAMPLE - ); - - // [OPTIONAL - UNCOMMENT TO USE] - - // links to useful websites, that explain why the change is needed - // $rectorRecipe->setResources([ - // 'https://github.com/symfony/symfony/blob/704c648ba53be38ef2b0105c97c6497744fef8d8/UPGRADE-6.0.md' - // ]); - - // do you need to check for extra generated file? - // $rectorRecipe->addExtraFile('SomeExtraFile.php', 'setConfiguration(['SOME_CONSTANT_KEY' => ['before' => 'after']]); - - // [RECTOR CORE CONTRIBUTION - OPTIONAL] - // set the rule belongs to; is optional, because e.g. generic rules don't need a specific set to belong to - // $rectorRecipe->setSet(\Rector\Set\ValueObject\SetList::NAMING); - - $services = $containerConfigurator->services(); - - $services->set(RectorRecipeProvider::class) - ->arg('$rectorRecipe', ValueObjectInliner::inlineArgumentObject($rectorRecipe, $services)); -}; diff --git a/utils/doctrine-annotation-parser-syncer/src/Contract/Rector/ClassSyncerRectorInterface.php b/utils/doctrine-annotation-parser-syncer/src/Contract/Rector/ClassSyncerRectorInterface.php index a20051be821..fa47162a4c8 100644 --- a/utils/doctrine-annotation-parser-syncer/src/Contract/Rector/ClassSyncerRectorInterface.php +++ b/utils/doctrine-annotation-parser-syncer/src/Contract/Rector/ClassSyncerRectorInterface.php @@ -4,8 +4,6 @@ declare(strict_types=1); namespace Rector\Utils\DoctrineAnnotationParserSyncer\Contract\Rector; -use Rector\RectorGenerator\Contract\InternalRectorInterface; - -interface ClassSyncerRectorInterface extends InternalRectorInterface +interface ClassSyncerRectorInterface { } diff --git a/utils/project-validator/src/Command/ValidateFixtureFilenameCommand.php b/utils/project-validator/src/Command/ValidateFixtureFilenameCommand.php index 7cea1a4b164..d43f3d5af92 100644 --- a/utils/project-validator/src/Command/ValidateFixtureFilenameCommand.php +++ b/utils/project-validator/src/Command/ValidateFixtureFilenameCommand.php @@ -70,7 +70,7 @@ final class ValidateFixtureFilenameCommand extends Command ->name('#(?<=-)[^\/]*\.php\.inc$#') ->path('#/Fixture/#') ->in(__DIR__ . '/../../../../tests') - ->in(__DIR__ . '/../../../../packages/*/tests') + ->in(__DIR__ . '/../../../../packages-tests') ->in(__DIR__ . '/../../../../rules/*/tests'); return $this->finderSanitizer->sanitize($finder); diff --git a/utils/project-validator/src/Command/ValidateFixtureSuffixCommand.php b/utils/project-validator/src/Command/ValidateFixtureSuffixCommand.php index 6ec7083f216..18aff0417ce 100644 --- a/utils/project-validator/src/Command/ValidateFixtureSuffixCommand.php +++ b/utils/project-validator/src/Command/ValidateFixtureSuffixCommand.php @@ -82,7 +82,7 @@ final class ValidateFixtureSuffixCommand extends Command ->notPath('Rector/FileNode/RenameSpecFileToTestFileRector/Fixture/some_file_Spec.php') ->notPath('Rector/FileWithoutNamespace/PseudoNamespaceToNamespaceRector/Fixture/DateTime.php') ->in(__DIR__ . '/../../../../tests') - ->in(__DIR__ . '/../../../../packages/*/tests') + ->in(__DIR__ . '/../../../../packages-tests') ->in(__DIR__ . '/../../../../rules/*/tests'); return $this->finderSanitizer->sanitize($finder);