diff --git a/src/Application/FileProcessor.php b/src/Application/FileProcessor.php index 13f256d3bd6..7c3a404ead0 100644 --- a/src/Application/FileProcessor.php +++ b/src/Application/FileProcessor.php @@ -4,7 +4,6 @@ declare (strict_types=1); namespace Rector\Application; use RectorPrefix202412\Nette\Utils\FileSystem; -use RectorPrefix202412\Nette\Utils\Strings; use PHPStan\AnalysedCodeException; use PHPStan\Parser\ParserErrorsException; use Rector\Caching\Detector\ChangedFilesDetector; @@ -23,7 +22,6 @@ use Rector\ValueObject\Application\File; use Rector\ValueObject\Configuration; use Rector\ValueObject\Error\SystemError; use Rector\ValueObject\FileProcessResult; -use Rector\ValueObject\Reporting\FileDiff; use RectorPrefix202412\Symfony\Component\Console\Style\SymfonyStyle; use Throwable; final class FileProcessor @@ -68,11 +66,6 @@ final class FileProcessor * @readonly */ private NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator; - /** - * @var string - * @see https://regex101.com/r/llm7XZ/1 - */ - private const OPEN_TAG_SPACED_REGEX = '#^[ \\t]+<\\?php#m'; public function __construct(BetterStandardPrinter $betterStandardPrinter, RectorNodeTraverser $rectorNodeTraverser, SymfonyStyle $symfonyStyle, FileDiffFactory $fileDiffFactory, ChangedFilesDetector $changedFilesDetector, ErrorFactory $errorFactory, FilePathHelper $filePathHelper, PostFileProcessor $postFileProcessor, RectorParser $rectorParser, NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator) { $this->betterStandardPrinter = $betterStandardPrinter; @@ -157,26 +150,6 @@ final class FileProcessor { // only save to string first, no need to print to file when not needed $newContent = $this->betterStandardPrinter->printFormatPreserving($file->getNewStmts(), $file->getOldStmts(), $file->getOldTokens()); - /** - * When no diff applied, the PostRector may still change the content, that's why printing still needed - * On printing, the space may be wiped, these below check compare with original file content used to verify - * that no change actually needed - */ - if (!$file->getFileDiff() instanceof FileDiff) { - /** - * exact compare with original file content - */ - $originalFileContent = $file->getOriginalFileContent(); - if ($originalFileContent === $newContent) { - return; - } - // handle space before hasChanged() based on new content $file->changeFileContent($newContent); if ($configuration->isDryRun()) { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index e8a0b0f04db..ac34a6e8c54 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '1b68ff48b80d81bd4295ef304196fd97d74e0032'; + public const PACKAGE_VERSION = '912d0b7ecc78aae4cbc2f3df7992fab9b5c63014'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-12-01 00:40:46'; + public const RELEASE_DATE = '2024-12-01 22:00:05'; /** * @var int */ diff --git a/src/PhpParser/Printer/BetterStandardPrinter.php b/src/PhpParser/Printer/BetterStandardPrinter.php index d4689546630..6f08b39b0a0 100644 --- a/src/PhpParser/Printer/BetterStandardPrinter.php +++ b/src/PhpParser/Printer/BetterStandardPrinter.php @@ -22,6 +22,7 @@ use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\InterpolatedString; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Declare_; +use PhpParser\Node\Stmt\InlineHTML; use PhpParser\Node\Stmt\Nop; use PhpParser\PrettyPrinter\Standard; use PHPStan\Node\Expr\AlwaysRememberedExpr; @@ -343,12 +344,18 @@ final class BetterStandardPrinter extends Standard */ private function containsNop(array $nodes) : bool { + $hasNop = \false; foreach ($nodes as $node) { + // early false when visited Node is InlineHTML + if ($node instanceof InlineHTML) { + return \false; + } + // use flag to avoid next is InlineHTML that returns early if ($node instanceof Nop) { - return \true; + $hasNop = \true; } } - return \false; + return $hasNop; } private function wrapValueWith(String_ $string, string $wrap) : string { diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index a726f46353c..04e7686eeba 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -2236,6 +2236,9 @@ return array( 'Rector\\Symfony\\Contract\\Tag\\TagInterface' => $vendorDir . '/rector/rector-symfony/src/Contract/Tag/TagInterface.php', 'Rector\\Symfony\\DataProvider\\ServiceMapProvider' => $vendorDir . '/rector/rector-symfony/src/DataProvider/ServiceMapProvider.php', 'Rector\\Symfony\\DataProvider\\ServiceNameToTypeUniqueProvider' => $vendorDir . '/rector/rector-symfony/src/DataProvider/ServiceNameToTypeUniqueProvider.php', + 'Rector\\Symfony\\DependencyInjection\\NodeDecorator\\CommandConstructorDecorator' => $vendorDir . '/rector/rector-symfony/rules/DependencyInjection/NodeDecorator/CommandConstructorDecorator.php', + 'Rector\\Symfony\\DependencyInjection\\Rector\\Class_\\CommandGetByTypeToConstructorInjectionRector' => $vendorDir . '/rector/rector-symfony/rules/DependencyInjection/Rector/Class_/CommandGetByTypeToConstructorInjectionRector.php', + 'Rector\\Symfony\\DependencyInjection\\Rector\\Class_\\ControllerGetByTypeToConstructorInjectionRector' => $vendorDir . '/rector/rector-symfony/rules/DependencyInjection/Rector/Class_/ControllerGetByTypeToConstructorInjectionRector.php', 'Rector\\Symfony\\DowngradeSymfony70\\Rector\\Class_\\DowngradeSymfonyCommandAttributeRector' => $vendorDir . '/rector/rector-symfony/rules/DowngradeSymfony70/Rector/Class_/DowngradeSymfonyCommandAttributeRector.php', 'Rector\\Symfony\\Enum\\SensioAttribute' => $vendorDir . '/rector/rector-symfony/src/Enum/SensioAttribute.php', 'Rector\\Symfony\\Enum\\SymfonyAnnotation' => $vendorDir . '/rector/rector-symfony/src/Enum/SymfonyAnnotation.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 6969da7f429..a45bbd408cf 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -2455,6 +2455,9 @@ class ComposerStaticInitc12d7e0a7ec6f5f877903ca571cd9ab7 'Rector\\Symfony\\Contract\\Tag\\TagInterface' => __DIR__ . '/..' . '/rector/rector-symfony/src/Contract/Tag/TagInterface.php', 'Rector\\Symfony\\DataProvider\\ServiceMapProvider' => __DIR__ . '/..' . '/rector/rector-symfony/src/DataProvider/ServiceMapProvider.php', 'Rector\\Symfony\\DataProvider\\ServiceNameToTypeUniqueProvider' => __DIR__ . '/..' . '/rector/rector-symfony/src/DataProvider/ServiceNameToTypeUniqueProvider.php', + 'Rector\\Symfony\\DependencyInjection\\NodeDecorator\\CommandConstructorDecorator' => __DIR__ . '/..' . '/rector/rector-symfony/rules/DependencyInjection/NodeDecorator/CommandConstructorDecorator.php', + 'Rector\\Symfony\\DependencyInjection\\Rector\\Class_\\CommandGetByTypeToConstructorInjectionRector' => __DIR__ . '/..' . '/rector/rector-symfony/rules/DependencyInjection/Rector/Class_/CommandGetByTypeToConstructorInjectionRector.php', + 'Rector\\Symfony\\DependencyInjection\\Rector\\Class_\\ControllerGetByTypeToConstructorInjectionRector' => __DIR__ . '/..' . '/rector/rector-symfony/rules/DependencyInjection/Rector/Class_/ControllerGetByTypeToConstructorInjectionRector.php', 'Rector\\Symfony\\DowngradeSymfony70\\Rector\\Class_\\DowngradeSymfonyCommandAttributeRector' => __DIR__ . '/..' . '/rector/rector-symfony/rules/DowngradeSymfony70/Rector/Class_/DowngradeSymfonyCommandAttributeRector.php', 'Rector\\Symfony\\Enum\\SensioAttribute' => __DIR__ . '/..' . '/rector/rector-symfony/src/Enum/SensioAttribute.php', 'Rector\\Symfony\\Enum\\SymfonyAnnotation' => __DIR__ . '/..' . '/rector/rector-symfony/src/Enum/SymfonyAnnotation.php', diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 29f198f0e3b..feff15909d8 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1868,12 +1868,12 @@ "source": { "type": "git", "url": "https:\/\/github.com\/rectorphp\/rector-symfony.git", - "reference": "dfec6fd94c2cc2dc866b18c152aa7ecd45fd828e" + "reference": "617b3aff39d3ae14e5ea24ad5150fb4d0fc4a05e" }, "dist": { "type": "zip", - "url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/dfec6fd94c2cc2dc866b18c152aa7ecd45fd828e", - "reference": "dfec6fd94c2cc2dc866b18c152aa7ecd45fd828e", + "url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/617b3aff39d3ae14e5ea24ad5150fb4d0fc4a05e", + "reference": "617b3aff39d3ae14e5ea24ad5150fb4d0fc4a05e", "shasum": "" }, "require": { @@ -1898,7 +1898,7 @@ "tomasvotruba\/class-leak": "^1.0", "tracy\/tracy": "^2.10" }, - "time": "2024-11-24T16:11:00+00:00", + "time": "2024-12-01T14:07:35+00:00", "default-branch": true, "type": "rector-extension", "extra": { diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 60b363e8c1d..95c5f0864d8 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -2,4 +2,4 @@ namespace RectorPrefix202412; -return array('root' => array('name' => 'rector/rector-src', 'pretty_version' => 'dev-main', 'version' => 'dev-main', 'reference' => null, 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'dev' => \false), 'versions' => array('clue/ndjson-react' => array('pretty_version' => 'v1.3.0', 'version' => '1.3.0.0', 'reference' => '392dc165fce93b5bb5c637b67e59619223c931b0', 'type' => 'library', 'install_path' => __DIR__ . '/../clue/ndjson-react', 'aliases' => array(), 'dev_requirement' => \false), 'composer/pcre' => array('pretty_version' => '3.3.2', 'version' => '3.3.2.0', 'reference' => 'b2bed4734f0cc156ee1fe9c0da2550420d99a21e', 'type' => 'library', 'install_path' => __DIR__ . '/./pcre', 'aliases' => array(), 'dev_requirement' => \false), 'composer/semver' => array('pretty_version' => '3.4.3', 'version' => '3.4.3.0', 'reference' => '4313d26ada5e0c4edfbd1dc481a92ff7bff91f12', 'type' => 'library', 'install_path' => __DIR__ . '/./semver', 'aliases' => array(), 'dev_requirement' => \false), 'composer/xdebug-handler' => array('pretty_version' => '3.0.5', 'version' => '3.0.5.0', 'reference' => '6c1925561632e83d60a44492e0b344cf48ab85ef', 'type' => 'library', 'install_path' => __DIR__ . '/./xdebug-handler', 'aliases' => array(), 'dev_requirement' => \false), 'doctrine/inflector' => array('pretty_version' => '2.0.10', 'version' => '2.0.10.0', 'reference' => '5817d0659c5b50c9b950feb9af7b9668e2c436bc', 'type' => 'library', 'install_path' => __DIR__ . '/../doctrine/inflector', 'aliases' => array(), 'dev_requirement' => \false), 'evenement/evenement' => array('pretty_version' => 'v3.0.2', 'version' => '3.0.2.0', 'reference' => '0a16b0d71ab13284339abb99d9d2bd813640efbc', 'type' => 'library', 'install_path' => __DIR__ . '/../evenement/evenement', 'aliases' => array(), 'dev_requirement' => \false), 'fidry/cpu-core-counter' => array('pretty_version' => '1.2.0', 'version' => '1.2.0.0', 'reference' => '8520451a140d3f46ac33042715115e290cf5785f', 'type' => 'library', 'install_path' => __DIR__ . '/../fidry/cpu-core-counter', 'aliases' => array(), 'dev_requirement' => \false), 'illuminate/container' => array('pretty_version' => 'v11.34.2', 'version' => '11.34.2.0', 'reference' => 'b057b0bbb38d7c7524df1ca5c38e7318f4c64d26', 'type' => 'library', 'install_path' => __DIR__ . '/../illuminate/container', 'aliases' => array(), 'dev_requirement' => \false), 'illuminate/contracts' => array('pretty_version' => 'v11.34.2', 'version' => '11.34.2.0', 'reference' => '184317f701ba20ca265e36808ed54b75b115972d', 'type' => 'library', 'install_path' => __DIR__ . '/../illuminate/contracts', 'aliases' => array(), 'dev_requirement' => \false), 'nette/utils' => array('pretty_version' => 'v4.0.5', 'version' => '4.0.5.0', 'reference' => '736c567e257dbe0fcf6ce81b4d6dbe05c6899f96', 'type' => 'library', 'install_path' => __DIR__ . '/../nette/utils', 'aliases' => array(), 'dev_requirement' => \false), 'nikic/php-parser' => array('pretty_version' => 'v5.3.1', 'version' => '5.3.1.0', 'reference' => '8eea230464783aa9671db8eea6f8c6ac5285794b', 'type' => 'library', 'install_path' => __DIR__ . '/../nikic/php-parser', 'aliases' => array(), 'dev_requirement' => \false), 'ondram/ci-detector' => array('pretty_version' => '4.2.0', 'version' => '4.2.0.0', 'reference' => '8b0223b5ed235fd377c75fdd1bfcad05c0f168b8', 'type' => 'library', 'install_path' => __DIR__ . '/../ondram/ci-detector', 'aliases' => array(), 'dev_requirement' => \false), 'phpstan/phpdoc-parser' => array('pretty_version' => '2.0.0', 'version' => '2.0.0.0', 'reference' => 'c00d78fb6b29658347f9d37ebe104bffadf36299', 'type' => 'library', 'install_path' => __DIR__ . '/../phpstan/phpdoc-parser', 'aliases' => array(), 'dev_requirement' => \false), 'phpstan/phpstan' => array('dev_requirement' => \false, 'replaced' => array(0 => '2.0.3')), 'psr/container' => array('pretty_version' => '2.0.2', 'version' => '2.0.2.0', 'reference' => 'c71ecc56dfe541dbd90c5360474fbc405f8d5963', 'type' => 'library', 'install_path' => __DIR__ . '/../psr/container', 'aliases' => array(), 'dev_requirement' => \false), 'psr/container-implementation' => array('dev_requirement' => \false, 'provided' => array(0 => '1.1|2.0')), 'psr/log' => array('pretty_version' => '3.0.2', 'version' => '3.0.2.0', 'reference' => 'f16e1d5863e37f8d8c2a01719f5b34baa2b714d3', 'type' => 'library', 'install_path' => __DIR__ . '/../psr/log', 'aliases' => array(), 'dev_requirement' => \false), 'psr/log-implementation' => array('dev_requirement' => \false, 'provided' => array(0 => '1.0|2.0|3.0')), 'psr/simple-cache' => array('pretty_version' => '3.0.0', 'version' => '3.0.0.0', 'reference' => '764e0b3939f5ca87cb904f570ef9be2d78a07865', 'type' => 'library', 'install_path' => __DIR__ . '/../psr/simple-cache', 'aliases' => array(), 'dev_requirement' => \false), 'react/cache' => array('pretty_version' => 'v1.2.0', 'version' => '1.2.0.0', 'reference' => 'd47c472b64aa5608225f47965a484b75c7817d5b', 'type' => 'library', 'install_path' => __DIR__ . '/../react/cache', 'aliases' => array(), 'dev_requirement' => \false), 'react/child-process' => array('pretty_version' => 'v0.6.5', 'version' => '0.6.5.0', 'reference' => 'e71eb1aa55f057c7a4a0d08d06b0b0a484bead43', 'type' => 'library', 'install_path' => __DIR__ . '/../react/child-process', 'aliases' => array(), 'dev_requirement' => \false), 'react/dns' => array('pretty_version' => 'v1.13.0', 'version' => '1.13.0.0', 'reference' => 'eb8ae001b5a455665c89c1df97f6fb682f8fb0f5', 'type' => 'library', 'install_path' => __DIR__ . '/../react/dns', 'aliases' => array(), 'dev_requirement' => \false), 'react/event-loop' => array('pretty_version' => 'v1.5.0', 'version' => '1.5.0.0', 'reference' => 'bbe0bd8c51ffc05ee43f1729087ed3bdf7d53354', 'type' => 'library', 'install_path' => __DIR__ . '/../react/event-loop', 'aliases' => array(), 'dev_requirement' => \false), 'react/promise' => array('pretty_version' => 'v3.2.0', 'version' => '3.2.0.0', 'reference' => '8a164643313c71354582dc850b42b33fa12a4b63', 'type' => 'library', 'install_path' => __DIR__ . '/../react/promise', 'aliases' => array(), 'dev_requirement' => \false), 'react/socket' => array('pretty_version' => 'v1.16.0', 'version' => '1.16.0.0', 'reference' => '23e4ff33ea3e160d2d1f59a0e6050e4b0fb0eac1', 'type' => 'library', 'install_path' => __DIR__ . '/../react/socket', 'aliases' => array(), 'dev_requirement' => \false), 'react/stream' => array('pretty_version' => 'v1.4.0', 'version' => '1.4.0.0', 'reference' => '1e5b0acb8fe55143b5b426817155190eb6f5b18d', 'type' => 'library', 'install_path' => __DIR__ . '/../react/stream', 'aliases' => array(), 'dev_requirement' => \false), 'rector/extension-installer' => array('pretty_version' => '0.11.2', 'version' => '0.11.2.0', 'reference' => '05544e9b195863b8571ae2a3b903cbec7fa062e0', 'type' => 'composer-plugin', 'install_path' => __DIR__ . '/../rector/extension-installer', 'aliases' => array(), 'dev_requirement' => \false), 'rector/rector' => array('dev_requirement' => \false, 'replaced' => array(0 => 'dev-main')), 'rector/rector-doctrine' => array('pretty_version' => 'dev-main', 'version' => 'dev-main', 'reference' => '02ae401ff4e578a5dcdc0a68e5451628aaab2639', 'type' => 'rector-extension', 'install_path' => __DIR__ . '/../rector/rector-doctrine', 'aliases' => array(0 => '9999999-dev'), 'dev_requirement' => \false), 'rector/rector-downgrade-php' => array('pretty_version' => 'dev-main', 'version' => 'dev-main', 'reference' => '7bb52fbe9ada56afe39f7171de2a2ef847ed3571', 'type' => 'rector-extension', 'install_path' => __DIR__ . '/../rector/rector-downgrade-php', 'aliases' => array(0 => '9999999-dev'), 'dev_requirement' => \false), 'rector/rector-phpunit' => array('pretty_version' => 'dev-main', 'version' => 'dev-main', 'reference' => 'a506b2c8befb25aca43fe29fbc863b3126266916', 'type' => 'rector-extension', 'install_path' => __DIR__ . '/../rector/rector-phpunit', 'aliases' => array(0 => '0.11.x-dev'), 'dev_requirement' => \false), 'rector/rector-src' => array('pretty_version' => 'dev-main', 'version' => 'dev-main', 'reference' => null, 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'dev_requirement' => \false), 'rector/rector-symfony' => array('pretty_version' => 'dev-main', 'version' => 'dev-main', 'reference' => 'dfec6fd94c2cc2dc866b18c152aa7ecd45fd828e', 'type' => 'rector-extension', 'install_path' => __DIR__ . '/../rector/rector-symfony', 'aliases' => array(0 => '9999999-dev'), 'dev_requirement' => \false), 'sebastian/diff' => array('pretty_version' => '5.1.1', 'version' => '5.1.1.0', 'reference' => 'c41e007b4b62af48218231d6c2275e4c9b975b2e', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/diff', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/console' => array('pretty_version' => 'v6.4.15', 'version' => '6.4.15.0', 'reference' => 'f1fc6f47283e27336e7cebb9e8946c8de7bff9bd', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/console', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/deprecation-contracts' => array('pretty_version' => 'v3.5.1', 'version' => '3.5.1.0', 'reference' => '74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/deprecation-contracts', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/filesystem' => array('pretty_version' => 'v6.4.13', 'version' => '6.4.13.0', 'reference' => '4856c9cf585d5a0313d8d35afd681a526f038dd3', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/filesystem', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/finder' => array('pretty_version' => 'v6.4.13', 'version' => '6.4.13.0', 'reference' => 'daea9eca0b08d0ed1dc9ab702a46128fd1be4958', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/finder', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/polyfill-ctype' => array('dev_requirement' => \false, 'replaced' => array(0 => '*')), 'symfony/polyfill-intl-grapheme' => array('dev_requirement' => \false, 'replaced' => array(0 => '*')), 'symfony/polyfill-mbstring' => array('pretty_version' => 'v1.31.0', 'version' => '1.31.0.0', 'reference' => '85181ba99b2345b0ef10ce42ecac37612d9fd341', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/polyfill-mbstring', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/process' => array('pretty_version' => 'v6.4.15', 'version' => '6.4.15.0', 'reference' => '3cb242f059c14ae08591c5c4087d1fe443564392', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/process', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/service-contracts' => array('pretty_version' => 'v3.5.1', 'version' => '3.5.1.0', 'reference' => 'e53260aabf78fb3d63f8d79d69ece59f80d5eda0', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/service-contracts', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/string' => array('dev_requirement' => \false, 'replaced' => array(0 => '*')), 'symfony/yaml' => array('pretty_version' => 'v7.2.0', 'version' => '7.2.0.0', 'reference' => '099581e99f557e9f16b43c5916c26380b54abb22', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/yaml', 'aliases' => array(), 'dev_requirement' => \false), 'symplify/easy-parallel' => array('pretty_version' => '11.2.2', 'version' => '11.2.2.0', 'reference' => '8586c18bb8efb31cd192a4e5cc94ae7813f72ed9', 'type' => 'library', 'install_path' => __DIR__ . '/../symplify/easy-parallel', 'aliases' => array(), 'dev_requirement' => \false), 'symplify/rule-doc-generator-contracts' => array('pretty_version' => '11.2.0', 'version' => '11.2.0.0', 'reference' => '479cfcfd46047f80624aba931d9789e50475b5c6', 'type' => 'library', 'install_path' => __DIR__ . '/../symplify/rule-doc-generator-contracts', 'aliases' => array(), 'dev_requirement' => \false), 'webmozart/assert' => array('pretty_version' => '1.11.0', 'version' => '1.11.0.0', 'reference' => '11cb2199493b2f8a3b53e7f19068fc6aac760991', 'type' => 'library', 'install_path' => __DIR__ . '/../webmozart/assert', 'aliases' => array(), 'dev_requirement' => \false))); +return array('root' => array('name' => 'rector/rector-src', 'pretty_version' => 'dev-main', 'version' => 'dev-main', 'reference' => null, 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'dev' => \false), 'versions' => array('clue/ndjson-react' => array('pretty_version' => 'v1.3.0', 'version' => '1.3.0.0', 'reference' => '392dc165fce93b5bb5c637b67e59619223c931b0', 'type' => 'library', 'install_path' => __DIR__ . '/../clue/ndjson-react', 'aliases' => array(), 'dev_requirement' => \false), 'composer/pcre' => array('pretty_version' => '3.3.2', 'version' => '3.3.2.0', 'reference' => 'b2bed4734f0cc156ee1fe9c0da2550420d99a21e', 'type' => 'library', 'install_path' => __DIR__ . '/./pcre', 'aliases' => array(), 'dev_requirement' => \false), 'composer/semver' => array('pretty_version' => '3.4.3', 'version' => '3.4.3.0', 'reference' => '4313d26ada5e0c4edfbd1dc481a92ff7bff91f12', 'type' => 'library', 'install_path' => __DIR__ . '/./semver', 'aliases' => array(), 'dev_requirement' => \false), 'composer/xdebug-handler' => array('pretty_version' => '3.0.5', 'version' => '3.0.5.0', 'reference' => '6c1925561632e83d60a44492e0b344cf48ab85ef', 'type' => 'library', 'install_path' => __DIR__ . '/./xdebug-handler', 'aliases' => array(), 'dev_requirement' => \false), 'doctrine/inflector' => array('pretty_version' => '2.0.10', 'version' => '2.0.10.0', 'reference' => '5817d0659c5b50c9b950feb9af7b9668e2c436bc', 'type' => 'library', 'install_path' => __DIR__ . '/../doctrine/inflector', 'aliases' => array(), 'dev_requirement' => \false), 'evenement/evenement' => array('pretty_version' => 'v3.0.2', 'version' => '3.0.2.0', 'reference' => '0a16b0d71ab13284339abb99d9d2bd813640efbc', 'type' => 'library', 'install_path' => __DIR__ . '/../evenement/evenement', 'aliases' => array(), 'dev_requirement' => \false), 'fidry/cpu-core-counter' => array('pretty_version' => '1.2.0', 'version' => '1.2.0.0', 'reference' => '8520451a140d3f46ac33042715115e290cf5785f', 'type' => 'library', 'install_path' => __DIR__ . '/../fidry/cpu-core-counter', 'aliases' => array(), 'dev_requirement' => \false), 'illuminate/container' => array('pretty_version' => 'v11.34.2', 'version' => '11.34.2.0', 'reference' => 'b057b0bbb38d7c7524df1ca5c38e7318f4c64d26', 'type' => 'library', 'install_path' => __DIR__ . '/../illuminate/container', 'aliases' => array(), 'dev_requirement' => \false), 'illuminate/contracts' => array('pretty_version' => 'v11.34.2', 'version' => '11.34.2.0', 'reference' => '184317f701ba20ca265e36808ed54b75b115972d', 'type' => 'library', 'install_path' => __DIR__ . '/../illuminate/contracts', 'aliases' => array(), 'dev_requirement' => \false), 'nette/utils' => array('pretty_version' => 'v4.0.5', 'version' => '4.0.5.0', 'reference' => '736c567e257dbe0fcf6ce81b4d6dbe05c6899f96', 'type' => 'library', 'install_path' => __DIR__ . '/../nette/utils', 'aliases' => array(), 'dev_requirement' => \false), 'nikic/php-parser' => array('pretty_version' => 'v5.3.1', 'version' => '5.3.1.0', 'reference' => '8eea230464783aa9671db8eea6f8c6ac5285794b', 'type' => 'library', 'install_path' => __DIR__ . '/../nikic/php-parser', 'aliases' => array(), 'dev_requirement' => \false), 'ondram/ci-detector' => array('pretty_version' => '4.2.0', 'version' => '4.2.0.0', 'reference' => '8b0223b5ed235fd377c75fdd1bfcad05c0f168b8', 'type' => 'library', 'install_path' => __DIR__ . '/../ondram/ci-detector', 'aliases' => array(), 'dev_requirement' => \false), 'phpstan/phpdoc-parser' => array('pretty_version' => '2.0.0', 'version' => '2.0.0.0', 'reference' => 'c00d78fb6b29658347f9d37ebe104bffadf36299', 'type' => 'library', 'install_path' => __DIR__ . '/../phpstan/phpdoc-parser', 'aliases' => array(), 'dev_requirement' => \false), 'phpstan/phpstan' => array('dev_requirement' => \false, 'replaced' => array(0 => '2.0.3')), 'psr/container' => array('pretty_version' => '2.0.2', 'version' => '2.0.2.0', 'reference' => 'c71ecc56dfe541dbd90c5360474fbc405f8d5963', 'type' => 'library', 'install_path' => __DIR__ . '/../psr/container', 'aliases' => array(), 'dev_requirement' => \false), 'psr/container-implementation' => array('dev_requirement' => \false, 'provided' => array(0 => '1.1|2.0')), 'psr/log' => array('pretty_version' => '3.0.2', 'version' => '3.0.2.0', 'reference' => 'f16e1d5863e37f8d8c2a01719f5b34baa2b714d3', 'type' => 'library', 'install_path' => __DIR__ . '/../psr/log', 'aliases' => array(), 'dev_requirement' => \false), 'psr/log-implementation' => array('dev_requirement' => \false, 'provided' => array(0 => '1.0|2.0|3.0')), 'psr/simple-cache' => array('pretty_version' => '3.0.0', 'version' => '3.0.0.0', 'reference' => '764e0b3939f5ca87cb904f570ef9be2d78a07865', 'type' => 'library', 'install_path' => __DIR__ . '/../psr/simple-cache', 'aliases' => array(), 'dev_requirement' => \false), 'react/cache' => array('pretty_version' => 'v1.2.0', 'version' => '1.2.0.0', 'reference' => 'd47c472b64aa5608225f47965a484b75c7817d5b', 'type' => 'library', 'install_path' => __DIR__ . '/../react/cache', 'aliases' => array(), 'dev_requirement' => \false), 'react/child-process' => array('pretty_version' => 'v0.6.5', 'version' => '0.6.5.0', 'reference' => 'e71eb1aa55f057c7a4a0d08d06b0b0a484bead43', 'type' => 'library', 'install_path' => __DIR__ . '/../react/child-process', 'aliases' => array(), 'dev_requirement' => \false), 'react/dns' => array('pretty_version' => 'v1.13.0', 'version' => '1.13.0.0', 'reference' => 'eb8ae001b5a455665c89c1df97f6fb682f8fb0f5', 'type' => 'library', 'install_path' => __DIR__ . '/../react/dns', 'aliases' => array(), 'dev_requirement' => \false), 'react/event-loop' => array('pretty_version' => 'v1.5.0', 'version' => '1.5.0.0', 'reference' => 'bbe0bd8c51ffc05ee43f1729087ed3bdf7d53354', 'type' => 'library', 'install_path' => __DIR__ . '/../react/event-loop', 'aliases' => array(), 'dev_requirement' => \false), 'react/promise' => array('pretty_version' => 'v3.2.0', 'version' => '3.2.0.0', 'reference' => '8a164643313c71354582dc850b42b33fa12a4b63', 'type' => 'library', 'install_path' => __DIR__ . '/../react/promise', 'aliases' => array(), 'dev_requirement' => \false), 'react/socket' => array('pretty_version' => 'v1.16.0', 'version' => '1.16.0.0', 'reference' => '23e4ff33ea3e160d2d1f59a0e6050e4b0fb0eac1', 'type' => 'library', 'install_path' => __DIR__ . '/../react/socket', 'aliases' => array(), 'dev_requirement' => \false), 'react/stream' => array('pretty_version' => 'v1.4.0', 'version' => '1.4.0.0', 'reference' => '1e5b0acb8fe55143b5b426817155190eb6f5b18d', 'type' => 'library', 'install_path' => __DIR__ . '/../react/stream', 'aliases' => array(), 'dev_requirement' => \false), 'rector/extension-installer' => array('pretty_version' => '0.11.2', 'version' => '0.11.2.0', 'reference' => '05544e9b195863b8571ae2a3b903cbec7fa062e0', 'type' => 'composer-plugin', 'install_path' => __DIR__ . '/../rector/extension-installer', 'aliases' => array(), 'dev_requirement' => \false), 'rector/rector' => array('dev_requirement' => \false, 'replaced' => array(0 => 'dev-main')), 'rector/rector-doctrine' => array('pretty_version' => 'dev-main', 'version' => 'dev-main', 'reference' => '02ae401ff4e578a5dcdc0a68e5451628aaab2639', 'type' => 'rector-extension', 'install_path' => __DIR__ . '/../rector/rector-doctrine', 'aliases' => array(0 => '9999999-dev'), 'dev_requirement' => \false), 'rector/rector-downgrade-php' => array('pretty_version' => 'dev-main', 'version' => 'dev-main', 'reference' => '7bb52fbe9ada56afe39f7171de2a2ef847ed3571', 'type' => 'rector-extension', 'install_path' => __DIR__ . '/../rector/rector-downgrade-php', 'aliases' => array(0 => '9999999-dev'), 'dev_requirement' => \false), 'rector/rector-phpunit' => array('pretty_version' => 'dev-main', 'version' => 'dev-main', 'reference' => 'a506b2c8befb25aca43fe29fbc863b3126266916', 'type' => 'rector-extension', 'install_path' => __DIR__ . '/../rector/rector-phpunit', 'aliases' => array(0 => '0.11.x-dev'), 'dev_requirement' => \false), 'rector/rector-src' => array('pretty_version' => 'dev-main', 'version' => 'dev-main', 'reference' => null, 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'dev_requirement' => \false), 'rector/rector-symfony' => array('pretty_version' => 'dev-main', 'version' => 'dev-main', 'reference' => '617b3aff39d3ae14e5ea24ad5150fb4d0fc4a05e', 'type' => 'rector-extension', 'install_path' => __DIR__ . '/../rector/rector-symfony', 'aliases' => array(0 => '9999999-dev'), 'dev_requirement' => \false), 'sebastian/diff' => array('pretty_version' => '5.1.1', 'version' => '5.1.1.0', 'reference' => 'c41e007b4b62af48218231d6c2275e4c9b975b2e', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/diff', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/console' => array('pretty_version' => 'v6.4.15', 'version' => '6.4.15.0', 'reference' => 'f1fc6f47283e27336e7cebb9e8946c8de7bff9bd', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/console', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/deprecation-contracts' => array('pretty_version' => 'v3.5.1', 'version' => '3.5.1.0', 'reference' => '74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/deprecation-contracts', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/filesystem' => array('pretty_version' => 'v6.4.13', 'version' => '6.4.13.0', 'reference' => '4856c9cf585d5a0313d8d35afd681a526f038dd3', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/filesystem', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/finder' => array('pretty_version' => 'v6.4.13', 'version' => '6.4.13.0', 'reference' => 'daea9eca0b08d0ed1dc9ab702a46128fd1be4958', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/finder', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/polyfill-ctype' => array('dev_requirement' => \false, 'replaced' => array(0 => '*')), 'symfony/polyfill-intl-grapheme' => array('dev_requirement' => \false, 'replaced' => array(0 => '*')), 'symfony/polyfill-mbstring' => array('pretty_version' => 'v1.31.0', 'version' => '1.31.0.0', 'reference' => '85181ba99b2345b0ef10ce42ecac37612d9fd341', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/polyfill-mbstring', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/process' => array('pretty_version' => 'v6.4.15', 'version' => '6.4.15.0', 'reference' => '3cb242f059c14ae08591c5c4087d1fe443564392', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/process', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/service-contracts' => array('pretty_version' => 'v3.5.1', 'version' => '3.5.1.0', 'reference' => 'e53260aabf78fb3d63f8d79d69ece59f80d5eda0', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/service-contracts', 'aliases' => array(), 'dev_requirement' => \false), 'symfony/string' => array('dev_requirement' => \false, 'replaced' => array(0 => '*')), 'symfony/yaml' => array('pretty_version' => 'v7.2.0', 'version' => '7.2.0.0', 'reference' => '099581e99f557e9f16b43c5916c26380b54abb22', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/yaml', 'aliases' => array(), 'dev_requirement' => \false), 'symplify/easy-parallel' => array('pretty_version' => '11.2.2', 'version' => '11.2.2.0', 'reference' => '8586c18bb8efb31cd192a4e5cc94ae7813f72ed9', 'type' => 'library', 'install_path' => __DIR__ . '/../symplify/easy-parallel', 'aliases' => array(), 'dev_requirement' => \false), 'symplify/rule-doc-generator-contracts' => array('pretty_version' => '11.2.0', 'version' => '11.2.0.0', 'reference' => '479cfcfd46047f80624aba931d9789e50475b5c6', 'type' => 'library', 'install_path' => __DIR__ . '/../symplify/rule-doc-generator-contracts', 'aliases' => array(), 'dev_requirement' => \false), 'webmozart/assert' => array('pretty_version' => '1.11.0', 'version' => '1.11.0.0', 'reference' => '11cb2199493b2f8a3b53e7f19068fc6aac760991', 'type' => 'library', 'install_path' => __DIR__ . '/../webmozart/assert', 'aliases' => array(), 'dev_requirement' => \false))); diff --git a/vendor/rector/extension-installer/src/GeneratedConfig.php b/vendor/rector/extension-installer/src/GeneratedConfig.php index 17a5a58b87a..98a490a671d 100644 --- a/vendor/rector/extension-installer/src/GeneratedConfig.php +++ b/vendor/rector/extension-installer/src/GeneratedConfig.php @@ -9,7 +9,7 @@ namespace Rector\RectorInstaller; */ final class GeneratedConfig { - public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 02ae401'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 7bb52fb'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main a506b2c'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main dfec6fd')); + public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 02ae401'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 7bb52fb'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main a506b2c'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 617b3af')); private function __construct() { } diff --git a/vendor/rector/rector-symfony/config/sets/symfony/symfony-constructor-injection.php b/vendor/rector/rector-symfony/config/sets/symfony/symfony-constructor-injection.php index 09fe7d6aaa3..d06004fe58e 100644 --- a/vendor/rector/rector-symfony/config/sets/symfony/symfony-constructor-injection.php +++ b/vendor/rector/rector-symfony/config/sets/symfony/symfony-constructor-injection.php @@ -8,5 +8,13 @@ use Rector\Symfony\Symfony28\Rector\MethodCall\GetToConstructorInjectionRector; use Rector\Symfony\Symfony34\Rector\Closure\ContainerGetNameToTypeInTestsRector; use Rector\Symfony\Symfony42\Rector\MethodCall\ContainerGetToConstructorInjectionRector; return static function (RectorConfig $rectorConfig) : void { - $rectorConfig->rules([ContainerGetToConstructorInjectionRector::class, ContainerGetNameToTypeInTestsRector::class, GetToConstructorInjectionRector::class]); + $rectorConfig->rules([ + // modern step-by-step narrow approach + \Rector\Symfony\DependencyInjection\Rector\Class_\ControllerGetByTypeToConstructorInjectionRector::class, + \Rector\Symfony\DependencyInjection\Rector\Class_\CommandGetByTypeToConstructorInjectionRector::class, + // legacy rules that require container fetch + ContainerGetToConstructorInjectionRector::class, + ContainerGetNameToTypeInTestsRector::class, + GetToConstructorInjectionRector::class, + ]); }; diff --git a/vendor/rector/rector-symfony/rules/DependencyInjection/NodeDecorator/CommandConstructorDecorator.php b/vendor/rector/rector-symfony/rules/DependencyInjection/NodeDecorator/CommandConstructorDecorator.php new file mode 100644 index 00000000000..8c84f2d31cb --- /dev/null +++ b/vendor/rector/rector-symfony/rules/DependencyInjection/NodeDecorator/CommandConstructorDecorator.php @@ -0,0 +1,37 @@ +nodeTypeResolver = $nodeTypeResolver; + } + public function decorate(Class_ $class) : void + { + // special case for command to keep parent constructor call + if (!$this->nodeTypeResolver->isObjectType($class, new ObjectType('Symfony\\Component\\Console\\Command\\Command'))) { + return; + } + $constuctClassMethod = $class->getMethod(MethodName::CONSTRUCT); + if (!$constuctClassMethod instanceof ClassMethod) { + return; + } + // empty stmts? add parent::__construct() to setup command + if ((array) $constuctClassMethod->stmts === []) { + $parentConstructStaticCall = new StaticCall(new Name('parent'), '__construct'); + $constuctClassMethod->stmts[] = new Expression($parentConstructStaticCall); + } + } +} diff --git a/vendor/rector/rector-symfony/rules/DependencyInjection/Rector/Class_/CommandGetByTypeToConstructorInjectionRector.php b/vendor/rector/rector-symfony/rules/DependencyInjection/Rector/Class_/CommandGetByTypeToConstructorInjectionRector.php new file mode 100644 index 00000000000..2bdb38f6f5c --- /dev/null +++ b/vendor/rector/rector-symfony/rules/DependencyInjection/Rector/Class_/CommandGetByTypeToConstructorInjectionRector.php @@ -0,0 +1,145 @@ +classDependencyManipulator = $classDependencyManipulator; + $this->propertyNaming = $propertyNaming; + $this->commandConstructorDecorator = $commandConstructorDecorator; + } + public function getRuleDefinition() : RuleDefinition + { + return new RuleDefinition('From `$container->get(SomeType::class)` in commands to constructor injection (step 2/x)', [new CodeSample(<<<'CODE_SAMPLE' +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; + +final class SomeCommand extends ContainerAwareCommand +{ + public function someMethod() + { + $someType = $this->get(SomeType::class); + } +} +CODE_SAMPLE +, <<<'CODE_SAMPLE' +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; + +final class SomeCommand extends ContainerAwareCommand +{ + public function __construct(private SomeType $someType) + { + } + + public function someMethod() + { + $someType = $this->someType; + } +} +CODE_SAMPLE +)]); + } + /** + * @return array> + */ + public function getNodeTypes() : array + { + return [Class_::class]; + } + /** + * @param Class_ $node + */ + public function refactor(Node $node) : ?Node + { + if ($this->shouldSkipClass($node)) { + return null; + } + $propertyMetadatas = []; + $this->traverseNodesWithCallable($node, function (Node $node) use(&$propertyMetadatas) : ?Node { + if (!$node instanceof MethodCall) { + return null; + } + if ($node->isFirstClassCallable()) { + return null; + } + if (!$this->isName($node->name, 'get')) { + return null; + } + if (!$this->isName($node->var, 'this')) { + return null; + } + if (\count($node->getArgs()) !== 1) { + return null; + } + $firstArg = $node->getArgs()[0]; + if (!$firstArg->value instanceof ClassConstFetch) { + return null; + } + // must be class const fetch + if (!$this->isName($firstArg->value->name, 'class')) { + return null; + } + $className = $this->getName($firstArg->value->class); + if (!\is_string($className)) { + return null; + } + $propertyName = $this->propertyNaming->fqnToVariableName($className); + $propertyMetadata = new PropertyMetadata($propertyName, new FullyQualifiedObjectType($className)); + $propertyMetadatas[] = $propertyMetadata; + return $this->nodeFactory->createPropertyFetch('this', $propertyMetadata->getName()); + }); + if ($propertyMetadatas === []) { + return null; + } + foreach ($propertyMetadatas as $propertyMetadata) { + $this->classDependencyManipulator->addConstructorDependency($node, $propertyMetadata); + } + $this->commandConstructorDecorator->decorate($node); + return $node; + } + private function shouldSkipClass(Class_ $class) : bool + { + // keep it safe + if ($class->isAbstract()) { + return \true; + } + $scope = ScopeFetcher::fetch($class); + $classReflection = $scope->getClassReflection(); + if (!$classReflection instanceof ClassReflection) { + return \true; + } + return !$classReflection->isSubclassOf(SymfonyClass::CONTAINER_AWARE_COMMAND); + } +} diff --git a/vendor/rector/rector-symfony/rules/DependencyInjection/Rector/Class_/ControllerGetByTypeToConstructorInjectionRector.php b/vendor/rector/rector-symfony/rules/DependencyInjection/Rector/Class_/ControllerGetByTypeToConstructorInjectionRector.php new file mode 100644 index 00000000000..14e9c6b0e01 --- /dev/null +++ b/vendor/rector/rector-symfony/rules/DependencyInjection/Rector/Class_/ControllerGetByTypeToConstructorInjectionRector.php @@ -0,0 +1,138 @@ +classDependencyManipulator = $classDependencyManipulator; + $this->propertyNaming = $propertyNaming; + } + public function getRuleDefinition() : RuleDefinition + { + return new RuleDefinition('From `$container->get(SomeType::class)` in controllers to constructor injection (step 1/x)', [new CodeSample(<<<'CODE_SAMPLE' +use Symfony\Bundle\FrameworkBundle\Controller\Controller; + +final class SomeCommand extends Controller +{ + public function someMethod() + { + $someType = $this->get(SomeType::class); + } +} +CODE_SAMPLE +, <<<'CODE_SAMPLE' +use Symfony\Bundle\FrameworkBundle\Controller\Controller; + +final class SomeCommand extends Controller +{ + public function __construct(private SomeType $someType) + { + } + + public function someMethod() + { + $someType = $this->someType; + } +} +CODE_SAMPLE +)]); + } + /** + * @return array> + */ + public function getNodeTypes() : array + { + return [Class_::class]; + } + /** + * @param Class_ $node + */ + public function refactor(Node $node) : ?Node + { + if ($this->shouldSkipClass($node)) { + return null; + } + $propertyMetadatas = []; + $this->traverseNodesWithCallable($node, function (Node $node) use(&$propertyMetadatas) : ?Node { + if (!$node instanceof MethodCall) { + return null; + } + if ($node->isFirstClassCallable()) { + return null; + } + if (!$this->isName($node->name, 'get')) { + return null; + } + if (!$this->isName($node->var, 'this')) { + return null; + } + if (\count($node->getArgs()) !== 1) { + return null; + } + $firstArg = $node->getArgs()[0]; + if (!$firstArg->value instanceof ClassConstFetch) { + return null; + } + // must be class const fetch + if (!$this->isName($firstArg->value->name, 'class')) { + return null; + } + $className = $this->getName($firstArg->value->class); + if (!\is_string($className)) { + return null; + } + $propertyName = $this->propertyNaming->fqnToVariableName($className); + $propertyMetadata = new PropertyMetadata($propertyName, new FullyQualifiedObjectType($className)); + $propertyMetadatas[] = $propertyMetadata; + return $this->nodeFactory->createPropertyFetch('this', $propertyMetadata->getName()); + }); + if ($propertyMetadatas === []) { + return null; + } + foreach ($propertyMetadatas as $propertyMetadata) { + $this->classDependencyManipulator->addConstructorDependency($node, $propertyMetadata); + } + return $node; + } + private function shouldSkipClass(Class_ $class) : bool + { + // keep it safe + if (!$class->isFinal()) { + return \true; + } + $scope = ScopeFetcher::fetch($class); + $classReflection = $scope->getClassReflection(); + if (!$classReflection instanceof ClassReflection) { + return \true; + } + return !$classReflection->isSubclassOf(SymfonyClass::CONTROLLER); + } +} diff --git a/vendor/rector/rector-symfony/rules/Symfony42/Rector/MethodCall/ContainerGetToConstructorInjectionRector.php b/vendor/rector/rector-symfony/rules/Symfony42/Rector/MethodCall/ContainerGetToConstructorInjectionRector.php index 5bc4cd80fe8..72a2457429b 100644 --- a/vendor/rector/rector-symfony/rules/Symfony42/Rector/MethodCall/ContainerGetToConstructorInjectionRector.php +++ b/vendor/rector/rector-symfony/rules/Symfony42/Rector/MethodCall/ContainerGetToConstructorInjectionRector.php @@ -6,18 +6,14 @@ namespace Rector\Symfony\Symfony42\Rector\MethodCall; use PhpParser\Node; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\MethodCall; -use PhpParser\Node\Expr\StaticCall; -use PhpParser\Node\Name; use PhpParser\Node\Stmt\Class_; -use PhpParser\Node\Stmt\ClassMethod; -use PhpParser\Node\Stmt\Expression; use PHPStan\Type\ObjectType; use Rector\NodeManipulator\ClassDependencyManipulator; use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\PostRector\ValueObject\PropertyMetadata; use Rector\Rector\AbstractRector; +use Rector\Symfony\DependencyInjection\NodeDecorator\CommandConstructorDecorator; use Rector\Symfony\NodeAnalyzer\DependencyInjectionMethodCallAnalyzer; -use Rector\ValueObject\MethodName; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** @@ -39,11 +35,16 @@ final class ContainerGetToConstructorInjectionRector extends AbstractRector * @readonly */ private ClassDependencyManipulator $classDependencyManipulator; - public function __construct(DependencyInjectionMethodCallAnalyzer $dependencyInjectionMethodCallAnalyzer, TestsNodeAnalyzer $testsNodeAnalyzer, ClassDependencyManipulator $classDependencyManipulator) + /** + * @readonly + */ + private CommandConstructorDecorator $commandConstructorDecorator; + public function __construct(DependencyInjectionMethodCallAnalyzer $dependencyInjectionMethodCallAnalyzer, TestsNodeAnalyzer $testsNodeAnalyzer, ClassDependencyManipulator $classDependencyManipulator, CommandConstructorDecorator $commandConstructorDecorator) { $this->dependencyInjectionMethodCallAnalyzer = $dependencyInjectionMethodCallAnalyzer; $this->testsNodeAnalyzer = $testsNodeAnalyzer; $this->classDependencyManipulator = $classDependencyManipulator; + $this->commandConstructorDecorator = $commandConstructorDecorator; } public function getRuleDefinition() : RuleDefinition { @@ -123,23 +124,7 @@ CODE_SAMPLE foreach ($propertyMetadatas as $propertyMetadata) { $this->classDependencyManipulator->addConstructorDependency($class, $propertyMetadata); } - $this->decorateCommandConstructor($class); + $this->commandConstructorDecorator->decorate($class); return $node; } - private function decorateCommandConstructor(Class_ $class) : void - { - // special case for command to keep parent constructor call - if (!$this->isObjectType($class, new ObjectType('Symfony\\Component\\Console\\Command\\Command'))) { - return; - } - $constuctClassMethod = $class->getMethod(MethodName::CONSTRUCT); - if (!$constuctClassMethod instanceof ClassMethod) { - return; - } - // empty stmts? add parent::__construct() to setup command - if ((array) $constuctClassMethod->stmts === []) { - $parentConstructStaticCall = new StaticCall(new Name('parent'), '__construct'); - $constuctClassMethod->stmts[] = new Expression($parentConstructStaticCall); - } - } } diff --git a/vendor/rector/rector-symfony/src/Enum/SymfonyClass.php b/vendor/rector/rector-symfony/src/Enum/SymfonyClass.php index 7fd51ed1f49..4229e9f835c 100644 --- a/vendor/rector/rector-symfony/src/Enum/SymfonyClass.php +++ b/vendor/rector/rector-symfony/src/Enum/SymfonyClass.php @@ -5,6 +5,10 @@ namespace Rector\Symfony\Enum; final class SymfonyClass { + /** + * @var string + */ + public const CONTROLLER = 'Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller'; /** * @var string */ @@ -13,4 +17,8 @@ final class SymfonyClass * @var string */ public const COMMAND = 'Symfony\\Component\\Console\\Command\\Command'; + /** + * @var string + */ + public const CONTAINER_AWARE_COMMAND = 'Symfony\\Bundle\\FrameworkBundle\\Command\\ContainerAwareCommand'; } diff --git a/vendor/rector/rector-symfony/src/NodeAnalyzer/ServiceTypeMethodCallResolver.php b/vendor/rector/rector-symfony/src/NodeAnalyzer/ServiceTypeMethodCallResolver.php index 08da2871907..5645fc6c5ee 100644 --- a/vendor/rector/rector-symfony/src/NodeAnalyzer/ServiceTypeMethodCallResolver.php +++ b/vendor/rector/rector-symfony/src/NodeAnalyzer/ServiceTypeMethodCallResolver.php @@ -32,7 +32,8 @@ final class ServiceTypeMethodCallResolver if (!isset($methodCall->args[0])) { return new MixedType(); } - $argument = $methodCall->getArgs()[0]->value; + $firstArg = $methodCall->getArgs()[0]; + $argument = $firstArg->value; $serviceMap = $this->serviceMapProvider->provide(); if ($argument instanceof String_) { return $serviceMap->getServiceType($argument->value);