diff --git a/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php b/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php index 77d382db378..37a7d1d6eb5 100644 --- a/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php +++ b/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php @@ -111,11 +111,11 @@ final class PHPStanNodeScopeResolver $this->removeDeepChainMethodCallNodes($stmts); $scope = $this->scopeFactory->createFromFile($smartFileInfo); // skip chain method calls, performance issue: https://github.com/phpstan/phpstan/issues/254 - $nodeCallback = function (\PhpParser\Node $node, \PHPStan\Analyser\MutatingScope $scope) use(&$nodeCallback) : void { + $nodeCallback = function (\PhpParser\Node $node, \PHPStan\Analyser\MutatingScope $mutatingScope) use(&$nodeCallback) : void { if ($node instanceof \PhpParser\Node\Stmt\Trait_) { $traitName = $this->resolveClassName($node); $traitReflectionClass = $this->reflectionProvider->getClass($traitName); - $traitScope = clone $scope; + $traitScope = clone $mutatingScope; $scopeContext = $this->privatesAccessor->getPrivatePropertyOfClass($traitScope, self::CONTEXT, \PHPStan\Analyser\ScopeContext::class); $traitContext = clone $scopeContext; $this->privatesAccessor->setPrivatePropertyOfClass($traitContext, 'classReflection', $traitReflectionClass, \PHPStan\Reflection\ClassReflection::class); @@ -126,16 +126,16 @@ final class PHPStanNodeScopeResolver // the class reflection is resolved AFTER entering to class node // so we need to get it from the first after this one if ($node instanceof \PhpParser\Node\Stmt\Class_ || $node instanceof \PhpParser\Node\Stmt\Interface_) { - /** @var MutatingScope $scope */ - $scope = $this->resolveClassOrInterfaceScope($node, $scope); + /** @var MutatingScope $mutatingScope */ + $mutatingScope = $this->resolveClassOrInterfaceScope($node, $mutatingScope); } // special case for unreachable nodes if ($node instanceof \PHPStan\Node\UnreachableStatementNode) { $originalNode = $node->getOriginalStatement(); $originalNode->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::IS_UNREACHABLE, \true); - $originalNode->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE, $scope); + $originalNode->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE, $mutatingScope); } else { - $node->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE, $scope); + $node->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE, $mutatingScope); } }; $this->decoratePHPStanNodeScopeResolverWithRenamedClassSourceLocator($this->nodeScopeResolver); diff --git a/packages/NodeTypeResolver/PhpDoc/NodeAnalyzer/DocBlockNamespaceRenamer.php b/packages/NodeTypeResolver/PhpDoc/NodeAnalyzer/DocBlockNamespaceRenamer.php index 7a2c9c2da4a..6014f30f5db 100644 --- a/packages/NodeTypeResolver/PhpDoc/NodeAnalyzer/DocBlockNamespaceRenamer.php +++ b/packages/NodeTypeResolver/PhpDoc/NodeAnalyzer/DocBlockNamespaceRenamer.php @@ -41,12 +41,12 @@ final class DocBlockNamespaceRenamer { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); $phpDocNodeTraverser = new \RectorPrefix20220410\Symplify\Astral\PhpDocParser\PhpDocNodeTraverser(); - $phpDocNodeTraverser->traverseWithCallable($phpDocInfo->getPhpDocNode(), '', function (\PHPStan\PhpDocParser\Ast\Node $subNode) use($oldToNewNamespaces) : ?DocNode { - if (!$subNode instanceof \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode) { + $phpDocNodeTraverser->traverseWithCallable($phpDocInfo->getPhpDocNode(), '', function (\PHPStan\PhpDocParser\Ast\Node $docNode) use($oldToNewNamespaces) : ?DocNode { + if (!$docNode instanceof \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode) { return null; } - $name = $subNode->name; - $trimmedName = \ltrim($subNode->name, '\\'); + $name = $docNode->name; + $trimmedName = \ltrim($docNode->name, '\\'); if ($name === $trimmedName) { return null; } diff --git a/packages/PostRector/Collector/NodesToRemoveCollector.php b/packages/PostRector/Collector/NodesToRemoveCollector.php index ff24391d5f8..e5ffd135b32 100644 --- a/packages/PostRector/Collector/NodesToRemoveCollector.php +++ b/packages/PostRector/Collector/NodesToRemoveCollector.php @@ -130,15 +130,15 @@ final class NodesToRemoveCollector implements \Rector\PostRector\Contract\Collec } $paramVariable = $node->var; if ($paramVariable instanceof \PhpParser\Node\Expr\Variable) { - return (bool) $this->betterNodeFinder->findFirst((array) $parentNode->stmts, function (\PhpParser\Node $variable) use($paramVariable) : bool { - if (!$this->nodeComparator->areNodesEqual($variable, $paramVariable)) { + return (bool) $this->betterNodeFinder->findFirst((array) $parentNode->stmts, function (\PhpParser\Node $node) use($paramVariable) : bool { + if (!$this->nodeComparator->areNodesEqual($node, $paramVariable)) { return \false; } - $hasArgParent = (bool) $this->betterNodeFinder->findParentType($variable, \PhpParser\Node\Arg::class); + $hasArgParent = (bool) $this->betterNodeFinder->findParentType($node, \PhpParser\Node\Arg::class); if (!$hasArgParent) { return \false; } - return !(bool) $this->betterNodeFinder->findParentType($variable, \PhpParser\Node\Expr\StaticCall::class); + return !(bool) $this->betterNodeFinder->findParentType($node, \PhpParser\Node\Expr\StaticCall::class); }); } return \false; diff --git a/rules/CodingStyle/Rector/Class_/AddArrayDefaultToArrayPropertyRector.php b/rules/CodingStyle/Rector/Class_/AddArrayDefaultToArrayPropertyRector.php index bcecd4562c5..9fd4678398f 100644 --- a/rules/CodingStyle/Rector/Class_/AddArrayDefaultToArrayPropertyRector.php +++ b/rules/CodingStyle/Rector/Class_/AddArrayDefaultToArrayPropertyRector.php @@ -132,15 +132,15 @@ CODE_SAMPLE */ private function completeDefaultArrayToPropertyNames(\PhpParser\Node\Stmt\Class_ $class, array $propertyNames) : void { - $this->traverseNodesWithCallable($class, function (\PhpParser\Node $class) use($propertyNames) : ?PropertyProperty { - if (!$class instanceof \PhpParser\Node\Stmt\PropertyProperty) { + $this->traverseNodesWithCallable($class, function (\PhpParser\Node $node) use($propertyNames) : ?PropertyProperty { + if (!$node instanceof \PhpParser\Node\Stmt\PropertyProperty) { return null; } - if (!$this->isNames($class, $propertyNames)) { + if (!$this->isNames($node, $propertyNames)) { return null; } - $class->default = new \PhpParser\Node\Expr\Array_(); - return $class; + $node->default = new \PhpParser\Node\Expr\Array_(); + return $node; }); } /** diff --git a/rules/Naming/Guard/BreakingVariableRenameGuard.php b/rules/Naming/Guard/BreakingVariableRenameGuard.php index 65ad4286c2d..23e476a58b0 100644 --- a/rules/Naming/Guard/BreakingVariableRenameGuard.php +++ b/rules/Naming/Guard/BreakingVariableRenameGuard.php @@ -102,7 +102,10 @@ final class BreakingVariableRenameGuard } return $this->isUsedInIfAndOtherBranches($variable, $currentName); } - public function shouldSkipParam(string $currentName, string $expectedName, \PhpParser\Node\Stmt\ClassMethod $classMethod, \PhpParser\Node\Param $param) : bool + /** + * @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $classMethod + */ + public function shouldSkipParam(string $currentName, string $expectedName, $classMethod, \PhpParser\Node\Param $param) : bool { // is the suffix? → also accepted $expectedNameCamelCase = \ucfirst($expectedName); @@ -116,7 +119,7 @@ final class BreakingVariableRenameGuard if ($this->conflictingNameResolver->hasNameIsInFunctionLike($expectedName, $classMethod)) { return \true; } - if ($this->overridenExistingNamesResolver->hasNameInClassMethodForParam($expectedName, $classMethod)) { + if ($this->overridenExistingNamesResolver->hasNameInFunctionLikeForParam($expectedName, $classMethod)) { return \true; } if ($this->isVariableAlreadyDefined($param->var, $currentName)) { diff --git a/rules/Naming/Naming/ConflictingNameResolver.php b/rules/Naming/Naming/ConflictingNameResolver.php index 02aac87ab9d..ac86216ef23 100644 --- a/rules/Naming/Naming/ConflictingNameResolver.php +++ b/rules/Naming/Naming/ConflictingNameResolver.php @@ -52,8 +52,9 @@ final class ConflictingNameResolver } /** * @return string[] + * @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $classMethod */ - public function resolveConflictingVariableNamesForParam(\PhpParser\Node\Stmt\ClassMethod $classMethod) : array + public function resolveConflictingVariableNamesForParam($classMethod) : array { $expectedNames = []; foreach ($classMethod->params as $param) { diff --git a/rules/Naming/Naming/OverridenExistingNamesResolver.php b/rules/Naming/Naming/OverridenExistingNamesResolver.php index ae72fb20841..65bd462909d 100644 --- a/rules/Naming/Naming/OverridenExistingNamesResolver.php +++ b/rules/Naming/Naming/OverridenExistingNamesResolver.php @@ -46,7 +46,10 @@ final class OverridenExistingNamesResolver $overridenVariableNames = $this->resolveOveriddenNamesForNew($functionLike); return \in_array($variableName, $overridenVariableNames, \true); } - public function hasNameInClassMethodForParam(string $expectedName, \PhpParser\Node\Stmt\ClassMethod $classMethod) : bool + /** + * @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $classMethod + */ + public function hasNameInFunctionLikeForParam(string $expectedName, $classMethod) : bool { /** @var Assign[] $assigns */ $assigns = $this->betterNodeFinder->findInstanceOf((array) $classMethod->stmts, \PhpParser\Node\Expr\Assign::class); diff --git a/rules/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector.php b/rules/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector.php index 0097263683d..94b17f84ee2 100644 --- a/rules/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector.php +++ b/rules/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector.php @@ -4,8 +4,10 @@ declare (strict_types=1); namespace Rector\Naming\Rector\ClassMethod; use PhpParser\Node; +use PhpParser\Node\Expr\Closure; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; +use PhpParser\Node\Stmt\Function_; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\MethodName; use Rector\Naming\ExpectedNameResolver\MatchParamTypeExpectedNameResolver; @@ -85,10 +87,10 @@ CODE_SAMPLE */ public function getNodeTypes() : array { - return [\PhpParser\Node\Stmt\ClassMethod::class]; + return [\PhpParser\Node\Stmt\ClassMethod::class, \PhpParser\Node\Stmt\Function_::class, \PhpParser\Node\Expr\Closure::class]; } /** - * @param ClassMethod $node + * @param ClassMethod|Function_|Closure $node */ public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node { @@ -117,13 +119,19 @@ CODE_SAMPLE } return $node; } - private function shouldSkipParam(\PhpParser\Node\Param $param, string $expectedName, \PhpParser\Node\Stmt\ClassMethod $classMethod) : bool + /** + * @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $classMethod + */ + private function shouldSkipParam(\PhpParser\Node\Param $param, string $expectedName, $classMethod) : bool { /** @var string $paramName */ $paramName = $this->getName($param); if ($this->breakingVariableRenameGuard->shouldSkipParam($paramName, $expectedName, $classMethod, $param)) { return \true; } + if (!$classMethod instanceof \PhpParser\Node\Stmt\ClassMethod) { + return \false; + } // promoted property if (!$this->isName($classMethod, \Rector\Core\ValueObject\MethodName::CONSTRUCT)) { return \false; diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index d6b137f2357..1c2627ce7e5 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -16,11 +16,11 @@ final class VersionResolver /** * @var string */ - public const PACKAGE_VERSION = '9b46906e39ded6bbf0a48d016f7b95ae1431ec29'; + public const PACKAGE_VERSION = '76894e5c63cc76303b71458121c12a5666204bff'; /** * @var string */ - public const RELEASE_DATE = '2022-04-10 13:01:19'; + public const RELEASE_DATE = '2022-04-10 10:22:55'; public static function resolvePackageVersion() : string { $process = new \RectorPrefix20220410\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__); diff --git a/src/NodeAnalyzer/VariableAnalyzer.php b/src/NodeAnalyzer/VariableAnalyzer.php index 9c02422822e..f99615fa652 100644 --- a/src/NodeAnalyzer/VariableAnalyzer.php +++ b/src/NodeAnalyzer/VariableAnalyzer.php @@ -34,15 +34,15 @@ final class VariableAnalyzer if ($this->isParentStaticOrGlobal($variable)) { return \true; } - return (bool) $this->betterNodeFinder->findFirstPreviousOfNode($variable, function (\PhpParser\Node $n) use($variable) : bool { - if (!\in_array(\get_class($n), [\PhpParser\Node\Stmt\Static_::class, \PhpParser\Node\Stmt\Global_::class], \true)) { + return (bool) $this->betterNodeFinder->findFirstPreviousOfNode($variable, function (\PhpParser\Node $node) use($variable) : bool { + if (!\in_array(\get_class($node), [\PhpParser\Node\Stmt\Static_::class, \PhpParser\Node\Stmt\Global_::class], \true)) { return \false; } /** - * @var Static_|Global_ $n + * @var Static_|Global_ $node * @var StaticVar[]|Variable[] $vars */ - $vars = $n->vars; + $vars = $node->vars; foreach ($vars as $var) { $staticVarVariable = $var instanceof \PhpParser\Node\Stmt\StaticVar ? $var->var : $var; if ($this->nodeComparator->areNodesEqual($staticVarVariable, $variable)) { diff --git a/vendor/autoload.php b/vendor/autoload.php index 29635b5da22..cc978108a13 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59::getLoader(); +return ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index a9c0a941c03..92f9f00067d 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59 +class ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3 { private static $loader; @@ -22,19 +22,19 @@ class ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit114027d2a257abb219ed67ae013d23a3::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $includeFiles = \Composer\Autoload\ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::$files; + $includeFiles = \Composer\Autoload\ComposerStaticInit114027d2a257abb219ed67ae013d23a3::$files; foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire77d63ece181c04c49904b82bbc0f8c59($fileIdentifier, $file); + composerRequire114027d2a257abb219ed67ae013d23a3($fileIdentifier, $file); } return $loader; @@ -46,7 +46,7 @@ class ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59 * @param string $file * @return void */ -function composerRequire77d63ece181c04c49904b82bbc0f8c59($fileIdentifier, $file) +function composerRequire114027d2a257abb219ed67ae013d23a3($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index dd83a1f3d0b..6bfe4230a99 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59 +class ComposerStaticInit114027d2a257abb219ed67ae013d23a3 { public static $files = array ( '320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php', @@ -3858,9 +3858,9 @@ class ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit114027d2a257abb219ed67ae013d23a3::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit114027d2a257abb219ed67ae013d23a3::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit114027d2a257abb219ed67ae013d23a3::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/scoper-autoload.php b/vendor/scoper-autoload.php index c879aca467a..e0394e9093c 100644 --- a/vendor/scoper-autoload.php +++ b/vendor/scoper-autoload.php @@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php'; if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) { spl_autoload_call('RectorPrefix20220410\AutoloadIncluder'); } -if (!class_exists('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', false) && !interface_exists('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', false) && !trait_exists('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', false)) { - spl_autoload_call('RectorPrefix20220410\ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59'); +if (!class_exists('ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3', false) && !interface_exists('ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3', false) && !trait_exists('ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3', false)) { + spl_autoload_call('RectorPrefix20220410\ComposerAutoloaderInit114027d2a257abb219ed67ae013d23a3'); } if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) { spl_autoload_call('RectorPrefix20220410\Helmich\TypoScriptParser\Parser\AST\Statement'); @@ -59,9 +59,9 @@ if (!function_exists('print_node')) { return \RectorPrefix20220410\print_node(...func_get_args()); } } -if (!function_exists('composerRequire77d63ece181c04c49904b82bbc0f8c59')) { - function composerRequire77d63ece181c04c49904b82bbc0f8c59() { - return \RectorPrefix20220410\composerRequire77d63ece181c04c49904b82bbc0f8c59(...func_get_args()); +if (!function_exists('composerRequire114027d2a257abb219ed67ae013d23a3')) { + function composerRequire114027d2a257abb219ed67ae013d23a3() { + return \RectorPrefix20220410\composerRequire114027d2a257abb219ed67ae013d23a3(...func_get_args()); } } if (!function_exists('scanPath')) {