From 07e5908c4a0f9e5f2ce0153974db4e40f5b3796f Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 11 Dec 2024 11:18:22 +0000 Subject: [PATCH] Updated Rector to commit f5c95f5f8d2476456409694aacad3ac1d78df3e1 https://github.com/rectorphp/rector-src/commit/f5c95f5f8d2476456409694aacad3ac1d78df3e1 [CodeQuality] Handle crash on yield from on OptionalParametersAfterRequiredRector (#6545) --- src/Application/VersionResolver.php | 4 ++-- src/Configuration/ConfigurationRuleFilter.php | 15 +++++++-------- src/Configuration/OnlyRuleResolver.php | 5 +++-- src/Console/Command/ProcessCommand.php | 3 +++ .../PHPStan/Scope/PHPStanNodeScopeResolver.php | 4 +++- src/Parallel/Command/WorkerCommandLineFactory.php | 2 +- vendor/composer/InstalledVersions.php | 11 +++++++---- 7 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index f190e7dce16..92b964ccac9 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 = 'ebbada3fcdda79b5737d5a8986ceaf538a7159dd'; + public const PACKAGE_VERSION = 'f5c95f5f8d2476456409694aacad3ac1d78df3e1'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-12-10 17:08:16'; + public const RELEASE_DATE = '2024-12-11 18:15:48'; /** * @var int */ diff --git a/src/Configuration/ConfigurationRuleFilter.php b/src/Configuration/ConfigurationRuleFilter.php index 85822ba3a12..5d7bcb1f304 100644 --- a/src/Configuration/ConfigurationRuleFilter.php +++ b/src/Configuration/ConfigurationRuleFilter.php @@ -16,30 +16,29 @@ final class ConfigurationRuleFilter $this->configuration = $configuration; } /** - * @param array $rectors - * @return array + * @param list $rectors + * @return list */ public function filter(array $rectors) : array { - if ($this->configuration === null) { + if (!$this->configuration instanceof Configuration) { return $rectors; } $onlyRule = $this->configuration->getOnlyRule(); if ($onlyRule !== null) { - $rectors = $this->filterOnlyRule($rectors, $onlyRule); - return $rectors; + return $this->filterOnlyRule($rectors, $onlyRule); } return $rectors; } /** - * @param array $rectors - * @return array + * @param list $rectors + * @return list */ public function filterOnlyRule(array $rectors, string $onlyRule) : array { $activeRectors = []; foreach ($rectors as $rector) { - if (\is_a($rector, $onlyRule)) { + if ($rector instanceof $onlyRule) { $activeRectors[] = $rector; } } diff --git a/src/Configuration/OnlyRuleResolver.php b/src/Configuration/OnlyRuleResolver.php index 5fcd3bed844..c7e8ad16aa9 100644 --- a/src/Configuration/OnlyRuleResolver.php +++ b/src/Configuration/OnlyRuleResolver.php @@ -47,12 +47,13 @@ final class OnlyRuleResolver $matching = \array_unique($matching); if (\count($matching) == 1) { return $matching[0]; - } elseif (\count($matching) > 1) { + } + if (\count($matching) > 1) { \sort($matching); $message = \sprintf('Short rule name "%s" is ambiguous. Specify the full rule name:' . \PHP_EOL . '- ' . \implode(\PHP_EOL . '- ', $matching), $rule); throw new RectorRuleNameAmbigiousException($message); } - if (\strpos($rule, '\\') === \false) { + if (\in_array(\strpos($rule, '\\') !== \false, [0, \false], \true)) { $message = \sprintf('Rule "%s" was not found.%sThe rule has no namespace. Make sure to escape the backslashes, and add quotes around the rule name: --only="My\\Rector\\Rule"', $rule, \PHP_EOL); } else { $message = \sprintf('Rule "%s" was not found.%sMake sure it is registered in your config or in one of the sets', $rule, \PHP_EOL); diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index d44a1c95544..2aefe1ad58e 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -73,6 +73,9 @@ final class ProcessCommand extends Command * @readonly */ private MissConfigurationReporter $missConfigurationReporter; + /** + * @readonly + */ private ConfigurationRuleFilter $configurationRuleFilter; public function __construct(AdditionalAutoloader $additionalAutoloader, ChangedFilesDetector $changedFilesDetector, ConfigInitializer $configInitializer, ApplicationFileProcessor $applicationFileProcessor, DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator, OutputFormatterCollector $outputFormatterCollector, SymfonyStyle $symfonyStyle, MemoryLimiter $memoryLimiter, ConfigurationFactory $configurationFactory, DeprecatedRulesReporter $deprecatedRulesReporter, MissConfigurationReporter $missConfigurationReporter, ConfigurationRuleFilter $configurationRuleFilter) { diff --git a/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php b/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php index dda0a7f6708..1e461565e06 100644 --- a/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php +++ b/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php @@ -29,6 +29,7 @@ use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Expr\Ternary; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Yield_; +use PhpParser\Node\Expr\YieldFrom; use PhpParser\Node\Identifier; use PhpParser\Node\IntersectionType; use PhpParser\Node\Name; @@ -175,7 +176,7 @@ final class PHPStanNodeScopeResolver return; } $this->decorateNodeAttrGroups($node, $mutatingScope, $nodeCallback); - if (($node instanceof Expression || $node instanceof Return_ || $node instanceof EnumCase || $node instanceof Cast) && $node->expr instanceof Expr) { + if (($node instanceof Expression || $node instanceof Return_ || $node instanceof EnumCase || $node instanceof Cast || $node instanceof YieldFrom) && $node->expr instanceof Expr) { $node->expr->setAttribute(AttributeKey::SCOPE, $mutatingScope); return; } @@ -273,6 +274,7 @@ final class PHPStanNodeScopeResolver } if ($node instanceof Yield_) { $this->processYield($node, $mutatingScope); + return; } }; $this->nodeScopeResolverProcessNodes($stmts, $scope, $nodeCallback); diff --git a/src/Parallel/Command/WorkerCommandLineFactory.php b/src/Parallel/Command/WorkerCommandLineFactory.php index 66b25208a8a..885226ed16f 100644 --- a/src/Parallel/Command/WorkerCommandLineFactory.php +++ b/src/Parallel/Command/WorkerCommandLineFactory.php @@ -99,7 +99,7 @@ final class WorkerCommandLineFactory } if ($input->getOption(Option::ONLY) !== null) { $workerCommandArray[] = self::OPTION_DASHES . Option::ONLY; - $workerCommandArray[] = \escapeshellarg($input->getOption(Option::ONLY)); + $workerCommandArray[] = \escapeshellarg((string) $input->getOption(Option::ONLY)); } return \implode(' ', $workerCommandArray); } diff --git a/vendor/composer/InstalledVersions.php b/vendor/composer/InstalledVersions.php index 3ad1ee0420f..b6c4fba8736 100644 --- a/vendor/composer/InstalledVersions.php +++ b/vendor/composer/InstalledVersions.php @@ -280,6 +280,7 @@ class InstalledVersions self::$canGetVendors = \method_exists('RectorPrefix202412\\Composer\\Autoload\\ClassLoader', 'getRegisteredLoaders'); } $installed = array(); + $copiedLocalDir = \false; if (self::$canGetVendors) { foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { if (isset(self::$installedByVendor[$vendorDir])) { @@ -287,9 +288,11 @@ class InstalledVersions } elseif (\is_file($vendorDir . '/composer/installed.php')) { /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ $required = (require $vendorDir . '/composer/installed.php'); - $installed[] = self::$installedByVendor[$vendorDir] = $required; - if (null === self::$installed && \strtr($vendorDir . '/composer', '\\', '/') === \strtr(__DIR__, '\\', '/')) { - self::$installed = $installed[\count($installed) - 1]; + self::$installedByVendor[$vendorDir] = $required; + $installed[] = $required; + if (\strtr($vendorDir . '/composer', '\\', '/') === \strtr(__DIR__, '\\', '/')) { + self::$installed = $required; + $copiedLocalDir = \true; } } } @@ -305,7 +308,7 @@ class InstalledVersions self::$installed = array(); } } - if (self::$installed !== array()) { + if (self::$installed !== array() && !$copiedLocalDir) { $installed[] = self::$installed; } return $installed;