diff --git a/.gitignore b/.gitignore index bb4b79c706b5..341abfeadb8c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,13 +10,10 @@ composer.lock # often customized locally - example on Github is just fine create-rector.yaml -phpstan-dependencies.json -phpstan-paths.txt # tests - travis /laravel-dir - -uuid-migration.json +/utils # compiler /compiler/composer.lock @@ -24,4 +21,4 @@ uuid-migration.json /tmp # from "scan-fatal-errors" command -rector-types.yaml \ No newline at end of file +rector-types.yaml diff --git a/compiler/build/box.json b/compiler/build/box.json index 0affa26d52f8..01a2890ef9d8 100644 --- a/compiler/build/box.json +++ b/compiler/build/box.json @@ -9,7 +9,6 @@ "directories": [ "config", "src", - "helpers", "packages", "vendor" ], diff --git a/composer.json b/composer.json index 2d0a3693381d..ef4cfecba651 100644 --- a/composer.json +++ b/composer.json @@ -102,10 +102,7 @@ "Rector\\Twig\\": "packages/Twig/src", "Rector\\TypeDeclaration\\": "packages/TypeDeclaration/src", "Rector\\ZendToSymfony\\": "packages/ZendToSymfony/src", - "Rector\\Utils\\DocumentationGenerator\\": "utils/DocumentationGenerator/src", - "Rector\\Utils\\RectorGenerator\\": "utils/RectorGenerator/src", - "Rector\\Utils\\PHPStanAttributeTypeSyncer\\": "utils/PHPStanAttributeTypeSyncer/src", - "Rector\\Utils\\PHPStanStaticTypeMapperChecker\\": "utils/PHPStanStaticTypeMapperChecker/src", + "Rector\\RectorGenerator\\": "packages/RectorGenerator/src", "Rector\\StrictCodeQuality\\": "packages/StrictCodeQuality/src", "Rector\\DynamicTypeAnalysis\\": "packages/DynamicTypeAnalysis/src", "Rector\\PhpDeglobalize\\": "packages/PhpDeglobalize/src", @@ -116,7 +113,7 @@ "Rector\\CakePHPToSymfony\\": "packages/CakePHPToSymfony/src" }, "files": [ - "helpers/rector_dump_function.php" + "src/functions/rector_dump_function.php" ] }, "autoload-dev": { @@ -176,6 +173,9 @@ "Rector\\DynamicTypeAnalysis\\Tests\\": "packages/DynamicTypeAnalysis/tests", "Rector\\PhpDeglobalize\\Tests\\": "packages/PhpDeglobalize/tests", "Rector\\Phalcon\\Tests\\": "packages/Phalcon/tests", + "Rector\\Utils\\DocumentationGenerator\\": "utils/DocumentationGenerator/src", + "Rector\\Utils\\PHPStanAttributeTypeSyncer\\": "utils/PHPStanAttributeTypeSyncer/src", + "Rector\\Utils\\PHPStanStaticTypeMapperChecker\\": "utils/PHPStanStaticTypeMapperChecker/src", "Rector\\DoctrineGedmoToKnplabs\\Tests\\": "packages/DoctrineGedmoToKnplabs/tests", "Rector\\MinimalScope\\Tests\\": "packages/MinimalScope/tests", "Rector\\Polyfill\\Tests\\": "packages/Polyfill/tests", diff --git a/config/config.yaml b/config/config.yaml index 1c911199205a..88b69b1d237f 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -2,7 +2,8 @@ imports: - { resource: '../packages/**/config/config.yaml' } - { resource: 'services.yaml' } # only in local repository - - { resource: '../utils/**/config/config.yaml' } + # ignore errors, because utils are not part of composer package nor rector.phar + - { resource: '../utils/**/config/config.yaml', ignore_errors: true } parameters: # processed paths diff --git a/config/services.yaml b/config/services.yaml index fa2761468881..f89de6a58c83 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -15,6 +15,7 @@ services: - '../src/DependencyInjection/Loader/*' - '../src/HttpKernel/*' - '../src/ValueObject/*' + - '../src/functions/*' # extra services Rector\Symfony\Rector\Form\Helper\FormTypeStringToTypeProvider: null diff --git a/helpers/rector_dump_function.php b/helpers/rector_dump_function.php deleted file mode 100644 index 99f909a33b2e..000000000000 --- a/helpers/rector_dump_function.php +++ /dev/null @@ -1,17 +0,0 @@ -getSrcNamespace(), PHP_EOL )); - if ($isConfirmed === false) { + if (! $isConfirmed) { return; } diff --git a/utils/RectorGenerator/src/Configuration/ConfigurationFactory.php b/packages/RectorGenerator/src/Configuration/ConfigurationFactory.php similarity index 95% rename from utils/RectorGenerator/src/Configuration/ConfigurationFactory.php rename to packages/RectorGenerator/src/Configuration/ConfigurationFactory.php index 9018fa59342a..4667dabbee3d 100644 --- a/utils/RectorGenerator/src/Configuration/ConfigurationFactory.php +++ b/packages/RectorGenerator/src/Configuration/ConfigurationFactory.php @@ -2,15 +2,15 @@ declare(strict_types=1); -namespace Rector\Utils\RectorGenerator\Configuration; +namespace Rector\RectorGenerator\Configuration; use Nette\Utils\Strings; use PhpParser\Node; use Rector\Exception\ShouldNotHappenException; +use Rector\RectorGenerator\Guard\RecipeGuard; +use Rector\RectorGenerator\Node\NodeClassProvider; +use Rector\RectorGenerator\ValueObject\Configuration; use Rector\Set\Set; -use Rector\Utils\RectorGenerator\Guard\RecipeGuard; -use Rector\Utils\RectorGenerator\Node\NodeClassProvider; -use Rector\Utils\RectorGenerator\ValueObject\Configuration; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; diff --git a/utils/RectorGenerator/src/Exception/ConfigurationException.php b/packages/RectorGenerator/src/Exception/ConfigurationException.php similarity index 68% rename from utils/RectorGenerator/src/Exception/ConfigurationException.php rename to packages/RectorGenerator/src/Exception/ConfigurationException.php index e62be0008686..22205ce62cdc 100644 --- a/utils/RectorGenerator/src/Exception/ConfigurationException.php +++ b/packages/RectorGenerator/src/Exception/ConfigurationException.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\Utils\RectorGenerator\Exception; +namespace Rector\RectorGenerator\Exception; use Exception; diff --git a/utils/RectorGenerator/src/FileSystem/JsonFileSystem.php b/packages/RectorGenerator/src/FileSystem/JsonFileSystem.php similarity index 95% rename from utils/RectorGenerator/src/FileSystem/JsonFileSystem.php rename to packages/RectorGenerator/src/FileSystem/JsonFileSystem.php index 1073daaaf7e9..6d8b9b2e6a91 100644 --- a/utils/RectorGenerator/src/FileSystem/JsonFileSystem.php +++ b/packages/RectorGenerator/src/FileSystem/JsonFileSystem.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\Utils\RectorGenerator\FileSystem; +namespace Rector\RectorGenerator\FileSystem; use Nette\Utils\FileSystem; use Nette\Utils\Json; diff --git a/utils/RectorGenerator/src/FileSystem/JsonStringFormatter.php b/packages/RectorGenerator/src/FileSystem/JsonStringFormatter.php similarity index 86% rename from utils/RectorGenerator/src/FileSystem/JsonStringFormatter.php rename to packages/RectorGenerator/src/FileSystem/JsonStringFormatter.php index c7c0ca98c162..1d1783aa6c1f 100644 --- a/utils/RectorGenerator/src/FileSystem/JsonStringFormatter.php +++ b/packages/RectorGenerator/src/FileSystem/JsonStringFormatter.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\Utils\RectorGenerator\FileSystem; +namespace Rector\RectorGenerator\FileSystem; use Nette\Utils\Strings; @@ -29,14 +29,13 @@ public function inlineSections(string $jsonContent, array $sections): string public function inlineAuthors(string $jsonContent): string { $pattern = '#(?"authors": \[\s+)(?.*?)(?\s+\](,))#ms'; - $jsonContent = Strings::replace($jsonContent, $pattern, function (array $match): string { + + return Strings::replace($jsonContent, $pattern, function (array $match): string { $inlined = Strings::replace($match['content'], '#\s+#', ' '); $inlined = trim($inlined); $inlined = Strings::replace($inlined, '#},#', "},\n "); return $match['start'] . $inlined . $match['end']; }); - - return $jsonContent; } } diff --git a/utils/RectorGenerator/src/FileSystem/TemplateFileSystem.php b/packages/RectorGenerator/src/FileSystem/TemplateFileSystem.php similarity index 87% rename from utils/RectorGenerator/src/FileSystem/TemplateFileSystem.php rename to packages/RectorGenerator/src/FileSystem/TemplateFileSystem.php index 70a61f8ff176..bbf01a865a05 100644 --- a/utils/RectorGenerator/src/FileSystem/TemplateFileSystem.php +++ b/packages/RectorGenerator/src/FileSystem/TemplateFileSystem.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace Rector\Utils\RectorGenerator\FileSystem; +namespace Rector\RectorGenerator\FileSystem; use Nette\Utils\Strings; -use Rector\Utils\RectorGenerator\Finder\TemplateFinder; -use Rector\Utils\RectorGenerator\ValueObject\Configuration; -use Rector\Utils\RectorGenerator\ValueObject\Package; +use Rector\RectorGenerator\Finder\TemplateFinder; +use Rector\RectorGenerator\ValueObject\Configuration; +use Rector\RectorGenerator\ValueObject\Package; use Symplify\SmartFileSystem\SmartFileInfo; final class TemplateFileSystem diff --git a/utils/RectorGenerator/src/Finder/TemplateFinder.php b/packages/RectorGenerator/src/Finder/TemplateFinder.php similarity index 87% rename from utils/RectorGenerator/src/Finder/TemplateFinder.php rename to packages/RectorGenerator/src/Finder/TemplateFinder.php index d7124553e6ab..80e7f46a531f 100644 --- a/utils/RectorGenerator/src/Finder/TemplateFinder.php +++ b/packages/RectorGenerator/src/Finder/TemplateFinder.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\Utils\RectorGenerator\Finder; +namespace Rector\RectorGenerator\Finder; use Symfony\Component\Finder\Finder; use Symplify\SmartFileSystem\Finder\FinderSanitizer; @@ -35,9 +35,10 @@ public function __construct(FinderSanitizer $finderSanitizer) */ public function find(bool $isPhpSnippet): array { - $finder = Finder::create()->files() - ->in(self::TEMPLATES_DIRECTORY) - ->exclude(self::TEMPLATES_FIXTURE_DIRECTORY); + $finder = Finder::create() + ->files() + ->exclude('Fixture/') + ->in(self::TEMPLATES_DIRECTORY); $smartFileInfos = $this->finderSanitizer->sanitize($finder); $smartFileInfos[] = $this->createFixtureSmartFileInfo($isPhpSnippet); diff --git a/utils/RectorGenerator/src/Guard/RecipeGuard.php b/packages/RectorGenerator/src/Guard/RecipeGuard.php similarity index 90% rename from utils/RectorGenerator/src/Guard/RecipeGuard.php rename to packages/RectorGenerator/src/Guard/RecipeGuard.php index ae9dd43742e6..b7f0a3891b2d 100644 --- a/utils/RectorGenerator/src/Guard/RecipeGuard.php +++ b/packages/RectorGenerator/src/Guard/RecipeGuard.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Rector\Utils\RectorGenerator\Guard; +namespace Rector\RectorGenerator\Guard; -use Rector\Utils\RectorGenerator\Exception\ConfigurationException; +use Rector\RectorGenerator\Exception\ConfigurationException; final class RecipeGuard { diff --git a/utils/RectorGenerator/src/Node/NodeClassProvider.php b/packages/RectorGenerator/src/Node/NodeClassProvider.php similarity index 92% rename from utils/RectorGenerator/src/Node/NodeClassProvider.php rename to packages/RectorGenerator/src/Node/NodeClassProvider.php index 97e830354cc9..6d819a941f2c 100644 --- a/utils/RectorGenerator/src/Node/NodeClassProvider.php +++ b/packages/RectorGenerator/src/Node/NodeClassProvider.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\Utils\RectorGenerator\Node; +namespace Rector\RectorGenerator\Node; use Nette\Loaders\RobotLoader; diff --git a/utils/RectorGenerator/src/TemplateVariablesFactory.php b/packages/RectorGenerator/src/TemplateVariablesFactory.php similarity index 96% rename from utils/RectorGenerator/src/TemplateVariablesFactory.php rename to packages/RectorGenerator/src/TemplateVariablesFactory.php index 093d580f26e1..2338ce5314e3 100644 --- a/utils/RectorGenerator/src/TemplateVariablesFactory.php +++ b/packages/RectorGenerator/src/TemplateVariablesFactory.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\Utils\RectorGenerator; +namespace Rector\RectorGenerator; use Nette\Utils\Strings; use PhpParser\Node\Expr\Array_; @@ -10,7 +10,7 @@ use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Name\FullyQualified; use Rector\PhpParser\Printer\BetterStandardPrinter; -use Rector\Utils\RectorGenerator\ValueObject\Configuration; +use Rector\RectorGenerator\ValueObject\Configuration; final class TemplateVariablesFactory { diff --git a/utils/RectorGenerator/src/ValueObject/Configuration.php b/packages/RectorGenerator/src/ValueObject/Configuration.php similarity index 98% rename from utils/RectorGenerator/src/ValueObject/Configuration.php rename to packages/RectorGenerator/src/ValueObject/Configuration.php index 0d5e08ad8e7c..a518df58698f 100644 --- a/utils/RectorGenerator/src/ValueObject/Configuration.php +++ b/packages/RectorGenerator/src/ValueObject/Configuration.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\Utils\RectorGenerator\ValueObject; +namespace Rector\RectorGenerator\ValueObject; use Nette\Utils\Strings; diff --git a/utils/RectorGenerator/src/ValueObject/Package.php b/packages/RectorGenerator/src/ValueObject/Package.php similarity index 95% rename from utils/RectorGenerator/src/ValueObject/Package.php rename to packages/RectorGenerator/src/ValueObject/Package.php index c967aa417eef..aec573855ed1 100644 --- a/utils/RectorGenerator/src/ValueObject/Package.php +++ b/packages/RectorGenerator/src/ValueObject/Package.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\Utils\RectorGenerator\ValueObject; +namespace Rector\RectorGenerator\ValueObject; final class Package { diff --git a/utils/RectorGenerator/templates/packages/_Package_/src/Rector/_Category_/_Name_.php.inc b/packages/RectorGenerator/templates/packages/_Package_/src/Rector/_Category_/_Name_.php.inc similarity index 100% rename from utils/RectorGenerator/templates/packages/_Package_/src/Rector/_Category_/_Name_.php.inc rename to packages/RectorGenerator/templates/packages/_Package_/src/Rector/_Category_/_Name_.php.inc diff --git a/utils/RectorGenerator/templates/packages/_Package_/tests/Rector/_Category_/_Name_/Fixture/fixture.php.inc b/packages/RectorGenerator/templates/packages/_Package_/tests/Rector/_Category_/_Name_/Fixture/fixture.php.inc similarity index 100% rename from utils/RectorGenerator/templates/packages/_Package_/tests/Rector/_Category_/_Name_/Fixture/fixture.php.inc rename to packages/RectorGenerator/templates/packages/_Package_/tests/Rector/_Category_/_Name_/Fixture/fixture.php.inc diff --git a/utils/RectorGenerator/templates/packages/_Package_/tests/Rector/_Category_/_Name_/Fixture/html_fixture.php.inc b/packages/RectorGenerator/templates/packages/_Package_/tests/Rector/_Category_/_Name_/Fixture/html_fixture.php.inc similarity index 100% rename from utils/RectorGenerator/templates/packages/_Package_/tests/Rector/_Category_/_Name_/Fixture/html_fixture.php.inc rename to packages/RectorGenerator/templates/packages/_Package_/tests/Rector/_Category_/_Name_/Fixture/html_fixture.php.inc diff --git a/utils/RectorGenerator/templates/packages/_Package_/tests/Rector/_Category_/_Name_/_Name_Test.php.inc b/packages/RectorGenerator/templates/packages/_Package_/tests/Rector/_Category_/_Name_/_Name_Test.php.inc similarity index 100% rename from utils/RectorGenerator/templates/packages/_Package_/tests/Rector/_Category_/_Name_/_Name_Test.php.inc rename to packages/RectorGenerator/templates/packages/_Package_/tests/Rector/_Category_/_Name_/_Name_Test.php.inc diff --git a/src/functions/rector_dump_function.php b/src/functions/rector_dump_function.php new file mode 100644 index 000000000000..922cbd441e82 --- /dev/null +++ b/src/functions/rector_dump_function.php @@ -0,0 +1,21 @@ +