diff --git a/packages/NodeNestingScope/ParentScopeFinder.php b/packages/NodeNestingScope/ParentScopeFinder.php index 68af3bd5e6ac..d1c1bbe7bdbe 100644 --- a/packages/NodeNestingScope/ParentScopeFinder.php +++ b/packages/NodeNestingScope/ParentScopeFinder.php @@ -21,9 +21,9 @@ public function __construct(\Rector\Core\PhpParser\Node\BetterNodeFinder $better $this->betterNodeFinder = $betterNodeFinder; } /** - * @return ClassMethod|Function_|Class_|Namespace_|Closure|null + * @return \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Namespace_|\PhpParser\Node\Expr\Closure|null */ - public function find(\PhpParser\Node $node) : ?\PhpParser\Node + public function find(\PhpParser\Node $node) { return $this->betterNodeFinder->findParentTypes($node, [\PhpParser\Node\Expr\Closure::class, \PhpParser\Node\Stmt\Function_::class, \PhpParser\Node\Stmt\ClassMethod::class, \PhpParser\Node\Stmt\Class_::class, \PhpParser\Node\Stmt\Namespace_::class]); } diff --git a/packages/NodeRemoval/NodeRemover.php b/packages/NodeRemoval/NodeRemover.php index c893176dc09e..05f3eb3a3fe8 100644 --- a/packages/NodeRemoval/NodeRemover.php +++ b/packages/NodeRemoval/NodeRemover.php @@ -65,16 +65,16 @@ public function removeNodes(array $nodes) : void } } /** - * @param Closure|ClassMethod|Function_ $node + * @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike */ - public function removeStmt(\PhpParser\Node $node, int $key) : void + public function removeStmt($functionLike, int $key) : void { - if ($node->stmts === null) { + if ($functionLike->stmts === null) { throw new \Rector\Core\Exception\ShouldNotHappenException(); } // notify about remove node - $this->rectorChangeCollector->notifyNodeFileInfo($node->stmts[$key]); - unset($node->stmts[$key]); + $this->rectorChangeCollector->notifyNodeFileInfo($functionLike->stmts[$key]); + unset($functionLike->stmts[$key]); } /** * @param int|\PhpParser\Node\Param $keyOrParam diff --git a/rules/Arguments/ArgumentDefaultValueReplacer.php b/rules/Arguments/ArgumentDefaultValueReplacer.php index ceace824dc61..f533fbaac9f5 100644 --- a/rules/Arguments/ArgumentDefaultValueReplacer.php +++ b/rules/Arguments/ArgumentDefaultValueReplacer.php @@ -30,9 +30,9 @@ public function __construct(\Rector\Core\PhpParser\Node\NodeFactory $nodeFactory $this->valueResolver = $valueResolver; } /** - * @param MethodCall|StaticCall|ClassMethod|Expr\FuncCall $node + * @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\FuncCall $node */ - public function processReplaces(\PhpParser\Node $node, \Rector\Arguments\Contract\ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue) : ?\PhpParser\Node + public function processReplaces($node, \Rector\Arguments\Contract\ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue) : ?\PhpParser\Node { if ($node instanceof \PhpParser\Node\Stmt\ClassMethod) { if (!isset($node->params[$replaceArgumentDefaultValue->getPosition()])) { diff --git a/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php b/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php index ab855af1eba6..e891907fe8f9 100644 --- a/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php +++ b/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php @@ -151,9 +151,9 @@ private function processPositionWithDefaultValues($node, \Rector\Arguments\Value } } /** - * @param ClassMethod|MethodCall|StaticCall $node + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node */ - private function shouldSkipParameter(\PhpParser\Node $node, \Rector\Arguments\ValueObject\ArgumentAdder $argumentAdder) : bool + private function shouldSkipParameter($node, \Rector\Arguments\ValueObject\ArgumentAdder $argumentAdder) : bool { $position = $argumentAdder->getPosition(); $argumentName = $argumentAdder->getArgumentName(); diff --git a/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php b/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php index fdfac86fb783..e976a9de1371 100644 --- a/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php +++ b/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php @@ -7,7 +7,6 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\FunctionLike; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; @@ -73,9 +72,9 @@ public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node return $node; } /** - * @param ClassMethod|Function_ $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike */ - private function matchFuncGetArgsVariableAssign(\PhpParser\Node\FunctionLike $functionLike) : ?\PhpParser\Node\Expr\Assign + private function matchFuncGetArgsVariableAssign($functionLike) : ?\PhpParser\Node\Expr\Assign { /** @var Assign[] $assigns */ $assigns = $this->betterNodeFinder->findInstanceOf((array) $functionLike->stmts, \PhpParser\Node\Expr\Assign::class); diff --git a/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php b/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php index 70864758afbb..93121da608f6 100644 --- a/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php +++ b/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php @@ -110,9 +110,9 @@ private function resolveCurrentStmtVariableName(\PhpParser\Node\Stmt $stmt) : ?s return null; } /** - * @param ClassMethod|Function_|Closure $node + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node */ - private function shouldAddEmptyLine(?string $currentStmtVariableName, \PhpParser\Node $node, int $key) : bool + private function shouldAddEmptyLine(?string $currentStmtVariableName, $node, int $key) : bool { if (!$this->isNewVariableThanBefore($currentStmtVariableName)) { return \false; @@ -148,9 +148,9 @@ private function isNewVariableThanBefore(?string $currentStmtVariableName) : boo return $this->previousStmtVariableName !== $currentStmtVariableName; } /** - * @param ClassMethod|Function_|Closure $node + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node */ - private function isPrecededByEmptyLine(\PhpParser\Node $node, int $key) : bool + private function isPrecededByEmptyLine($node, int $key) : bool { if ($node->stmts === null) { return \false; diff --git a/rules/DowngradePhp71/Rector/FunctionLike/DowngradeNullableTypeDeclarationRector.php b/rules/DowngradePhp71/Rector/FunctionLike/DowngradeNullableTypeDeclarationRector.php index bed976a53b3a..0c1d8fb21106 100644 --- a/rules/DowngradePhp71/Rector/FunctionLike/DowngradeNullableTypeDeclarationRector.php +++ b/rules/DowngradePhp71/Rector/FunctionLike/DowngradeNullableTypeDeclarationRector.php @@ -5,7 +5,6 @@ use PhpParser\Node; use PhpParser\Node\Expr\Closure; -use PhpParser\Node\FunctionLike; use PhpParser\Node\NullableType; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; @@ -96,9 +95,9 @@ private function isNullableParam(\PhpParser\Node\Param $param) : bool return $param->type instanceof \PhpParser\Node\NullableType; } /** - * @param ClassMethod|Function_|Closure $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - private function refactorParamType(\PhpParser\Node\Param $param, \PhpParser\Node\FunctionLike $functionLike) : bool + private function refactorParamType(\PhpParser\Node\Param $param, $functionLike) : bool { if (!$this->isNullableParam($param)) { return \false; @@ -108,9 +107,9 @@ private function refactorParamType(\PhpParser\Node\Param $param, \PhpParser\Node return \true; } /** - * @param ClassMethod|Function_|Closure $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - private function decorateWithDocBlock(\PhpParser\Node\FunctionLike $functionLike, \PhpParser\Node\Param $param) : void + private function decorateWithDocBlock($functionLike, \PhpParser\Node\Param $param) : void { if ($param->type === null) { return; diff --git a/rules/DowngradePhp71/TypeDeclaration/PhpDocFromTypeDeclarationDecorator.php b/rules/DowngradePhp71/TypeDeclaration/PhpDocFromTypeDeclarationDecorator.php index 60c5729ac344..739d38b035e5 100644 --- a/rules/DowngradePhp71/TypeDeclaration/PhpDocFromTypeDeclarationDecorator.php +++ b/rules/DowngradePhp71/TypeDeclaration/PhpDocFromTypeDeclarationDecorator.php @@ -5,7 +5,6 @@ use PhpParser\Node; use PhpParser\Node\Expr\Closure; -use PhpParser\Node\FunctionLike; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; @@ -47,10 +46,10 @@ public function __construct(\Rector\StaticTypeMapper\StaticTypeMapper $staticTyp $this->typeUnwrapper = $typeUnwrapper; } /** - * @param ClassMethod|Function_|Closure $functionLike * @return bool True if node was changed + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - public function decorate(\PhpParser\Node\FunctionLike $functionLike) : bool + public function decorate($functionLike) : bool { if ($functionLike->returnType === null) { return \false; @@ -62,10 +61,10 @@ public function decorate(\PhpParser\Node\FunctionLike $functionLike) : bool return \true; } /** - * @param ClassMethod|Function_ $functionLike * @param array> $requiredTypes + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - public function decorateParam(\PhpParser\Node\Param $param, \PhpParser\Node\FunctionLike $functionLike, array $requiredTypes) : void + public function decorateParam(\PhpParser\Node\Param $param, $functionLike, array $requiredTypes) : void { if ($param->type === null) { return; @@ -77,9 +76,9 @@ public function decorateParam(\PhpParser\Node\Param $param, \PhpParser\Node\Func $this->moveParamTypeToParamDoc($functionLike, $param, $type); } /** - * @param ClassMethod|Function_ $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - public function decorateParamWithSpecificType(\PhpParser\Node\Param $param, \PhpParser\Node\FunctionLike $functionLike, \PHPStan\Type\Type $requireType) : void + public function decorateParamWithSpecificType(\PhpParser\Node\Param $param, $functionLike, \PHPStan\Type\Type $requireType) : void { if ($param->type === null) { return; @@ -91,10 +90,10 @@ public function decorateParamWithSpecificType(\PhpParser\Node\Param $param, \Php $this->moveParamTypeToParamDoc($functionLike, $param, $type); } /** - * @param ClassMethod|Function_|Closure $functionLike * @return bool True if node was changed + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - public function decorateReturnWithSpecificType(\PhpParser\Node\FunctionLike $functionLike, \PHPStan\Type\Type $requireType) : bool + public function decorateReturnWithSpecificType($functionLike, \PHPStan\Type\Type $requireType) : bool { if ($functionLike->returnType === null) { return \false; @@ -114,9 +113,9 @@ private function isTypeMatchOrSubType(\PhpParser\Node $typeNode, \PHPStan\Type\T return \is_a($returnType, \get_class($requireType), \true); } /** - * @param ClassMethod|Function_ $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - private function moveParamTypeToParamDoc(\PhpParser\Node\FunctionLike $functionLike, \PhpParser\Node\Param $param, \PHPStan\Type\Type $type) : void + private function moveParamTypeToParamDoc($functionLike, \PhpParser\Node\Param $param, \PHPStan\Type\Type $type) : void { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike); $paramName = $this->nodeNameResolver->getName($param); diff --git a/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php b/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php index 0cc184bc3676..d115854483a2 100644 --- a/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php +++ b/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php @@ -189,9 +189,9 @@ private function getDifferentParamTypeFromReflectionMethod(\ReflectionMethod $re return null; } /** - * @param ClassMethod|Function_ $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike */ - private function refactorParam(\PhpParser\Node\Param $param, \PhpParser\Node\FunctionLike $functionLike) : void + private function refactorParam(\PhpParser\Node\Param $param, $functionLike) : void { if (!$this->isNullableParam($param, $functionLike)) { return; @@ -200,9 +200,9 @@ private function refactorParam(\PhpParser\Node\Param $param, \PhpParser\Node\Fun $param->type = null; } /** - * @param ClassMethod|Function_ $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike */ - private function decorateWithDocBlock(\PhpParser\Node\FunctionLike $functionLike, \PhpParser\Node\Param $param) : void + private function decorateWithDocBlock($functionLike, \PhpParser\Node\Param $param) : void { if ($param->type === null) { return; diff --git a/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php b/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php index 263aa08cc1f8..8e76c3916d52 100644 --- a/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php +++ b/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php @@ -110,9 +110,9 @@ private function processUses(\PhpParser\Node\Expr\Closure $node) : void $this->cleanTrailingComma($node, $node->uses); } /** - * @param ClassMethod|Function_|Closure $node + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node */ - private function processParams(\PhpParser\Node $node) : ?\PhpParser\Node + private function processParams($node) : ?\PhpParser\Node { if ($node->params === []) { return null; diff --git a/rules/Naming/Guard/BreakingVariableRenameGuard.php b/rules/Naming/Guard/BreakingVariableRenameGuard.php index f47ad32f4b95..3b0c17ccf030 100644 --- a/rules/Naming/Guard/BreakingVariableRenameGuard.php +++ b/rules/Naming/Guard/BreakingVariableRenameGuard.php @@ -8,7 +8,6 @@ use PhpParser\Node; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\FunctionLike; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Foreach_; @@ -68,9 +67,9 @@ public function __construct(\Rector\Core\PhpParser\Node\BetterNodeFinder $better $this->nodeNameResolver = $nodeNameResolver; } /** - * @param ClassMethod|Function_|Closure $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - public function shouldSkipVariable(string $currentName, string $expectedName, \PhpParser\Node\FunctionLike $functionLike, \PhpParser\Node\Expr\Variable $variable) : bool + public function shouldSkipVariable(string $currentName, string $expectedName, $functionLike, \PhpParser\Node\Expr\Variable $variable) : bool { // is the suffix? → also accepted $expectedNameCamelCase = \ucfirst($expectedName); @@ -143,16 +142,16 @@ private function isVariableAlreadyDefined(\PhpParser\Node\Expr\Variable $variabl return $trinaryLogic->maybe(); } /** - * @param ClassMethod|Function_|Closure $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - private function skipOnConflictOtherVariable(\PhpParser\Node\FunctionLike $functionLike, string $newName) : bool + private function skipOnConflictOtherVariable($functionLike, string $newName) : bool { return $this->betterNodeFinder->hasInstanceOfName((array) $functionLike->stmts, \PhpParser\Node\Expr\Variable::class, $newName); } /** - * @param ClassMethod|Function_|Closure $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - private function isUsedInClosureUsesName(string $expectedName, \PhpParser\Node\FunctionLike $functionLike) : bool + private function isUsedInClosureUsesName(string $expectedName, $functionLike) : bool { if (!$functionLike instanceof \PhpParser\Node\Expr\Closure) { return \false; diff --git a/rules/Naming/Matcher/ForeachMatcher.php b/rules/Naming/Matcher/ForeachMatcher.php index 973a50031552..fd73506f8159 100644 --- a/rules/Naming/Matcher/ForeachMatcher.php +++ b/rules/Naming/Matcher/ForeachMatcher.php @@ -3,7 +3,6 @@ declare (strict_types=1); namespace Rector\Naming\Matcher; -use PhpParser\Node; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\ClassMethod; @@ -52,9 +51,9 @@ public function match(\PhpParser\Node\Stmt\Foreach_ $foreach) : ?\Rector\Naming\ return new \Rector\Naming\ValueObject\VariableAndCallForeach($foreach->valueVar, $call, $variableName, $functionLike); } /** - * @return ClassMethod|Function_|Closure|null + * @return \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|null */ - private function getFunctionLike(\PhpParser\Node\Stmt\Foreach_ $foreach) : ?\PhpParser\Node + private function getFunctionLike(\PhpParser\Node\Stmt\Foreach_ $foreach) { return $this->betterNodeFinder->findParentTypes($foreach, [\PhpParser\Node\Expr\Closure::class, \PhpParser\Node\Stmt\ClassMethod::class, \PhpParser\Node\Stmt\Function_::class]); } diff --git a/rules/Naming/Matcher/VariableAndCallAssignMatcher.php b/rules/Naming/Matcher/VariableAndCallAssignMatcher.php index e04d58d683c2..a421284fb0ed 100644 --- a/rules/Naming/Matcher/VariableAndCallAssignMatcher.php +++ b/rules/Naming/Matcher/VariableAndCallAssignMatcher.php @@ -3,7 +3,6 @@ declare (strict_types=1); namespace Rector\Naming\Matcher; -use PhpParser\Node; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; @@ -53,9 +52,9 @@ public function match(\PhpParser\Node\Expr\Assign $assign) : ?\Rector\Naming\Val return new \Rector\Naming\ValueObject\VariableAndCallAssign($assign->var, $call, $assign, $variableName, $functionLike); } /** - * @return ClassMethod|Function_|Closure|null + * @return \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|null */ - private function getFunctionLike(\PhpParser\Node\Expr\Assign $assign) : ?\PhpParser\Node + private function getFunctionLike(\PhpParser\Node\Expr\Assign $assign) { return $this->betterNodeFinder->findParentTypes($assign, [\PhpParser\Node\Expr\Closure::class, \PhpParser\Node\Stmt\ClassMethod::class, \PhpParser\Node\Stmt\Function_::class]); } diff --git a/rules/Naming/Naming/ConflictingNameResolver.php b/rules/Naming/Naming/ConflictingNameResolver.php index 249b2efc687e..636a32a4df16 100644 --- a/rules/Naming/Naming/ConflictingNameResolver.php +++ b/rules/Naming/Naming/ConflictingNameResolver.php @@ -5,7 +5,6 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Closure; -use PhpParser\Node\FunctionLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; use Rector\Core\PhpParser\Node\BetterNodeFinder; @@ -62,18 +61,18 @@ public function resolveConflictingVariableNamesForParam(\PhpParser\Node\Stmt\Cla return $this->arrayFilter->filterWithAtLeastTwoOccurences($expectedNames); } /** - * @param ClassMethod|Function_|Closure $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - public function checkNameIsInFunctionLike(string $variableName, \PhpParser\Node\FunctionLike $functionLike) : bool + public function checkNameIsInFunctionLike(string $variableName, $functionLike) : bool { $conflictingVariableNames = $this->resolveConflictingVariableNamesForNew($functionLike); return \in_array($variableName, $conflictingVariableNames, \true); } /** - * @param ClassMethod|Function_|Closure $functionLike * @return string[] + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - private function resolveConflictingVariableNamesForNew(\PhpParser\Node\FunctionLike $functionLike) : array + private function resolveConflictingVariableNamesForNew($functionLike) : array { // cache it! $classMethodHash = \spl_object_hash($functionLike); @@ -89,10 +88,10 @@ private function resolveConflictingVariableNamesForNew(\PhpParser\Node\FunctionL return $protectedNames; } /** - * @param ClassMethod|Function_|Closure $functionLike * @return string[] + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - private function collectParamNames(\PhpParser\Node\FunctionLike $functionLike) : array + private function collectParamNames($functionLike) : array { $paramNames = []; // params @@ -102,10 +101,10 @@ private function collectParamNames(\PhpParser\Node\FunctionLike $functionLike) : return $paramNames; } /** - * @param ClassMethod|Function_|Closure $functionLike * @return string[] + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - private function resolveForNewAssigns(\PhpParser\Node\FunctionLike $functionLike) : array + private function resolveForNewAssigns($functionLike) : array { $names = []; /** @var Assign[] $assigns */ @@ -120,10 +119,10 @@ private function resolveForNewAssigns(\PhpParser\Node\FunctionLike $functionLike return $names; } /** - * @param ClassMethod|Function_|Closure $functionLike * @return string[] + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - private function resolveForNonNewAssigns(\PhpParser\Node\FunctionLike $functionLike) : array + private function resolveForNonNewAssigns($functionLike) : array { $names = []; /** @var Assign[] $assigns */ diff --git a/rules/Naming/Naming/OverridenExistingNamesResolver.php b/rules/Naming/Naming/OverridenExistingNamesResolver.php index f7ab752866ad..f0d6438f1994 100644 --- a/rules/Naming/Naming/OverridenExistingNamesResolver.php +++ b/rules/Naming/Naming/OverridenExistingNamesResolver.php @@ -6,7 +6,6 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\FunctionLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; use Rector\Core\PhpParser\Node\BetterNodeFinder; @@ -37,9 +36,9 @@ public function __construct(\Rector\Naming\PhpArray\ArrayFilter $arrayFilter, \R $this->nodeNameResolver = $nodeNameResolver; } /** - * @param ClassMethod|Function_|Closure $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - public function checkNameInClassMethodForNew(string $variableName, \PhpParser\Node\FunctionLike $functionLike) : bool + public function checkNameInClassMethodForNew(string $variableName, $functionLike) : bool { $overridenVariableNames = $this->resolveOveriddenNamesForNew($functionLike); return \in_array($variableName, $overridenVariableNames, \true); @@ -62,10 +61,10 @@ public function checkNameInClassMethodForParam(string $expectedName, \PhpParser\ return \in_array($expectedName, $usedVariableNames, \true); } /** - * @param ClassMethod|Function_|Closure $functionLike * @return string[] + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - private function resolveOveriddenNamesForNew(\PhpParser\Node\FunctionLike $functionLike) : array + private function resolveOveriddenNamesForNew($functionLike) : array { $classMethodHash = \spl_object_hash($functionLike); if (isset($this->overridenExistingVariableNamesByClassMethod[$classMethodHash])) { diff --git a/rules/Naming/ValueObject/ParamRename.php b/rules/Naming/ValueObject/ParamRename.php index d06f1f8fdb63..de0dd2326ff9 100644 --- a/rules/Naming/ValueObject/ParamRename.php +++ b/rules/Naming/ValueObject/ParamRename.php @@ -5,7 +5,6 @@ use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\FunctionLike; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; @@ -29,13 +28,13 @@ final class ParamRename implements \Rector\Naming\Contract\RenameParamValueObjec */ private $variable; /** - * @var \PhpParser\Node\FunctionLike + * @var \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure */ private $functionLike; /** - * @param ClassMethod|Function_|Closure $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - public function __construct(string $currentName, string $expectedName, \PhpParser\Node\Param $param, \PhpParser\Node\Expr\Variable $variable, \PhpParser\Node\FunctionLike $functionLike) + public function __construct(string $currentName, string $expectedName, \PhpParser\Node\Param $param, \PhpParser\Node\Expr\Variable $variable, $functionLike) { $this->currentName = $currentName; $this->expectedName = $expectedName; @@ -52,9 +51,9 @@ public function getExpectedName() : string return $this->expectedName; } /** - * @return ClassMethod|Function_|Closure + * @return \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure */ - public function getFunctionLike() : \PhpParser\Node\FunctionLike + public function getFunctionLike() { return $this->functionLike; } diff --git a/rules/Naming/ValueObject/VariableAndCallAssign.php b/rules/Naming/ValueObject/VariableAndCallAssign.php index 8aa7dcf94a35..3980420ba0f9 100644 --- a/rules/Naming/ValueObject/VariableAndCallAssign.php +++ b/rules/Naming/ValueObject/VariableAndCallAssign.php @@ -3,14 +3,12 @@ declare (strict_types=1); namespace Rector\Naming\ValueObject; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\FunctionLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; final class VariableAndCallAssign @@ -20,7 +18,7 @@ final class VariableAndCallAssign */ private $variable; /** - * @var \PhpParser\Node\Expr + * @var \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall */ private $expr; /** @@ -32,14 +30,14 @@ final class VariableAndCallAssign */ private $variableName; /** - * @var \PhpParser\Node\FunctionLike + * @var \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure */ private $functionLike; /** - * @param FuncCall|StaticCall|MethodCall $expr - * @param ClassMethod|Function_|Closure $functionLike + * @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall $expr + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - public function __construct(\PhpParser\Node\Expr\Variable $variable, \PhpParser\Node\Expr $expr, \PhpParser\Node\Expr\Assign $assign, string $variableName, \PhpParser\Node\FunctionLike $functionLike) + public function __construct(\PhpParser\Node\Expr\Variable $variable, $expr, \PhpParser\Node\Expr\Assign $assign, string $variableName, $functionLike) { $this->variable = $variable; $this->expr = $expr; diff --git a/rules/Naming/ValueObject/VariableAndCallForeach.php b/rules/Naming/ValueObject/VariableAndCallForeach.php index 5c3f5b31e37c..48091f4f9878 100644 --- a/rules/Naming/ValueObject/VariableAndCallForeach.php +++ b/rules/Naming/ValueObject/VariableAndCallForeach.php @@ -3,13 +3,11 @@ declare (strict_types=1); namespace Rector\Naming\ValueObject; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\FunctionLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; final class VariableAndCallForeach @@ -19,7 +17,7 @@ final class VariableAndCallForeach */ private $variable; /** - * @var \PhpParser\Node\Expr + * @var \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall */ private $expr; /** @@ -27,14 +25,14 @@ final class VariableAndCallForeach */ private $variableName; /** - * @var \PhpParser\Node\FunctionLike + * @var \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure */ private $functionLike; /** - * @param FuncCall|StaticCall|MethodCall $expr - * @param ClassMethod|Function_|Closure $functionLike + * @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall $expr + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - public function __construct(\PhpParser\Node\Expr\Variable $variable, \PhpParser\Node\Expr $expr, string $variableName, \PhpParser\Node\FunctionLike $functionLike) + public function __construct(\PhpParser\Node\Expr\Variable $variable, $expr, string $variableName, $functionLike) { $this->variable = $variable; $this->expr = $expr; diff --git a/rules/Naming/VariableRenamer.php b/rules/Naming/VariableRenamer.php index a30cd26b12a2..60fc216abf25 100644 --- a/rules/Naming/VariableRenamer.php +++ b/rules/Naming/VariableRenamer.php @@ -7,7 +7,6 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\FunctionLike; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; @@ -49,9 +48,9 @@ public function __construct(\RectorPrefix20210629\Symplify\Astral\NodeTraverser\ $this->betterNodeFinder = $betterNodeFinder; } /** - * @param ClassMethod|Function_|Closure $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - public function renameVariableInFunctionLike(\PhpParser\Node\FunctionLike $functionLike, string $oldName, string $expectedName, ?\PhpParser\Node\Expr\Assign $assign = null) : void + public function renameVariableInFunctionLike($functionLike, string $oldName, string $expectedName, ?\PhpParser\Node\Expr\Assign $assign = null) : void { $isRenamingActive = \false; if ($assign === null) { diff --git a/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php b/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php index 5c9a82a93f14..5199f74167da 100644 --- a/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php +++ b/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php @@ -99,10 +99,10 @@ public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node return $node; } /** - * @param ClassMethod|Function_|Closure $node * @return string[] + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node */ - private function collectUndefinedVariableScope(\PhpParser\Node $node) : array + private function collectUndefinedVariableScope($node) : array { $undefinedVariables = []; $this->traverseNodesWithCallable((array) $node->stmts, function (\PhpParser\Node $node) use(&$undefinedVariables) : ?int { diff --git a/rules/Php70/Rector/Ternary/TernaryToSpaceshipRector.php b/rules/Php70/Rector/Ternary/TernaryToSpaceshipRector.php index c6c96d2991eb..4a739c3ca167 100644 --- a/rules/Php70/Rector/Ternary/TernaryToSpaceshipRector.php +++ b/rules/Php70/Rector/Ternary/TernaryToSpaceshipRector.php @@ -89,7 +89,7 @@ private function processSmallerThanTernary(\PhpParser\Node\Expr\Ternary $node, \ if (!$nestedTernary->cond instanceof \PhpParser\Node\Expr\BinaryOp\Greater) { return null; } - if (!$this->valueResolver->areValues([$node->if, $nestedTernary->if, $nestedTernary->else], [-1, 1, 0])) { + if (!$this->valueResolver->areValuesEqual([$node->if, $nestedTernary->if, $nestedTernary->else], [-1, 1, 0])) { return null; } return new \PhpParser\Node\Expr\BinaryOp\Spaceship($node->cond->left, $node->cond->right); @@ -105,7 +105,7 @@ private function processGreaterThanTernary(\PhpParser\Node\Expr\Ternary $node, \ if (!$nestedTernary->cond instanceof \PhpParser\Node\Expr\BinaryOp\Smaller) { return null; } - if (!$this->valueResolver->areValues([$node->if, $nestedTernary->if, $nestedTernary->else], [-1, 1, 0])) { + if (!$this->valueResolver->areValuesEqual([$node->if, $nestedTernary->if, $nestedTernary->else], [-1, 1, 0])) { return null; } return new \PhpParser\Node\Expr\BinaryOp\Spaceship($node->cond->right, $node->cond->left); diff --git a/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php b/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php index 5ff9462b2c5d..26be6ed8deaf 100644 --- a/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php +++ b/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php @@ -117,9 +117,9 @@ public function configure(array $configuration) : void } /** * @param array $tags - * @param Class_|Property|ClassMethod|Function_|Closure|ArrowFunction $node + * @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $node */ - private function processApplyAttrGroups(array $tags, \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo $phpDocInfo, \PhpParser\Node $node) : bool + private function processApplyAttrGroups(array $tags, \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo $phpDocInfo, $node) : bool { $hasNewAttrGroups = \false; foreach ($tags as $tag) { diff --git a/rules/Php80/Rector/FuncCall/TokenGetAllToObjectRector.php b/rules/Php80/Rector/FuncCall/TokenGetAllToObjectRector.php index 8d83129215af..a46de29a372a 100644 --- a/rules/Php80/Rector/FuncCall/TokenGetAllToObjectRector.php +++ b/rules/Php80/Rector/FuncCall/TokenGetAllToObjectRector.php @@ -8,7 +8,6 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\FunctionLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Foreach_; use PhpParser\Node\Stmt\Function_; @@ -101,9 +100,9 @@ private function refactorTokensVariable(\PhpParser\Node\Expr\FuncCall $funcCall) $this->replaceGetNameOrGetValue($classMethodOrFunction, $assign->var); } /** - * @param ClassMethod|Function_ $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike */ - private function replaceGetNameOrGetValue(\PhpParser\Node\FunctionLike $functionLike, \PhpParser\Node\Expr $assignedExpr) : void + private function replaceGetNameOrGetValue($functionLike, \PhpParser\Node\Expr $assignedExpr) : void { $tokensForeaches = $this->findForeachesOverTokenVariable($functionLike, $assignedExpr); foreach ($tokensForeaches as $tokenForeach) { @@ -111,10 +110,10 @@ private function replaceGetNameOrGetValue(\PhpParser\Node\FunctionLike $function } } /** - * @param ClassMethod|Function_ $functionLike * @return Foreach_[] + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike */ - private function findForeachesOverTokenVariable(\PhpParser\Node\FunctionLike $functionLike, \PhpParser\Node\Expr $assignedExpr) : array + private function findForeachesOverTokenVariable($functionLike, \PhpParser\Node\Expr $assignedExpr) : array { return $this->betterNodeFinder->find((array) $functionLike->stmts, function (\PhpParser\Node $node) use($assignedExpr) : bool { if (!$node instanceof \PhpParser\Node\Stmt\Foreach_) { diff --git a/rules/Php80/Rector/FunctionLike/UnionTypesRector.php b/rules/Php80/Rector/FunctionLike/UnionTypesRector.php index 05f3e5ddec8b..434420ce6e53 100644 --- a/rules/Php80/Rector/FunctionLike/UnionTypesRector.php +++ b/rules/Php80/Rector/FunctionLike/UnionTypesRector.php @@ -6,7 +6,6 @@ use PhpParser\Node; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Closure; -use PhpParser\Node\FunctionLike; use PhpParser\Node\Name; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; @@ -90,7 +89,7 @@ public function getNodeTypes() : array return [\PhpParser\Node\Stmt\ClassMethod::class, \PhpParser\Node\Stmt\Function_::class, \PhpParser\Node\Expr\Closure::class, \PhpParser\Node\Expr\ArrowFunction::class]; } /** - * @param ClassMethod|Function_|Closure|ArrowFunction $node + * @param ClassMethod | Function_ | Closure | ArrowFunction $node */ public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node { @@ -105,9 +104,9 @@ public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node return $node; } /** - * @param ClassMethod|Function_|Closure|ArrowFunction $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $functionLike */ - private function refactorParamTypes(\PhpParser\Node\FunctionLike $functionLike, \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo $phpDocInfo) : void + private function refactorParamTypes($functionLike, \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo $phpDocInfo) : void { if ($functionLike instanceof \PhpParser\Node\Stmt\ClassMethod && $this->classMethodParamVendorLockResolver->isVendorLocked($functionLike)) { return; @@ -145,9 +144,9 @@ private function changeObjectWithoutClassType(\PhpParser\Node\Param $param, \PHP $param->type = new \PhpParser\Node\Name('object'); } /** - * @param ClassMethod|Function_|Closure|ArrowFunction $functionLike + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $functionLike */ - private function refactorReturnType(\PhpParser\Node\FunctionLike $functionLike, \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo $phpDocInfo) : void + private function refactorReturnType($functionLike, \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo $phpDocInfo) : void { // do not override existing return type if ($functionLike->getReturnType() !== null) { diff --git a/rules/Privatization/NodeManipulator/VisibilityManipulator.php b/rules/Privatization/NodeManipulator/VisibilityManipulator.php index b82b3431c03e..240cfffcd936 100644 --- a/rules/Privatization/NodeManipulator/VisibilityManipulator.php +++ b/rules/Privatization/NodeManipulator/VisibilityManipulator.php @@ -19,23 +19,23 @@ final class VisibilityManipulator */ private const ALLOWED_NODE_TYPES = [\PhpParser\Node\Stmt\ClassMethod::class, \PhpParser\Node\Stmt\Property::class, \PhpParser\Node\Stmt\ClassConst::class, \PhpParser\Node\Stmt\Class_::class]; /** - * @param ClassMethod|Property|ClassConst $node + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassConst $node */ - public function makeStatic(\PhpParser\Node $node) : void + public function makeStatic($node) : void { $this->addVisibilityFlag($node, \Rector\Core\ValueObject\Visibility::STATIC); } /** - * @param ClassMethod|Class_ $node + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Class_ $node */ - public function makeAbstract(\PhpParser\Node $node) : void + public function makeAbstract($node) : void { $this->addVisibilityFlag($node, \Rector\Core\ValueObject\Visibility::ABSTRACT); } /** - * @param ClassMethod|Property $node + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Property $node */ - public function makeNonStatic(\PhpParser\Node $node) : void + public function makeNonStatic($node) : void { if (!$node->isStatic()) { return; diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector.php index 71accb655164..ba0f99482a37 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector.php @@ -91,7 +91,7 @@ public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node return $node; } /** - * @param ClassMethod|Function_ $node + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $node */ private function shouldSkip($node) : bool { @@ -99,7 +99,7 @@ private function shouldSkip($node) : bool if ($returns !== []) { return \true; } - $notNeverNodes = $this->betterNodeFinder->findInstancesOf($node, [\PhpParser\Node\Expr\Yield_::class]); + $notNeverNodes = $this->betterNodeFinder->findInstanceOf($node, \PhpParser\Node\Expr\Yield_::class); if ($notNeverNodes !== []) { return \true; } @@ -111,10 +111,7 @@ private function shouldSkip($node) : bool if ($node instanceof \PhpParser\Node\Stmt\ClassMethod && !$this->parentClassMethodTypeOverrideGuard->isReturnTypeChangeAllowed($node)) { return \true; } - if ($node->returnType && $this->isName($node->returnType, 'never')) { - return \true; - } - return \false; + return $node->returnType && $this->isName($node->returnType, 'never'); } /** * @param ClassMethod|Function_ $functionLike diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 24dcbbb56e7d..dcc02b6bc888 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -16,11 +16,11 @@ final class VersionResolver /** * @var string */ - public const PACKAGE_VERSION = '75c77576a52135a93112c042bfd070264a894a52'; + public const PACKAGE_VERSION = '2a394c750f518a33d56a0aa80fa2addf6ff1c140'; /** * @var string */ - public const RELEASE_DATE = '2021-06-29 14:23:35'; + public const RELEASE_DATE = '2021-06-29 15:25:57'; public static function resolvePackageVersion() : string { $process = new \RectorPrefix20210629\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__); diff --git a/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php b/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php index d3ec985a328e..7d39da3893ac 100644 --- a/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php +++ b/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php @@ -3,7 +3,7 @@ declare (strict_types=1); namespace Rector\Core\Contract\PHPStan\Reflection\TypeToCallReflectionResolver; -use PHPStan\Reflection\ClassMemberAccessAnswerer; +use PHPStan\Analyser\Scope; use PHPStan\Reflection\FunctionReflection; use PHPStan\Reflection\MethodReflection; use PHPStan\Type\Type; @@ -13,5 +13,5 @@ public function supports(\PHPStan\Type\Type $type) : bool; /** * @return FunctionReflection|MethodReflection|null */ - public function resolve(\PHPStan\Type\Type $type, \PHPStan\Reflection\ClassMemberAccessAnswerer $classMemberAccessAnswerer); + public function resolve(\PHPStan\Type\Type $type, \PHPStan\Analyser\Scope $scope); } diff --git a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ClosureTypeToCallReflectionResolver.php b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ClosureTypeToCallReflectionResolver.php index c00829a254a8..d9af1fa8f3c0 100644 --- a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ClosureTypeToCallReflectionResolver.php +++ b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ClosureTypeToCallReflectionResolver.php @@ -3,7 +3,7 @@ declare (strict_types=1); namespace Rector\Core\PHPStan\Reflection\TypeToCallReflectionResolver; -use PHPStan\Reflection\ClassMemberAccessAnswerer; +use PHPStan\Analyser\Scope; use PHPStan\Reflection\Native\NativeFunctionReflection; use PHPStan\TrinaryLogic; use PHPStan\Type\ClosureType; @@ -18,8 +18,8 @@ public function supports(\PHPStan\Type\Type $type) : bool /** * @param ClosureType $type */ - public function resolve(\PHPStan\Type\Type $type, \PHPStan\Reflection\ClassMemberAccessAnswerer $classMemberAccessAnswerer) : \PHPStan\Reflection\Native\NativeFunctionReflection + public function resolve(\PHPStan\Type\Type $type, \PHPStan\Analyser\Scope $scope) : \PHPStan\Reflection\Native\NativeFunctionReflection { - return new \PHPStan\Reflection\Native\NativeFunctionReflection('{closure}', $type->getCallableParametersAcceptors($classMemberAccessAnswerer), null, \PHPStan\TrinaryLogic::createMaybe()); + return new \PHPStan\Reflection\Native\NativeFunctionReflection('{closure}', $type->getCallableParametersAcceptors($scope), null, \PHPStan\TrinaryLogic::createMaybe()); } } diff --git a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantArrayTypeToCallReflectionResolver.php b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantArrayTypeToCallReflectionResolver.php index 08aee1634579..d08b25771e35 100644 --- a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantArrayTypeToCallReflectionResolver.php +++ b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantArrayTypeToCallReflectionResolver.php @@ -3,7 +3,7 @@ declare (strict_types=1); namespace Rector\Core\PHPStan\Reflection\TypeToCallReflectionResolver; -use PHPStan\Reflection\ClassMemberAccessAnswerer; +use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\Constant\ConstantArrayType; @@ -34,7 +34,7 @@ public function supports(\PHPStan\Type\Type $type) : bool /** * @param ConstantArrayType $type */ - public function resolve(\PHPStan\Type\Type $type, \PHPStan\Reflection\ClassMemberAccessAnswerer $classMemberAccessAnswerer) : ?\PHPStan\Reflection\MethodReflection + public function resolve(\PHPStan\Type\Type $type, \PHPStan\Analyser\Scope $scope) : ?\PHPStan\Reflection\MethodReflection { $constantArrayTypeAndMethod = $this->findTypeAndMethodName($type); if (!$constantArrayTypeAndMethod instanceof \PHPStan\Type\Constant\ConstantArrayTypeAndMethod) { @@ -47,8 +47,8 @@ public function resolve(\PHPStan\Type\Type $type, \PHPStan\Reflection\ClassMembe return null; } $constantArrayType = $constantArrayTypeAndMethod->getType(); - $methodReflection = $constantArrayType->getMethod($constantArrayTypeAndMethod->getMethod(), $classMemberAccessAnswerer); - if (!$classMemberAccessAnswerer->canCallMethod($methodReflection)) { + $methodReflection = $constantArrayType->getMethod($constantArrayTypeAndMethod->getMethod(), $scope); + if (!$scope->canCallMethod($methodReflection)) { return null; } return $methodReflection; diff --git a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantStringTypeToCallReflectionResolver.php b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantStringTypeToCallReflectionResolver.php index 7bdc61bafb10..3aa4129f932e 100644 --- a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantStringTypeToCallReflectionResolver.php +++ b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantStringTypeToCallReflectionResolver.php @@ -5,7 +5,7 @@ use RectorPrefix20210629\Nette\Utils\Strings; use PhpParser\Node\Name; -use PHPStan\Reflection\ClassMemberAccessAnswerer; +use PHPStan\Analyser\Scope; use PHPStan\Reflection\FunctionReflection; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ReflectionProvider; @@ -24,7 +24,15 @@ final class ConstantStringTypeToCallReflectionResolver implements \Rector\Core\C * * @var string */ - private const STATIC_METHOD_REGEX = '#^(?[a-zA-Z_\\x7f-\\xff\\\\][a-zA-Z0-9_\\x7f-\\xff\\\\]*)::(?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\z#'; + private const STATIC_METHOD_REGEX = '#^(?<' . self::CLASS_KEY . '>[a-zA-Z_\\x7f-\\xff\\\\][a-zA-Z0-9_\\x7f-\\xff\\\\]*)::(?<' . self::METHOD_KEY . '>[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\z#'; + /** + * @var string + */ + private const CLASS_KEY = 'class'; + /** + * @var string + */ + private const METHOD_KEY = 'method'; /** * @var \PHPStan\Reflection\ReflectionProvider */ @@ -41,7 +49,7 @@ public function supports(\PHPStan\Type\Type $type) : bool * @param ConstantStringType $type * @return FunctionReflection|MethodReflection|null */ - public function resolve(\PHPStan\Type\Type $type, \PHPStan\Reflection\ClassMemberAccessAnswerer $classMemberAccessAnswerer) + public function resolve(\PHPStan\Type\Type $type, \PHPStan\Analyser\Scope $scope) { $value = $type->getValue(); // 'my_function' @@ -54,13 +62,15 @@ public function resolve(\PHPStan\Type\Type $type, \PHPStan\Reflection\ClassMembe if ($matches === null) { return null; } - if (!$this->reflectionProvider->hasClass($matches['class'])) { + $class = $matches[self::CLASS_KEY]; + if (!$this->reflectionProvider->hasClass($class)) { return null; } - $classReflection = $this->reflectionProvider->getClass($matches['class']); - if (!$classReflection->hasMethod($matches['method'])) { + $classReflection = $this->reflectionProvider->getClass($class); + $method = $matches[self::METHOD_KEY]; + if (!$classReflection->hasMethod($method)) { return null; } - return $classReflection->getMethod($matches['method'], $classMemberAccessAnswerer); + return $classReflection->getMethod($method, $scope); } } diff --git a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ObjectTypeToCallReflectionResolver.php b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ObjectTypeToCallReflectionResolver.php index 4451fe8001fd..3a3b2c5b078d 100644 --- a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ObjectTypeToCallReflectionResolver.php +++ b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ObjectTypeToCallReflectionResolver.php @@ -3,7 +3,7 @@ declare (strict_types=1); namespace Rector\Core\PHPStan\Reflection\TypeToCallReflectionResolver; -use PHPStan\Reflection\ClassMemberAccessAnswerer; +use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\ObjectType; @@ -29,7 +29,7 @@ public function supports(\PHPStan\Type\Type $type) : bool /** * @param ObjectType $type */ - public function resolve(\PHPStan\Type\Type $type, \PHPStan\Reflection\ClassMemberAccessAnswerer $classMemberAccessAnswerer) : ?\PHPStan\Reflection\MethodReflection + public function resolve(\PHPStan\Type\Type $type, \PHPStan\Analyser\Scope $scope) : ?\PHPStan\Reflection\MethodReflection { $className = $type->getClassName(); if (!$this->reflectionProvider->hasClass($className)) { diff --git a/src/PhpParser/Node/Value/ValueResolver.php b/src/PhpParser/Node/Value/ValueResolver.php index d277c8f221ba..68d8323fafa4 100644 --- a/src/PhpParser/Node/Value/ValueResolver.php +++ b/src/PhpParser/Node/Value/ValueResolver.php @@ -135,7 +135,7 @@ public function isNull(\PhpParser\Node $node) : bool * @param Expr[]|null[] $nodes * @param mixed[] $expectedValues */ - public function areValues(array $nodes, array $expectedValues) : bool + public function areValuesEqual(array $nodes, array $expectedValues) : bool { foreach ($nodes as $i => $node) { if ($node === null) { diff --git a/vendor/autoload.php b/vendor/autoload.php index 929eb3aace01..23f80435bf8d 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit59c4fcd97c3ad29947ac27aefc2e4e98::getLoader(); +return ComposerAutoloaderInit21b95b602ec0f7bd9066f339873ca708::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 6b630a71dc63..21853ed8e24a 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit59c4fcd97c3ad29947ac27aefc2e4e98 +class ComposerAutoloaderInit21b95b602ec0f7bd9066f339873ca708 { private static $loader; @@ -22,15 +22,15 @@ public static function getLoader() return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit59c4fcd97c3ad29947ac27aefc2e4e98', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit21b95b602ec0f7bd9066f339873ca708', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); - spl_autoload_unregister(array('ComposerAutoloaderInit59c4fcd97c3ad29947ac27aefc2e4e98', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit21b95b602ec0f7bd9066f339873ca708', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit59c4fcd97c3ad29947ac27aefc2e4e98::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit21b95b602ec0f7bd9066f339873ca708::getInitializer($loader)); } else { $classMap = require __DIR__ . '/autoload_classmap.php'; if ($classMap) { @@ -42,19 +42,19 @@ public static function getLoader() $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInit59c4fcd97c3ad29947ac27aefc2e4e98::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit21b95b602ec0f7bd9066f339873ca708::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire59c4fcd97c3ad29947ac27aefc2e4e98($fileIdentifier, $file); + composerRequire21b95b602ec0f7bd9066f339873ca708($fileIdentifier, $file); } return $loader; } } -function composerRequire59c4fcd97c3ad29947ac27aefc2e4e98($fileIdentifier, $file) +function composerRequire21b95b602ec0f7bd9066f339873ca708($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index cfdaedca8a9b..34f2d7159edd 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit59c4fcd97c3ad29947ac27aefc2e4e98 +class ComposerStaticInit21b95b602ec0f7bd9066f339873ca708 { public static $files = array ( 'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php', @@ -3838,9 +3838,9 @@ class ComposerStaticInit59c4fcd97c3ad29947ac27aefc2e4e98 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit59c4fcd97c3ad29947ac27aefc2e4e98::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit59c4fcd97c3ad29947ac27aefc2e4e98::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit59c4fcd97c3ad29947ac27aefc2e4e98::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit21b95b602ec0f7bd9066f339873ca708::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit21b95b602ec0f7bd9066f339873ca708::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit21b95b602ec0f7bd9066f339873ca708::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/scoper-autoload.php b/vendor/scoper-autoload.php index b21b36669843..8cd416fdd70c 100644 --- a/vendor/scoper-autoload.php +++ b/vendor/scoper-autoload.php @@ -21,8 +21,8 @@ if (!class_exists('CheckoutEntityFactory', false) && !interface_exists('CheckoutEntityFactory', false) && !trait_exists('CheckoutEntityFactory', false)) { spl_autoload_call('RectorPrefix20210629\CheckoutEntityFactory'); } -if (!class_exists('ComposerAutoloaderInit59c4fcd97c3ad29947ac27aefc2e4e98', false) && !interface_exists('ComposerAutoloaderInit59c4fcd97c3ad29947ac27aefc2e4e98', false) && !trait_exists('ComposerAutoloaderInit59c4fcd97c3ad29947ac27aefc2e4e98', false)) { - spl_autoload_call('RectorPrefix20210629\ComposerAutoloaderInit59c4fcd97c3ad29947ac27aefc2e4e98'); +if (!class_exists('ComposerAutoloaderInit21b95b602ec0f7bd9066f339873ca708', false) && !interface_exists('ComposerAutoloaderInit21b95b602ec0f7bd9066f339873ca708', false) && !trait_exists('ComposerAutoloaderInit21b95b602ec0f7bd9066f339873ca708', false)) { + spl_autoload_call('RectorPrefix20210629\ComposerAutoloaderInit21b95b602ec0f7bd9066f339873ca708'); } if (!class_exists('Doctrine\Inflector\Inflector', false) && !interface_exists('Doctrine\Inflector\Inflector', false) && !trait_exists('Doctrine\Inflector\Inflector', false)) { spl_autoload_call('RectorPrefix20210629\Doctrine\Inflector\Inflector'); @@ -3320,9 +3320,9 @@ function print_node() { return \RectorPrefix20210629\print_node(...func_get_args()); } } -if (!function_exists('composerRequire59c4fcd97c3ad29947ac27aefc2e4e98')) { - function composerRequire59c4fcd97c3ad29947ac27aefc2e4e98() { - return \RectorPrefix20210629\composerRequire59c4fcd97c3ad29947ac27aefc2e4e98(...func_get_args()); +if (!function_exists('composerRequire21b95b602ec0f7bd9066f339873ca708')) { + function composerRequire21b95b602ec0f7bd9066f339873ca708() { + return \RectorPrefix20210629\composerRequire21b95b602ec0f7bd9066f339873ca708(...func_get_args()); } } if (!function_exists('parseArgs')) {