diff --git a/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php b/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php index 7fbbd40b447..e90a2a7d16b 100644 --- a/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php +++ b/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php @@ -70,7 +70,10 @@ public function changeReturnType(PhpDocInfo $phpDocInfo, Type $newType): void } // override existing type - $newPHPStanPhpDocType = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($newType, TypeKind::KIND_RETURN); + $newPHPStanPhpDocType = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode( + $newType, + TypeKind::KIND_RETURN + ); $currentReturnTagValueNode = $phpDocInfo->getReturnTagValue(); if ($currentReturnTagValueNode !== null) { diff --git a/packages/FamilyTree/Reflection/FamilyRelationsAnalyzer.php b/packages/FamilyTree/Reflection/FamilyRelationsAnalyzer.php index c8d07aff527..d1a827201d7 100644 --- a/packages/FamilyTree/Reflection/FamilyRelationsAnalyzer.php +++ b/packages/FamilyTree/Reflection/FamilyRelationsAnalyzer.php @@ -155,8 +155,7 @@ private function isPropertyAssignedInClassMethod( ClassMethod $classMethod, string $propertyName, string $kindPropertyFetch - ): bool - { + ): bool { if ($classMethod->stmts === null) { return false; } diff --git a/packages/NodeNestingScope/ParentScopeFinder.php b/packages/NodeNestingScope/ParentScopeFinder.php index ebbbf65e53d..2bec5cadd5a 100644 --- a/packages/NodeNestingScope/ParentScopeFinder.php +++ b/packages/NodeNestingScope/ParentScopeFinder.php @@ -19,10 +19,7 @@ public function __construct( ) { } - /** - * @return ClassMethod|Function_|Class_|Namespace_|Closure|null - */ - public function find(Node $node): ?Node + public function find(Node $node): ClassMethod | Function_ | Class_ | Namespace_ | Closure | null { return $this->betterNodeFinder->findParentTypes($node, [ Closure::class, diff --git a/packages/NodeRemoval/NodeRemover.php b/packages/NodeRemoval/NodeRemover.php index 7842c5c641d..2c891939ab8 100644 --- a/packages/NodeRemoval/NodeRemover.php +++ b/packages/NodeRemoval/NodeRemover.php @@ -63,19 +63,16 @@ public function removeNodes(array $nodes): void } } - /** - * @param Closure|ClassMethod|Function_ $node - */ - public function removeStmt(Node $node, int $key): void + public function removeStmt(Closure | ClassMethod | Function_ $functionLike, int $key): void { - if ($node->stmts === null) { + if ($functionLike->stmts === null) { throw new ShouldNotHappenException(); } // notify about remove node - $this->rectorChangeCollector->notifyNodeFileInfo($node->stmts[$key]); + $this->rectorChangeCollector->notifyNodeFileInfo($functionLike->stmts[$key]); - unset($node->stmts[$key]); + unset($functionLike->stmts[$key]); } public function removeParam(ClassMethod $classMethod, int | Param $keyOrParam): void diff --git a/rules/Arguments/ArgumentDefaultValueReplacer.php b/rules/Arguments/ArgumentDefaultValueReplacer.php index afe356ecb4b..baad1c5e8c2 100644 --- a/rules/Arguments/ArgumentDefaultValueReplacer.php +++ b/rules/Arguments/ArgumentDefaultValueReplacer.php @@ -24,11 +24,8 @@ public function __construct( ) { } - /** - * @param MethodCall|StaticCall|ClassMethod|Expr\FuncCall $node - */ public function processReplaces( - Node $node, + MethodCall | StaticCall | ClassMethod | FuncCall $node, ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue ): ?Node { if ($node instanceof ClassMethod) { diff --git a/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php b/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php index 5d1835aafe6..e3f44dc4308 100644 --- a/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php +++ b/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php @@ -186,11 +186,10 @@ private function processPositionWithDefaultValues( } } - /** - * @param ClassMethod|MethodCall|StaticCall $node - */ - private function shouldSkipParameter(Node $node, ArgumentAdder $argumentAdder): bool - { + private function shouldSkipParameter( + ClassMethod | MethodCall | StaticCall $node, + 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 73f3bedd62d..59c7a8b4f6d 100644 --- a/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php +++ b/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.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\Param; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; @@ -88,10 +87,7 @@ public function refactor(Node $node): ?Node return $node; } - /** - * @param ClassMethod|Function_ $functionLike - */ - private function matchFuncGetArgsVariableAssign(FunctionLike $functionLike): ?Assign + private function matchFuncGetArgsVariableAssign(ClassMethod | Function_ $functionLike): ?Assign { /** @var Assign[] $assigns */ $assigns = $this->betterNodeFinder->findInstanceOf((array) $functionLike->stmts, Assign::class); diff --git a/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php b/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php index 42b6630d086..d689c449669 100644 --- a/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php +++ b/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php @@ -126,11 +126,11 @@ private function resolveCurrentStmtVariableName(Stmt $stmt): ?string return null; } - /** - * @param ClassMethod|Function_|Closure $node - */ - private function shouldAddEmptyLine(?string $currentStmtVariableName, Node $node, int $key): bool - { + private function shouldAddEmptyLine( + ?string $currentStmtVariableName, + ClassMethod | Function_ | Closure $node, + int $key + ): bool { if (! $this->isNewVariableThanBefore($currentStmtVariableName)) { return false; } @@ -173,10 +173,7 @@ private function isNewVariableThanBefore(?string $currentStmtVariableName): bool return $this->previousStmtVariableName !== $currentStmtVariableName; } - /** - * @param ClassMethod|Function_|Closure $node - */ - private function isPrecededByEmptyLine(Node $node, int $key): bool + private function isPrecededByEmptyLine(ClassMethod | Function_ | Closure $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 1959bd82191..bff088c7085 100644 --- a/rules/DowngradePhp71/Rector/FunctionLike/DowngradeNullableTypeDeclarationRector.php +++ b/rules/DowngradePhp71/Rector/FunctionLike/DowngradeNullableTypeDeclarationRector.php @@ -6,7 +6,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; @@ -105,10 +104,7 @@ private function isNullableParam(Param $param): bool return $param->type instanceof NullableType; } - /** - * @param ClassMethod|Function_|Closure $functionLike - */ - private function refactorParamType(Param $param, FunctionLike $functionLike): bool + private function refactorParamType(Param $param, ClassMethod | Function_ | Closure $functionLike): bool { if (! $this->isNullableParam($param)) { return false; @@ -120,10 +116,7 @@ private function refactorParamType(Param $param, FunctionLike $functionLike): bo return true; } - /** - * @param ClassMethod|Function_|Closure $functionLike - */ - private function decorateWithDocBlock(FunctionLike $functionLike, Param $param): void + private function decorateWithDocBlock(ClassMethod | Function_ | Closure $functionLike, Param $param): void { if ($param->type === null) { return; diff --git a/rules/DowngradePhp71/TypeDeclaration/PhpDocFromTypeDeclarationDecorator.php b/rules/DowngradePhp71/TypeDeclaration/PhpDocFromTypeDeclarationDecorator.php index e86e48865ff..faa67f1d294 100644 --- a/rules/DowngradePhp71/TypeDeclaration/PhpDocFromTypeDeclarationDecorator.php +++ b/rules/DowngradePhp71/TypeDeclaration/PhpDocFromTypeDeclarationDecorator.php @@ -6,7 +6,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_; @@ -30,10 +29,9 @@ public function __construct( } /** - * @param ClassMethod|Function_|Closure $functionLike * @return bool True if node was changed */ - public function decorate(FunctionLike $functionLike): bool + public function decorate(ClassMethod | Function_ | Closure $functionLike): bool { if ($functionLike->returnType === null) { return false; @@ -49,11 +47,13 @@ public function decorate(FunctionLike $functionLike): bool } /** - * @param ClassMethod|Function_ $functionLike * @param array> $requiredTypes */ - public function decorateParam(Param $param, FunctionLike $functionLike, array $requiredTypes): void - { + public function decorateParam( + Param $param, + ClassMethod | Function_ | Closure $functionLike, + array $requiredTypes + ): void { if ($param->type === null) { return; } @@ -67,12 +67,9 @@ public function decorateParam(Param $param, FunctionLike $functionLike, array $r $this->moveParamTypeToParamDoc($functionLike, $param, $type); } - /** - * @param ClassMethod|Function_ $functionLike - */ public function decorateParamWithSpecificType( Param $param, - FunctionLike $functionLike, + ClassMethod | Function_ | Closure $functionLike, Type $requireType ): void { if ($param->type === null) { @@ -88,11 +85,12 @@ public function decorateParamWithSpecificType( } /** - * @param ClassMethod|Function_|Closure $functionLike * @return bool True if node was changed */ - public function decorateReturnWithSpecificType(FunctionLike $functionLike, Type $requireType): bool - { + public function decorateReturnWithSpecificType( + ClassMethod | Function_ | Closure $functionLike, + Type $requireType + ): bool { if ($functionLike->returnType === null) { return false; } @@ -115,11 +113,11 @@ private function isTypeMatchOrSubType(Node $typeNode, Type $requireType): bool return is_a($returnType, $requireType::class, true); } - /** - * @param ClassMethod|Function_ $functionLike - */ - private function moveParamTypeToParamDoc(FunctionLike $functionLike, Param $param, Type $type): void - { + private function moveParamTypeToParamDoc( + ClassMethod | Function_ | Closure $functionLike, + Param $param, + Type $type + ): void { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike); $paramName = $this->nodeNameResolver->getName($param); $this->phpDocTypeChanger->changeParamType($phpDocInfo, $type, $param, $paramName); diff --git a/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php b/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php index 482c60ca70d..d582e90a2f0 100644 --- a/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php +++ b/rules/DowngradePhp74/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php @@ -227,10 +227,7 @@ private function getDifferentParamTypeFromReflectionMethod( return null; } - /** - * @param ClassMethod|Function_ $functionLike - */ - private function refactorParam(Param $param, FunctionLike $functionLike): void + private function refactorParam(Param $param, ClassMethod | Function_ $functionLike): void { if (! $this->isNullableParam($param, $functionLike)) { return; @@ -240,10 +237,7 @@ private function refactorParam(Param $param, FunctionLike $functionLike): void $param->type = null; } - /** - * @param ClassMethod|Function_ $functionLike - */ - private function decorateWithDocBlock(FunctionLike $functionLike, Param $param): void + private function decorateWithDocBlock(ClassMethod | Function_ $functionLike, 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 114f623070b..596d26ef0fc 100644 --- a/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php +++ b/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php @@ -136,10 +136,7 @@ private function processUses(Closure $node): void $this->cleanTrailingComma($node, $node->uses); } - /** - * @param ClassMethod|Function_|Closure $node - */ - private function processParams(Node $node): ?Node + private function processParams(ClassMethod | Function_ | Closure $node): ?Node { if ($node->params === []) { return null; diff --git a/rules/Naming/Guard/BreakingVariableRenameGuard.php b/rules/Naming/Guard/BreakingVariableRenameGuard.php index 45c2715bfd8..e04c886ace7 100644 --- a/rules/Naming/Guard/BreakingVariableRenameGuard.php +++ b/rules/Naming/Guard/BreakingVariableRenameGuard.php @@ -9,7 +9,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_; @@ -47,13 +46,10 @@ public function __construct( ) { } - /** - * @param ClassMethod|Function_|Closure $functionLike - */ public function shouldSkipVariable( string $currentName, string $expectedName, - FunctionLike $functionLike, + ClassMethod | Function_ | Closure $functionLike, Variable $variable ): bool { // is the suffix? → also accepted @@ -152,19 +148,15 @@ private function isVariableAlreadyDefined(Variable $variable, string $currentVar return $trinaryLogic->maybe(); } - /** - * @param ClassMethod|Function_|Closure $functionLike - */ - private function skipOnConflictOtherVariable(FunctionLike $functionLike, string $newName): bool + private function skipOnConflictOtherVariable(ClassMethod | Function_ | Closure $functionLike, string $newName): bool { return $this->betterNodeFinder->hasInstanceOfName((array) $functionLike->stmts, Variable::class, $newName); } - /** - * @param ClassMethod|Function_|Closure $functionLike - */ - private function isUsedInClosureUsesName(string $expectedName, FunctionLike $functionLike): bool - { + private function isUsedInClosureUsesName( + string $expectedName, + ClassMethod | Function_ | Closure $functionLike + ): bool { if (! $functionLike instanceof Closure) { return false; } diff --git a/rules/Naming/Matcher/ForeachMatcher.php b/rules/Naming/Matcher/ForeachMatcher.php index d6ce76e52bf..6d0ad1dbc86 100644 --- a/rules/Naming/Matcher/ForeachMatcher.php +++ b/rules/Naming/Matcher/ForeachMatcher.php @@ -4,7 +4,6 @@ namespace Rector\Naming\Matcher; -use PhpParser\Node; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\ClassMethod; @@ -47,10 +46,7 @@ public function match(Foreach_ $foreach): ?VariableAndCallForeach return new VariableAndCallForeach($foreach->valueVar, $call, $variableName, $functionLike); } - /** - * @return ClassMethod|Function_|Closure|null - */ - private function getFunctionLike(Foreach_ $foreach): ?Node + private function getFunctionLike(Foreach_ $foreach): ClassMethod | Function_ | Closure | null { return $this->betterNodeFinder->findParentTypes( $foreach, diff --git a/rules/Naming/Matcher/VariableAndCallAssignMatcher.php b/rules/Naming/Matcher/VariableAndCallAssignMatcher.php index 834df13a672..009caaaf2b1 100644 --- a/rules/Naming/Matcher/VariableAndCallAssignMatcher.php +++ b/rules/Naming/Matcher/VariableAndCallAssignMatcher.php @@ -4,7 +4,6 @@ namespace Rector\Naming\Matcher; -use PhpParser\Node; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; @@ -48,10 +47,7 @@ public function match(Assign $assign): ?VariableAndCallAssign return new VariableAndCallAssign($assign->var, $call, $assign, $variableName, $functionLike); } - /** - * @return ClassMethod|Function_|Closure|null - */ - private function getFunctionLike(Assign $assign): ?Node + private function getFunctionLike(Assign $assign): ClassMethod | Function_ | Closure | null { return $this->betterNodeFinder->findParentTypes( $assign, diff --git a/rules/Naming/Naming/ConflictingNameResolver.php b/rules/Naming/Naming/ConflictingNameResolver.php index 8e7fdf7818c..361d55a6176 100644 --- a/rules/Naming/Naming/ConflictingNameResolver.php +++ b/rules/Naming/Naming/ConflictingNameResolver.php @@ -6,7 +6,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; @@ -48,20 +47,18 @@ public function resolveConflictingVariableNamesForParam(ClassMethod $classMethod return $this->arrayFilter->filterWithAtLeastTwoOccurences($expectedNames); } - /** - * @param ClassMethod|Function_|Closure $functionLike - */ - public function checkNameIsInFunctionLike(string $variableName, FunctionLike $functionLike): bool - { + public function checkNameIsInFunctionLike( + string $variableName, + ClassMethod | Function_ | Closure $functionLike + ): bool { $conflictingVariableNames = $this->resolveConflictingVariableNamesForNew($functionLike); return in_array($variableName, $conflictingVariableNames, true); } /** - * @param ClassMethod|Function_|Closure $functionLike * @return string[] */ - private function resolveConflictingVariableNamesForNew(FunctionLike $functionLike): array + private function resolveConflictingVariableNamesForNew(ClassMethod | Function_ | Closure $functionLike): array { // cache it! $classMethodHash = spl_object_hash($functionLike); @@ -83,10 +80,9 @@ private function resolveConflictingVariableNamesForNew(FunctionLike $functionLik } /** - * @param ClassMethod|Function_|Closure $functionLike * @return string[] */ - private function collectParamNames(FunctionLike $functionLike): array + private function collectParamNames(ClassMethod | Function_ | Closure $functionLike): array { $paramNames = []; @@ -99,10 +95,9 @@ private function collectParamNames(FunctionLike $functionLike): array } /** - * @param ClassMethod|Function_|Closure $functionLike * @return string[] */ - private function resolveForNewAssigns(FunctionLike $functionLike): array + private function resolveForNewAssigns(ClassMethod | Function_ | Closure $functionLike): array { $names = []; @@ -121,10 +116,9 @@ private function resolveForNewAssigns(FunctionLike $functionLike): array } /** - * @param ClassMethod|Function_|Closure $functionLike * @return string[] */ - private function resolveForNonNewAssigns(FunctionLike $functionLike): array + private function resolveForNonNewAssigns(ClassMethod | Function_ | Closure $functionLike): array { $names = []; diff --git a/rules/Naming/Naming/OverridenExistingNamesResolver.php b/rules/Naming/Naming/OverridenExistingNamesResolver.php index 75f54e4331e..5e3d2d60c22 100644 --- a/rules/Naming/Naming/OverridenExistingNamesResolver.php +++ b/rules/Naming/Naming/OverridenExistingNamesResolver.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\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; use Rector\Core\PhpParser\Node\BetterNodeFinder; @@ -28,11 +27,10 @@ public function __construct( ) { } - /** - * @param ClassMethod|Function_|Closure $functionLike - */ - public function checkNameInClassMethodForNew(string $variableName, FunctionLike $functionLike): bool - { + public function checkNameInClassMethodForNew( + string $variableName, + ClassMethod | Function_ | Closure $functionLike + ): bool { $overridenVariableNames = $this->resolveOveriddenNamesForNew($functionLike); return in_array($variableName, $overridenVariableNames, true); } @@ -59,10 +57,9 @@ public function checkNameInClassMethodForParam(string $expectedName, ClassMethod } /** - * @param ClassMethod|Function_|Closure $functionLike * @return string[] */ - private function resolveOveriddenNamesForNew(FunctionLike $functionLike): array + private function resolveOveriddenNamesForNew(ClassMethod | Function_ | Closure $functionLike): array { $classMethodHash = spl_object_hash($functionLike); diff --git a/rules/Naming/ValueObject/ParamRename.php b/rules/Naming/ValueObject/ParamRename.php index 66c870e25a8..d37cb493643 100644 --- a/rules/Naming/ValueObject/ParamRename.php +++ b/rules/Naming/ValueObject/ParamRename.php @@ -6,7 +6,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_; @@ -14,15 +13,12 @@ final class ParamRename implements RenameParamValueObjectInterface { - /** - * @param ClassMethod|Function_|Closure $functionLike - */ public function __construct( private string $currentName, private string $expectedName, private Param $param, private Variable $variable, - private FunctionLike $functionLike + private ClassMethod | Function_ | Closure $functionLike ) { } @@ -36,10 +32,7 @@ public function getExpectedName(): string return $this->expectedName; } - /** - * @return ClassMethod|Function_|Closure - */ - public function getFunctionLike(): FunctionLike + public function getFunctionLike(): ClassMethod | Function_ | Closure { return $this->functionLike; } diff --git a/rules/Naming/ValueObject/VariableAndCallAssign.php b/rules/Naming/ValueObject/VariableAndCallAssign.php index 3d205c9723c..665a9335cd4 100644 --- a/rules/Naming/ValueObject/VariableAndCallAssign.php +++ b/rules/Naming/ValueObject/VariableAndCallAssign.php @@ -4,29 +4,23 @@ 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 { - /** - * @param FuncCall|StaticCall|MethodCall $expr - * @param ClassMethod|Function_|Closure $functionLike - */ public function __construct( private Variable $variable, - private Expr $expr, + private FuncCall | StaticCall | MethodCall $expr, private Assign $assign, private string $variableName, - private FunctionLike $functionLike + private ClassMethod | Function_ | Closure $functionLike ) { } diff --git a/rules/Naming/ValueObject/VariableAndCallForeach.php b/rules/Naming/ValueObject/VariableAndCallForeach.php index 5be51562220..a982d1297b8 100644 --- a/rules/Naming/ValueObject/VariableAndCallForeach.php +++ b/rules/Naming/ValueObject/VariableAndCallForeach.php @@ -4,27 +4,21 @@ 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 { - /** - * @param FuncCall|StaticCall|MethodCall $expr - * @param ClassMethod|Function_|Closure $functionLike - */ public function __construct( private Variable $variable, - private Expr $expr, + private FuncCall | StaticCall | MethodCall $expr, private string $variableName, - private FunctionLike $functionLike + private ClassMethod | Function_ | Closure $functionLike ) { } diff --git a/rules/Naming/VariableRenamer.php b/rules/Naming/VariableRenamer.php index a32def56b34..d011e296ca6 100644 --- a/rules/Naming/VariableRenamer.php +++ b/rules/Naming/VariableRenamer.php @@ -8,7 +8,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_; @@ -31,11 +30,8 @@ public function __construct( ) { } - /** - * @param ClassMethod|Function_|Closure $functionLike - */ public function renameVariableInFunctionLike( - FunctionLike $functionLike, + ClassMethod | Function_ | Closure $functionLike, string $oldName, string $expectedName, ?Assign $assign = null diff --git a/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php b/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php index f82b1394743..4a3f468a686 100644 --- a/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php +++ b/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php @@ -117,10 +117,9 @@ public function refactor(Node $node): ?Node } /** - * @param ClassMethod|Function_|Closure $node * @return string[] */ - private function collectUndefinedVariableScope(Node $node): array + private function collectUndefinedVariableScope(ClassMethod | Function_ | Closure $node): array { $undefinedVariables = []; diff --git a/rules/Php70/Rector/Ternary/TernaryToSpaceshipRector.php b/rules/Php70/Rector/Ternary/TernaryToSpaceshipRector.php index 2122d61edaa..5aea1413ae8 100644 --- a/rules/Php70/Rector/Ternary/TernaryToSpaceshipRector.php +++ b/rules/Php70/Rector/Ternary/TernaryToSpaceshipRector.php @@ -112,7 +112,7 @@ private function processSmallerThanTernary(Ternary $node, Ternary $nestedTernary 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; } @@ -132,7 +132,7 @@ private function processGreaterThanTernary(Ternary $node, Ternary $nestedTernary 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; } diff --git a/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php b/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php index 52b8e5b55e7..6e51f82a4e2 100644 --- a/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php +++ b/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php @@ -140,10 +140,12 @@ public function configure(array $configuration): void /** * @param array $tags - * @param Class_|Property|ClassMethod|Function_|Closure|ArrowFunction $node */ - private function processApplyAttrGroups(array $tags, PhpDocInfo $phpDocInfo, Node $node): bool - { + private function processApplyAttrGroups( + array $tags, + PhpDocInfo $phpDocInfo, + Class_ | Property | ClassMethod | Function_ | Closure | ArrowFunction $node + ): bool { $hasNewAttrGroups = false; foreach ($tags as $tag) { foreach ($this->annotationsToAttributes as $annotationToAttribute) { diff --git a/rules/Php80/Rector/FuncCall/TokenGetAllToObjectRector.php b/rules/Php80/Rector/FuncCall/TokenGetAllToObjectRector.php index ed38b90acbd..56f1b4fb379 100644 --- a/rules/Php80/Rector/FuncCall/TokenGetAllToObjectRector.php +++ b/rules/Php80/Rector/FuncCall/TokenGetAllToObjectRector.php @@ -9,7 +9,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_; @@ -117,10 +116,7 @@ private function refactorTokensVariable(FuncCall $funcCall): void $this->replaceGetNameOrGetValue($classMethodOrFunction, $assign->var); } - /** - * @param ClassMethod|Function_ $functionLike - */ - private function replaceGetNameOrGetValue(FunctionLike $functionLike, Expr $assignedExpr): void + private function replaceGetNameOrGetValue(ClassMethod | Function_ $functionLike, Expr $assignedExpr): void { $tokensForeaches = $this->findForeachesOverTokenVariable($functionLike, $assignedExpr); foreach ($tokensForeaches as $tokenForeach) { @@ -129,10 +125,9 @@ private function replaceGetNameOrGetValue(FunctionLike $functionLike, Expr $assi } /** - * @param ClassMethod|Function_ $functionLike * @return Foreach_[] */ - private function findForeachesOverTokenVariable(FunctionLike $functionLike, Expr $assignedExpr): array + private function findForeachesOverTokenVariable(ClassMethod | Function_ $functionLike, Expr $assignedExpr): array { return $this->betterNodeFinder->find((array) $functionLike->stmts, function (Node $node) use ( $assignedExpr diff --git a/rules/Php80/Rector/FunctionLike/UnionTypesRector.php b/rules/Php80/Rector/FunctionLike/UnionTypesRector.php index 82c932ec55e..eda7eaa838c 100644 --- a/rules/Php80/Rector/FunctionLike/UnionTypesRector.php +++ b/rules/Php80/Rector/FunctionLike/UnionTypesRector.php @@ -7,7 +7,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; @@ -82,7 +81,7 @@ public function getNodeTypes(): array } /** - * @param ClassMethod|Function_|Closure|ArrowFunction $node + * @param ClassMethod | Function_ | Closure | ArrowFunction $node */ public function refactor(Node $node): ?Node { @@ -101,11 +100,10 @@ public function refactor(Node $node): ?Node return $node; } - /** - * @param ClassMethod|Function_|Closure|ArrowFunction $functionLike - */ - private function refactorParamTypes(FunctionLike $functionLike, PhpDocInfo $phpDocInfo): void - { + private function refactorParamTypes( + ClassMethod | Function_ | Closure | ArrowFunction $functionLike, + PhpDocInfo $phpDocInfo + ): void { if ($functionLike instanceof ClassMethod && $this->classMethodParamVendorLockResolver->isVendorLocked( $functionLike )) { @@ -152,11 +150,10 @@ private function changeObjectWithoutClassType(Param $param, UnionType $unionType $param->type = new Name('object'); } - /** - * @param ClassMethod|Function_|Closure|ArrowFunction $functionLike - */ - private function refactorReturnType(FunctionLike $functionLike, PhpDocInfo $phpDocInfo): void - { + private function refactorReturnType( + ClassMethod | Function_ | Closure | ArrowFunction $functionLike, + PhpDocInfo $phpDocInfo + ): void { // do not override existing return type if ($functionLike->getReturnType() !== null) { return; diff --git a/rules/Privatization/NodeManipulator/VisibilityManipulator.php b/rules/Privatization/NodeManipulator/VisibilityManipulator.php index 009efc03ec3..405d7c9af64 100644 --- a/rules/Privatization/NodeManipulator/VisibilityManipulator.php +++ b/rules/Privatization/NodeManipulator/VisibilityManipulator.php @@ -21,26 +21,17 @@ final class VisibilityManipulator */ private const ALLOWED_NODE_TYPES = [ClassMethod::class, Property::class, ClassConst::class, Class_::class]; - /** - * @param ClassMethod|Property|ClassConst $node - */ - public function makeStatic(Node $node): void + public function makeStatic(ClassMethod | Property | ClassConst $node): void { $this->addVisibilityFlag($node, Visibility::STATIC); } - /** - * @param ClassMethod|Class_ $node - */ - public function makeAbstract(Node $node): void + public function makeAbstract(ClassMethod | Class_ $node): void { $this->addVisibilityFlag($node, Visibility::ABSTRACT); } - /** - * @param ClassMethod|Property $node - */ - public function makeNonStatic(Node $node): void + public function makeNonStatic(ClassMethod | Property $node): void { if (! $node->isStatic()) { return; diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector.php index dba32ffa345..3a1767b3e39 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector.php @@ -95,36 +95,32 @@ public function refactor(Node $node): ?Node return $node; } - /** - * @param ClassMethod|Function_ $node - */ - private function shouldSkip($node):bool { + private function shouldSkip(ClassMethod | Function_ $node): bool + { $returns = $this->betterNodeFinder->findInstanceOf($node, Return_::class); if ($returns !== []) { return true; } - $notNeverNodes = $this->betterNodeFinder->findInstancesOf($node, [Yield_::class]); + $notNeverNodes = $this->betterNodeFinder->findInstanceOf($node, Yield_::class); if ($notNeverNodes !== []) { return true; } $neverNodes = $this->betterNodeFinder->findInstancesOf($node, [Node\Expr\Throw_::class, Throw_::class]); + $hasNeverFuncCall = $this->resolveHasNeverFuncCall($node); if ($neverNodes === [] && ! $hasNeverFuncCall) { return true; } if ($node instanceof ClassMethod && ! $this->parentClassMethodTypeOverrideGuard->isReturnTypeChangeAllowed( - $node - )) { + $node + )) { return true; } - if ($node->returnType && $this->isName($node->returnType, 'never')) { - return true; - } - return false; + return $node->returnType && $this->isName($node->returnType, 'never'); } /** diff --git a/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php b/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php index 3ba05f5c006..fd9b8185b65 100644 --- a/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php +++ b/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php @@ -4,7 +4,7 @@ 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; @@ -16,5 +16,5 @@ public function supports(Type $type): bool; /** * @return FunctionReflection|MethodReflection|null */ - public function resolve(Type $type, ClassMemberAccessAnswerer $classMemberAccessAnswerer); + public function resolve(Type $type, Scope $scope); } diff --git a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ClosureTypeToCallReflectionResolver.php b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ClosureTypeToCallReflectionResolver.php index 813c3238bc1..f9459c148fc 100644 --- a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ClosureTypeToCallReflectionResolver.php +++ b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ClosureTypeToCallReflectionResolver.php @@ -4,7 +4,7 @@ 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; @@ -21,11 +21,11 @@ public function supports(Type $type): bool /** * @param ClosureType $type */ - public function resolve(Type $type, ClassMemberAccessAnswerer $classMemberAccessAnswerer): NativeFunctionReflection + public function resolve(Type $type, Scope $scope): NativeFunctionReflection { return new NativeFunctionReflection( '{closure}', - $type->getCallableParametersAcceptors($classMemberAccessAnswerer), + $type->getCallableParametersAcceptors($scope), null, TrinaryLogic::createMaybe() ); diff --git a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantArrayTypeToCallReflectionResolver.php b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantArrayTypeToCallReflectionResolver.php index f1a9776df19..b7b15337787 100644 --- a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantArrayTypeToCallReflectionResolver.php +++ b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantArrayTypeToCallReflectionResolver.php @@ -4,7 +4,7 @@ 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(Type $type): bool /** * @param ConstantArrayType $type */ - public function resolve(Type $type, ClassMemberAccessAnswerer $classMemberAccessAnswerer): ?MethodReflection + public function resolve(Type $type, Scope $scope): ?MethodReflection { $constantArrayTypeAndMethod = $this->findTypeAndMethodName($type); if (! $constantArrayTypeAndMethod instanceof ConstantArrayTypeAndMethod) { @@ -49,11 +49,8 @@ public function resolve(Type $type, ClassMemberAccessAnswerer $classMemberAccess $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; } diff --git a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantStringTypeToCallReflectionResolver.php b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantStringTypeToCallReflectionResolver.php index a75b50a54ec..1466e98d16e 100644 --- a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantStringTypeToCallReflectionResolver.php +++ b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantStringTypeToCallReflectionResolver.php @@ -6,7 +6,7 @@ use 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; @@ -26,10 +26,20 @@ final class ConstantStringTypeToCallReflectionResolver implements TypeToCallRefl * * @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'; public function __construct( - private ReflectionProvider $reflectionProvider + private ReflectionProvider $reflectionProvider, ) { } @@ -42,7 +52,7 @@ public function supports(Type $type): bool * @param ConstantStringType $type * @return FunctionReflection|MethodReflection|null */ - public function resolve(Type $type, ClassMemberAccessAnswerer $classMemberAccessAnswerer) + public function resolve(Type $type, Scope $scope) { $value = $type->getValue(); @@ -58,15 +68,18 @@ public function resolve(Type $type, ClassMemberAccessAnswerer $classMemberAccess 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 b89e8c285f4..50a67a985c4 100644 --- a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ObjectTypeToCallReflectionResolver.php +++ b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ObjectTypeToCallReflectionResolver.php @@ -4,7 +4,7 @@ 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(Type $type): bool /** * @param ObjectType $type */ - public function resolve(Type $type, ClassMemberAccessAnswerer $classMemberAccessAnswerer): ?MethodReflection + public function resolve(Type $type, Scope $scope): ?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 149b7faff63..a4d4b9aab58 100644 --- a/src/PhpParser/Node/Value/ValueResolver.php +++ b/src/PhpParser/Node/Value/ValueResolver.php @@ -134,7 +134,7 @@ public function isNull(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) {