diff --git a/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php b/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php index 34d1495f0e9..d985c3a0faa 100644 --- a/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php +++ b/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php @@ -4,7 +4,11 @@ declare(strict_types=1); namespace Rector\BetterPhpDocParser\PhpDocParser; +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprFalseNode; +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode; +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprTrueNode; use PHPStan\PhpDocParser\Lexer\Lexer; +use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode; use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\ArrayParser; use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\PlainValueParser; use Rector\BetterPhpDocParser\ValueObject\Parser\BetterTokenIterator; @@ -44,10 +48,11 @@ final class StaticDoctrineAnnotationParser /** * @see https://github.com/doctrine/annotations/blob/c66f06b7c83e9a2a7523351a9d5a4b55f885e574/lib/Doctrine/Common/Annotations/DocParser.php#L1215-L1224 - * @return mixed|mixed[] + * @return array */ - public function resolveAnnotationValue(BetterTokenIterator $tokenIterator) - { + public function resolveAnnotationValue( + BetterTokenIterator $tokenIterator + ): CurlyListNode | string | array | ConstExprFalseNode | ConstExprTrueNode | ConstExprIntegerNode | DoctrineAnnotationTagValueNode { // skips dummy tokens like newlines $tokenIterator->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL); @@ -58,6 +63,7 @@ final class StaticDoctrineAnnotationParser } // 2. assign key = value - mimics FieldAssignment() https://github.com/doctrine/annotations/blob/0cb0cd2950a5c6cdbf22adbe2bfd5fd1ea68588f/lib/Doctrine/Common/Annotations/DocParser.php#L1291-L1303 + /** @var int $key */ $key = $this->parseValue($tokenIterator); $tokenIterator->consumeTokenType(Lexer::TOKEN_EQUAL); @@ -72,7 +78,7 @@ final class StaticDoctrineAnnotationParser /** * @see https://github.com/doctrine/annotations/blob/c66f06b7c83e9a2a7523351a9d5a4b55f885e574/lib/Doctrine/Common/Annotations/DocParser.php#L1051-L1079 - * @return array + * @return array */ private function resolveAnnotationValues(BetterTokenIterator $tokenIterator): array { @@ -101,10 +107,11 @@ final class StaticDoctrineAnnotationParser } /** - * @return bool|int|mixed|mixed[]|string + * @return array */ - private function parseValue(BetterTokenIterator $tokenIterator) - { + private function parseValue( + BetterTokenIterator $tokenIterator + ): CurlyListNode | string | array | ConstExprFalseNode | ConstExprTrueNode | ConstExprIntegerNode | DoctrineAnnotationTagValueNode { if ($tokenIterator->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET)) { $items = $this->arrayParser->parseCurlyArray($tokenIterator); return new CurlyListNode($items); diff --git a/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser/PlainValueParser.php b/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser/PlainValueParser.php index b8db0899442..2da5f19a42d 100644 --- a/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser/PlainValueParser.php +++ b/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser/PlainValueParser.php @@ -39,10 +39,11 @@ final class PlainValueParser } /** - * @return bool|int|mixed|string + * @return mixed[] */ - public function parseValue(BetterTokenIterator $tokenIterator) - { + public function parseValue( + BetterTokenIterator $tokenIterator + ): string | array | ConstExprFalseNode | ConstExprTrueNode | ConstExprIntegerNode | DoctrineAnnotationTagValueNode { $currentTokenValue = $tokenIterator->currentTokenValue(); // temporary hackaround multi-line doctrine annotations diff --git a/packages/NodeCollector/NodeCollector/NodeRepository.php b/packages/NodeCollector/NodeCollector/NodeRepository.php index d8d9b1867a3..314bf7ad956 100644 --- a/packages/NodeCollector/NodeCollector/NodeRepository.php +++ b/packages/NodeCollector/NodeCollector/NodeRepository.php @@ -471,9 +471,8 @@ final class NodeRepository return; } - $this->arrayCallablesByTypeAndMethod[$arrayCallable->getClass()][strtolower( - $arrayCallable->getMethod() - )][] = $arrayCallable; + $methodName = strtolower($arrayCallable->getMethod()); + $this->arrayCallablesByTypeAndMethod[$arrayCallable->getClass()][$methodName][] = $arrayCallable; } private function addMethod(ClassMethod $classMethod): void diff --git a/packages/NodeTypeResolver/NodeTypeResolver/IdentifierTypeResolver.php b/packages/NodeTypeResolver/NodeTypeResolver/IdentifierTypeResolver.php index b60324b3ee9..acc78e362b0 100644 --- a/packages/NodeTypeResolver/NodeTypeResolver/IdentifierTypeResolver.php +++ b/packages/NodeTypeResolver/NodeTypeResolver/IdentifierTypeResolver.php @@ -10,11 +10,10 @@ use PHPStan\Type\FloatType; use PHPStan\Type\IntegerType; use PHPStan\Type\MixedType; use PHPStan\Type\StringType; -use PHPStan\Type\Type; final class IdentifierTypeResolver { - public function resolve(Identifier $identifier): Type + public function resolve(Identifier $identifier): StringType | BooleanType | IntegerType | FloatType | MixedType { if ($identifier->toLowerString() === 'string') { return new StringType(); diff --git a/packages/NodeTypeResolver/NodeTypeResolver/NameTypeResolver.php b/packages/NodeTypeResolver/NodeTypeResolver/NameTypeResolver.php index d6e7c29fbde..9e5d4fd44ef 100644 --- a/packages/NodeTypeResolver/NodeTypeResolver/NameTypeResolver.php +++ b/packages/NodeTypeResolver/NodeTypeResolver/NameTypeResolver.php @@ -46,10 +46,7 @@ final class NameTypeResolver implements NodeTypeResolverInterface return new ObjectType($fullyQualifiedName); } - /** - * @return ObjectType|UnionType|MixedType - */ - private function resolveParent(Name $name): Type + private function resolveParent(Name $name): MixedType | ObjectType | UnionType { $className = $name->getAttribute(AttributeKey::CLASS_NAME); if ($className === null) { diff --git a/packages/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeCommonTypeNarrower.php b/packages/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeCommonTypeNarrower.php index 5c20ae9a306..6415acd10e7 100644 --- a/packages/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeCommonTypeNarrower.php +++ b/packages/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeCommonTypeNarrower.php @@ -16,7 +16,6 @@ use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\Generic\GenericClassStringType; use PHPStan\Type\ObjectType; -use PHPStan\Type\Type; use PHPStan\Type\UnionType; use Rector\Core\Contract\Rector\RectorInterface; use Rector\NodeTypeResolver\NodeTypeCorrector\GenericClassStringTypeCorrector; @@ -64,10 +63,7 @@ final class UnionTypeCommonTypeNarrower return null; } - /** - * @return GenericClassStringType|UnionType - */ - public function narrowToGenericClassStringType(UnionType $unionType): Type + public function narrowToGenericClassStringType(UnionType $unionType): UnionType | GenericClassStringType { $availableTypes = []; diff --git a/packages/StaticTypeMapper/PhpDocParser/IdentifierTypeMapper.php b/packages/StaticTypeMapper/PhpDocParser/IdentifierTypeMapper.php index 8598b4776a2..194b5fff777 100644 --- a/packages/StaticTypeMapper/PhpDocParser/IdentifierTypeMapper.php +++ b/packages/StaticTypeMapper/PhpDocParser/IdentifierTypeMapper.php @@ -13,7 +13,6 @@ use PHPStan\Type\IterableType; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; use PHPStan\Type\StaticType; -use PHPStan\Type\SubtractableType; use PHPStan\Type\Type; use Rector\NodeCollector\ScopeResolver\ParentClassScopeResolver; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -81,7 +80,7 @@ final class IdentifierTypeMapper implements PhpDocTypeMapperInterface return $this->objectTypeSpecifier->narrowToFullyQualifiedOrAliasedObjectType($node, $objectType); } - private function mapSelf(Node $node): SubtractableType + private function mapSelf(Node $node): MixedType | SelfObjectType { /** @var string|null $className */ $className = $node->getAttribute(AttributeKey::CLASS_NAME); @@ -93,7 +92,7 @@ final class IdentifierTypeMapper implements PhpDocTypeMapperInterface return new SelfObjectType($className); } - private function mapParent(Node $node): Type + private function mapParent(Node $node): ParentStaticType | MixedType { $parentClassName = $this->parentClassScopeResolver->resolveParentClassName($node); if ($parentClassName !== null) { @@ -103,7 +102,7 @@ final class IdentifierTypeMapper implements PhpDocTypeMapperInterface return new MixedType(); } - private function mapStatic(Node $node): Type + private function mapStatic(Node $node): MixedType | StaticType { /** @var string|null $className */ $className = $node->getAttribute(AttributeKey::CLASS_NAME); diff --git a/packages/StaticTypeMapper/PhpParser/NameNodeMapper.php b/packages/StaticTypeMapper/PhpParser/NameNodeMapper.php index b054721c1c0..cd851550752 100644 --- a/packages/StaticTypeMapper/PhpParser/NameNodeMapper.php +++ b/packages/StaticTypeMapper/PhpParser/NameNodeMapper.php @@ -67,7 +67,7 @@ final class NameNodeMapper implements PhpParserNodeMapperInterface return in_array($name, $oldToNewClasses, true); } - private function createClassReferenceType(Name $name, string $reference): Type + private function createClassReferenceType(Name $name, string $reference): MixedType | StaticType | ThisType { $className = $name->getAttribute(AttributeKey::CLASS_NAME); if ($className === null) { @@ -86,8 +86,9 @@ final class NameNodeMapper implements PhpParserNodeMapperInterface return new ThisType($className); } - private function createScalarType(string $name): Type - { + private function createScalarType( + string $name + ): ArrayType | IntegerType | FloatType | StringType | ConstantBooleanType | BooleanType | MixedType { if ($name === 'array') { return new ArrayType(new MixedType(), new MixedType()); } diff --git a/rector.php b/rector.php index 9d13cc9a324..d501e4c5e77 100644 --- a/rector.php +++ b/rector.php @@ -86,8 +86,6 @@ return static function (ContainerConfigurator $containerConfigurator): void { SplitStringClassConstantToClassConstFetchRector::class, // to be enabled when all rules for php 8 syntax applied - // PhpVersionFeature::STATIC_RETURN_TYPE - ReturnTypeDeclarationRector::class, RenamePropertyToMatchTypeRector::class, RemoveUnreachableStatementRector::class => [ diff --git a/rules/CodeQuality/Rector/Concat/JoinStringConcatRector.php b/rules/CodeQuality/Rector/Concat/JoinStringConcatRector.php index 382c706789c..f6c5f456136 100644 --- a/rules/CodeQuality/Rector/Concat/JoinStringConcatRector.php +++ b/rules/CodeQuality/Rector/Concat/JoinStringConcatRector.php @@ -6,7 +6,6 @@ namespace Rector\CodeQuality\Rector\Concat; use Nette\Utils\Strings; use PhpParser\Node; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\Concat; use PhpParser\Node\Scalar\String_; use Rector\Core\Rector\AbstractRector; @@ -93,10 +92,7 @@ CODE_SAMPLE return ! $parent instanceof Concat; } - /** - * @return Concat|String_ - */ - private function joinConcatIfStrings(Concat $node): Expr + private function joinConcatIfStrings(Concat $node): Concat | String_ { $concat = clone $node; diff --git a/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php b/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php index 0465f1ffe27..3ee8d863894 100644 --- a/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php +++ b/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php @@ -150,10 +150,7 @@ CODE_SAMPLE return null; } - /** - * @return Identical|Greater - */ - private function resolveCount(bool $isNegated, FuncCall $funcCall): BinaryOp + private function resolveCount(bool $isNegated, FuncCall $funcCall): Identical | Greater { $lNumber = new LNumber(0); @@ -184,10 +181,7 @@ CODE_SAMPLE return new NotIdentical($expr, $array); } - /** - * @return Identical|NotIdentical - */ - private function resolveString(bool $isNegated, Expr $expr): BinaryOp + private function resolveString(bool $isNegated, Expr $expr): Identical | NotIdentical { $string = new String_(''); @@ -199,10 +193,7 @@ CODE_SAMPLE return new NotIdentical($expr, $string); } - /** - * @return Identical|NotIdentical - */ - private function resolveInteger(bool $isNegated, Expr $expr): BinaryOp + private function resolveInteger(bool $isNegated, Expr $expr): Identical | NotIdentical { $lNumber = new LNumber(0); @@ -213,7 +204,7 @@ CODE_SAMPLE return new NotIdentical($expr, $lNumber); } - private function resolveFloat(bool $isNegated, Expr $expr): BinaryOp + private function resolveFloat(bool $isNegated, Expr $expr): Identical | NotIdentical { $dNumber = new DNumber(0.0); @@ -224,10 +215,7 @@ CODE_SAMPLE return new NotIdentical($expr, $dNumber); } - /** - * @return Identical|NotIdentical - */ - private function resolveNullable(bool $isNegated, Expr $expr): BinaryOp + private function resolveNullable(bool $isNegated, Expr $expr): Identical | NotIdentical { $constFetch = $this->nodeFactory->createNull(); diff --git a/rules/CodingStyle/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php b/rules/CodingStyle/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php index 16fd082ff17..b71432a20d0 100644 --- a/rules/CodingStyle/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php +++ b/rules/CodingStyle/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php @@ -129,7 +129,7 @@ CODE_SAMPLE return $expr->name->toString() === 'PHP_VERSION'; } - private function getNewNodeForArg(Expr $expr): Expr + private function getNewNodeForArg(Expr $expr): ConstFetch | LNumber { if ($this->isPhpVersionConstant($expr)) { return new ConstFetch(new Name('PHP_VERSION_ID')); diff --git a/rules/CodingStyle/Rector/PostInc/PostIncDecToPreIncDecRector.php b/rules/CodingStyle/Rector/PostInc/PostIncDecToPreIncDecRector.php index e621d5cd222..54868d18833 100644 --- a/rules/CodingStyle/Rector/PostInc/PostIncDecToPreIncDecRector.php +++ b/rules/CodingStyle/Rector/PostInc/PostIncDecToPreIncDecRector.php @@ -96,10 +96,7 @@ CODE_SAMPLE return $node instanceof Expression; } - /** - * @param PostInc|PostDec $node - */ - private function processPrePost(Node $node): Expr + private function processPrePost(PostInc | PostDec $node): PreInc | PreDec { if ($node instanceof PostInc) { return new PreInc($node->var); @@ -108,10 +105,7 @@ CODE_SAMPLE return new PreDec($node->var); } - /** - * @param PostInc|PostDec $node - */ - private function processPreArray(Node $node, ArrayDimFetch $arrayDimFetch): ?Expr + private function processPreArray(PostInc | PostDec $node, ArrayDimFetch $arrayDimFetch): ?Expr { $parentOfArrayDimFetch = $arrayDimFetch->getAttribute(AttributeKey::PARENT_NODE); if (! $this->isAnExpression($parentOfArrayDimFetch)) { @@ -127,7 +121,7 @@ CODE_SAMPLE /** * @param PostInc|PostDec $node */ - private function processPreFor(Node $node, For_ $for): Expr + private function processPreFor(Node $node, For_ $for): PreDec | PreInc { $for->loop = [$this->processPrePost($node)]; return $for->loop[0]; diff --git a/rules/CodingStyle/ValueObject/NameAndParent.php b/rules/CodingStyle/ValueObject/NameAndParent.php index 6dd73109351..77f49773944 100644 --- a/rules/CodingStyle/ValueObject/NameAndParent.php +++ b/rules/CodingStyle/ValueObject/NameAndParent.php @@ -19,10 +19,7 @@ final class NameAndParent ) { } - /** - * @return Name|Identifier - */ - public function getNameNode(): Node + public function getNameNode(): Identifier | Name { return $this->nameNode; } diff --git a/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php b/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php index ebc1cd5f81c..cfc2a1edb5e 100644 --- a/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php +++ b/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace Rector\DeadCode\Rector\MethodCall; use PhpParser\Node; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Assign; +use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; @@ -136,7 +136,7 @@ CODE_SAMPLE return (array) $classMethod->stmts !== []; } - private function processArrowFunction(ArrowFunction $arrowFunction, MethodCall $methodCall): Expr + private function processArrowFunction(ArrowFunction $arrowFunction, MethodCall $methodCall): MethodCall | ConstFetch { $parentOfParent = $arrowFunction->getAttribute(AttributeKey::PARENT_NODE); if ($parentOfParent instanceof Expression) { diff --git a/rules/Defluent/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php b/rules/Defluent/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php index 3d8460554fd..ce7152bf4e5 100644 --- a/rules/Defluent/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php +++ b/rules/Defluent/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php @@ -9,6 +9,7 @@ use PhpParser\Node\Expr; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\StaticCall; +use PhpParser\Node\Name; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Return_; use PhpParser\NodeFinder; @@ -186,7 +187,7 @@ final class FluentChainMethodCallNodeAnalyzer ->yes(); } - public function resolveRootExpr(MethodCall $methodCall): Node + public function resolveRootExpr(MethodCall $methodCall): Expr | Name { $callerNode = $methodCall->var; diff --git a/rules/DowngradePhp80/Rector/MethodCall/DowngradeNamedArgumentRector.php b/rules/DowngradePhp80/Rector/MethodCall/DowngradeNamedArgumentRector.php index 4e5d6435c83..b754eff502d 100644 --- a/rules/DowngradePhp80/Rector/MethodCall/DowngradeNamedArgumentRector.php +++ b/rules/DowngradePhp80/Rector/MethodCall/DowngradeNamedArgumentRector.php @@ -154,8 +154,11 @@ CODE_SAMPLE * @param MethodCall|StaticCall $node * @param Arg[] $args */ - private function processRemoveNamedArgument(ClassMethod $classMethod, Node $node, array $args): Expr - { + private function processRemoveNamedArgument( + ClassMethod $classMethod, + Node $node, + array $args + ): MethodCall | StaticCall { $params = $classMethod->params; /** @var Arg[] $newArgs */ $newArgs = []; diff --git a/rules/MysqlToMysqli/Rector/FuncCall/MysqlFuncCallToMysqliRector.php b/rules/MysqlToMysqli/Rector/FuncCall/MysqlFuncCallToMysqliRector.php index b8c89bf225e..42f81738b3c 100644 --- a/rules/MysqlToMysqli/Rector/FuncCall/MysqlFuncCallToMysqliRector.php +++ b/rules/MysqlToMysqli/Rector/FuncCall/MysqlFuncCallToMysqliRector.php @@ -102,7 +102,7 @@ CODE_SAMPLE return $funcCall; } - private function joinStringWithNode(string $string, Expr $expr): Expr + private function joinStringWithNode(string $string, Expr $expr): String_ | Concat { if ($expr instanceof String_) { return new String_($string . ' ' . $expr->value); diff --git a/rules/MysqlToMysqli/Rector/FuncCall/MysqlPConnectToMysqliConnectRector.php b/rules/MysqlToMysqli/Rector/FuncCall/MysqlPConnectToMysqliConnectRector.php index c2963edc4a5..c4f7ce4a9a9 100644 --- a/rules/MysqlToMysqli/Rector/FuncCall/MysqlPConnectToMysqliConnectRector.php +++ b/rules/MysqlToMysqli/Rector/FuncCall/MysqlPConnectToMysqliConnectRector.php @@ -74,7 +74,7 @@ CODE_SAMPLE return $node; } - private function joinStringWithNode(string $string, Expr $expr): Expr + private function joinStringWithNode(string $string, Expr $expr): String_ | Concat { if ($expr instanceof String_) { return new String_($string . $expr->value); diff --git a/rules/Naming/ValueObject/VariableAndCallAssign.php b/rules/Naming/ValueObject/VariableAndCallAssign.php index 3a402b292df..22d7a37e937 100644 --- a/rules/Naming/ValueObject/VariableAndCallAssign.php +++ b/rules/Naming/ValueObject/VariableAndCallAssign.php @@ -35,10 +35,7 @@ final class VariableAndCallAssign return $this->variable; } - /** - * @return FuncCall|StaticCall|MethodCall - */ - public function getCall(): Expr + public function getCall(): FuncCall | MethodCall | StaticCall { return $this->call; } @@ -48,10 +45,7 @@ final class VariableAndCallAssign return $this->variableName; } - /** - * @return ClassMethod|Function_|Closure - */ - public function getFunctionLike(): FunctionLike + public function getFunctionLike(): Closure | ClassMethod | Function_ { return $this->functionLike; } diff --git a/rules/Naming/ValueObject/VariableAndCallForeach.php b/rules/Naming/ValueObject/VariableAndCallForeach.php index 169fbafb317..fc9daff3a09 100644 --- a/rules/Naming/ValueObject/VariableAndCallForeach.php +++ b/rules/Naming/ValueObject/VariableAndCallForeach.php @@ -33,10 +33,7 @@ final class VariableAndCallForeach return $this->variable; } - /** - * @return FuncCall|StaticCall|MethodCall - */ - public function getCall(): Expr + public function getCall(): FuncCall | MethodCall | StaticCall { return $this->call; } @@ -46,10 +43,7 @@ final class VariableAndCallForeach return $this->variableName; } - /** - * @return ClassMethod|Function_|Closure - */ - public function getFunctionLike(): FunctionLike + public function getFunctionLike(): Closure | ClassMethod | Function_ { return $this->functionLike; } diff --git a/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php b/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php index b5b33f630fd..3d03a6938bf 100644 --- a/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php +++ b/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php @@ -7,7 +7,6 @@ namespace Rector\Php52\Rector\Switch_; use PhpParser\Node; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar\LNumber; -use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Break_; use PhpParser\Node\Stmt\Continue_; use PhpParser\Node\Stmt\Switch_; @@ -84,7 +83,7 @@ CODE_SAMPLE return $node; } - private function processContinueStatement(Continue_ $continue): Stmt + private function processContinueStatement(Continue_ $continue): Break_ | Continue_ { if ($continue->num === null) { return new Break_(); @@ -102,7 +101,7 @@ CODE_SAMPLE return $continue; } - private function processVariableNum(Continue_ $continue, Variable $numVariable): Stmt + private function processVariableNum(Continue_ $continue, Variable $numVariable): Continue_ | Break_ { $staticType = $this->getStaticType($numVariable); if (! $staticType instanceof ConstantType) { diff --git a/rules/Php70/ValueObject/VariableAssignPair.php b/rules/Php70/ValueObject/VariableAssignPair.php index 6a688dafbfc..80690ce1672 100644 --- a/rules/Php70/ValueObject/VariableAssignPair.php +++ b/rules/Php70/ValueObject/VariableAssignPair.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Rector\Php70\ValueObject; use PhpParser\Node; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\AssignOp; @@ -26,18 +25,12 @@ final class VariableAssignPair ) { } - /** - * @return Variable|ArrayDimFetch|PropertyFetch|StaticPropertyFetch - */ - public function getVariable(): Expr + public function getVariable(): ArrayDimFetch | PropertyFetch | StaticPropertyFetch | Variable { return $this->variable; } - /** - * @return Assign|AssignOp|AssignRef - */ - public function getAssign(): Expr + public function getAssign(): Assign | AssignOp | AssignRef { return $this->assign; } diff --git a/rules/Php80/NodeFactory/StrStartsWithFuncCallFactory.php b/rules/Php80/NodeFactory/StrStartsWithFuncCallFactory.php index f9c1d79dc6f..d10415032c8 100644 --- a/rules/Php80/NodeFactory/StrStartsWithFuncCallFactory.php +++ b/rules/Php80/NodeFactory/StrStartsWithFuncCallFactory.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Rector\Php80\NodeFactory; use PhpParser\Node\Arg; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Name; @@ -13,10 +12,7 @@ use Rector\Php80\ValueObject\StrStartsWith; final class StrStartsWithFuncCallFactory { - /** - * @return FuncCall|BooleanNot - */ - public function createStrStartsWith(StrStartsWith $strStartsWith): Expr + public function createStrStartsWith(StrStartsWith $strStartsWith): FuncCall | BooleanNot { $args = [new Arg($strStartsWith->getHaystackExpr()), new Arg($strStartsWith->getNeedleExpr())]; diff --git a/rules/Php80/NodeManipulator/TokenManipulator.php b/rules/Php80/NodeManipulator/TokenManipulator.php index 3e7a3b7f8ec..867c42c6d46 100644 --- a/rules/Php80/NodeManipulator/TokenManipulator.php +++ b/rules/Php80/NodeManipulator/TokenManipulator.php @@ -297,7 +297,7 @@ final class TokenManipulator return false; } - private function matchParentNodeInCaseOfIdenticalTrue(FuncCall $funcCall): Expr + private function matchParentNodeInCaseOfIdenticalTrue(FuncCall $funcCall): Identical | FuncCall { $parentNode = $funcCall->getAttribute(AttributeKey::PARENT_NODE); if ($parentNode instanceof Identical) { diff --git a/rules/Transform/NodeAnalyzer/FuncCallStaticCallToMethodCallAnalyzer.php b/rules/Transform/NodeAnalyzer/FuncCallStaticCallToMethodCallAnalyzer.php index d36580707bd..9b21dc7aa49 100644 --- a/rules/Transform/NodeAnalyzer/FuncCallStaticCallToMethodCallAnalyzer.php +++ b/rules/Transform/NodeAnalyzer/FuncCallStaticCallToMethodCallAnalyzer.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Rector\Transform\NodeAnalyzer; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\Variable; @@ -34,10 +33,12 @@ final class FuncCallStaticCallToMethodCallAnalyzer /** * @param ClassMethod|Function_ $functionLike - * @return MethodCall|PropertyFetch|Variable */ - public function matchTypeProvidingExpr(Class_ $class, FunctionLike $functionLike, ObjectType $objectType): Expr - { + public function matchTypeProvidingExpr( + Class_ $class, + FunctionLike $functionLike, + ObjectType $objectType + ): MethodCall | PropertyFetch | Variable { $expr = $this->typeProvidingExprFromClassResolver->resolveTypeProvidingExprFromClass( $class, $functionLike, diff --git a/rules/Transform/Rector/FileWithoutNamespace/FunctionToStaticMethodRector.php b/rules/Transform/Rector/FileWithoutNamespace/FunctionToStaticMethodRector.php index f36f82ed281..a69af17f2f2 100644 --- a/rules/Transform/Rector/FileWithoutNamespace/FunctionToStaticMethodRector.php +++ b/rules/Transform/Rector/FileWithoutNamespace/FunctionToStaticMethodRector.php @@ -7,7 +7,6 @@ namespace Rector\Transform\Rector\FileWithoutNamespace; use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\StaticCall; -use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\Namespace_; @@ -173,9 +172,8 @@ CODE_SAMPLE /** * @param Namespace_|FileWithoutNamespace $node - * @return Namespace_|Class_ */ - private function resolveNodeToPrint(Node $node, Class_ $class): Stmt + private function resolveNodeToPrint(Node $node, Class_ $class): Namespace_ | Class_ { if ($node instanceof Namespace_) { return new Namespace_($node->name, [$class]); diff --git a/rules/Transform/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php b/rules/Transform/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php index 70ee2de98de..f584876721d 100644 --- a/rules/Transform/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php +++ b/rules/Transform/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Rector\Transform\Rector\FuncCall; use PhpParser\Node; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\PropertyFetch; @@ -224,13 +223,10 @@ CODE_SAMPLE ); } - /** - * @return PropertyFetch|MethodCall - */ private function refactorEmptyFuncCallArgs( ArgumentFuncCallToMethodCall $argumentFuncCallToMethodCall, PropertyFetch $propertyFetch - ): Expr { + ): MethodCall | PropertyFetch { if ($argumentFuncCallToMethodCall->getMethodIfNoArgs()) { $methodName = $argumentFuncCallToMethodCall->getMethodIfNoArgs(); if (! is_string($methodName)) { diff --git a/rules/TypeDeclaration/PHPStan/Type/ObjectTypeSpecifier.php b/rules/TypeDeclaration/PHPStan/Type/ObjectTypeSpecifier.php index 9b9d52dfa1b..21ee2cec27a 100644 --- a/rules/TypeDeclaration/PHPStan/Type/ObjectTypeSpecifier.php +++ b/rules/TypeDeclaration/PHPStan/Type/ObjectTypeSpecifier.php @@ -14,7 +14,6 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; -use PHPStan\Type\SubtractableType; use PHPStan\Type\Type; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType; @@ -31,8 +30,10 @@ final class ObjectTypeSpecifier /** * @return AliasedObjectType|FullyQualifiedObjectType|ObjectType|MixedType */ - public function narrowToFullyQualifiedOrAliasedObjectType(Node $node, ObjectType $objectType): SubtractableType - { + public function narrowToFullyQualifiedOrAliasedObjectType( + Node $node, + ObjectType $objectType + ): ObjectType | AliasedObjectType | ShortenedObjectType | FullyQualifiedObjectType | MixedType { /** @var Use_[]|null $uses */ $uses = $node->getAttribute(AttributeKey::USE_NODES); if ($uses === null) { diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php index 315cf1878c7..e37f4ea5529 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php @@ -9,7 +9,6 @@ use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; -use PhpParser\Node\FunctionLike; use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; @@ -121,8 +120,11 @@ CODE_SAMPLE /** * @param ClassMethod|Function_|Closure $node */ - private function processSingleUnionType(Node $node, UnionType $unionType, NullableType $nullableType): FunctionLike - { + private function processSingleUnionType( + Node $node, + UnionType $unionType, + NullableType $nullableType + ): Closure | ClassMethod | Function_ { $types = $unionType->getTypes(); $returnType = $types[0] instanceof ObjectType && $types[1] instanceof NullType ? new NullableType(new FullyQualified($types[0]->getClassName())) @@ -224,7 +226,7 @@ CODE_SAMPLE Return_ $return, Identifier | Name | NullableType | PhpParserUnionType $returnedStrictTypeNode, ClassMethod | Function_ | Closure $functionLike - ): FunctionLike { + ): Closure | ClassMethod | Function_ { $resolvedType = $this->nodeTypeResolver->resolve($return); if ($resolvedType instanceof UnionType) { diff --git a/rules/TypeDeclaration/TypeInferer/ParamTypeInferer/PHPUnitDataProviderParamTypeInferer.php b/rules/TypeDeclaration/TypeInferer/ParamTypeInferer/PHPUnitDataProviderParamTypeInferer.php index 5e4eeedbd22..6467d42c7b1 100644 --- a/rules/TypeDeclaration/TypeInferer/ParamTypeInferer/PHPUnitDataProviderParamTypeInferer.php +++ b/rules/TypeDeclaration/TypeInferer/ParamTypeInferer/PHPUnitDataProviderParamTypeInferer.php @@ -157,7 +157,7 @@ final class PHPUnitDataProviderParamTypeInferer implements ParamTypeInfererInter return $this->typeFactory->createMixedPassedOrUnionType($paramOnPositionTypes); } - private function getTypeFromClassMethodYield(Array_ $classMethodYieldArrayNode): Type + private function getTypeFromClassMethodYield(Array_ $classMethodYieldArrayNode): MixedType | ConstantArrayType { $arrayTypes = $this->nodeTypeResolver->resolve($classMethodYieldArrayNode); diff --git a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInferer.php b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInferer.php index 5fbae522538..3d988b0e2d7 100644 --- a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInferer.php +++ b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInferer.php @@ -109,7 +109,7 @@ final class ReturnedNodesReturnTypeInferer implements ReturnTypeInfererInterface return $returns; } - private function resolveNoLocalReturnNodes(ClassLike $classLike, FunctionLike $functionLike): Type + private function resolveNoLocalReturnNodes(ClassLike $classLike, FunctionLike $functionLike): VoidType | MixedType { // void type if (! $this->isAbstractMethod($classLike, $functionLike)) { diff --git a/rules/TypeDeclaration/TypeNormalizer.php b/rules/TypeDeclaration/TypeNormalizer.php index 7ad1df84743..16801cdb020 100644 --- a/rules/TypeDeclaration/TypeNormalizer.php +++ b/rules/TypeDeclaration/TypeNormalizer.php @@ -145,7 +145,7 @@ final class TypeNormalizer /** * @param NestedArrayType[] $collectedNestedArrayTypes */ - private function createUnionedTypesFromArrayTypes(array $collectedNestedArrayTypes): Type + private function createUnionedTypesFromArrayTypes(array $collectedNestedArrayTypes): UnionType | ArrayType { $unionedTypes = []; foreach ($collectedNestedArrayTypes as $collectedNestedArrayType) { diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index b91b422d5c1..29bfe17e38e 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -409,7 +409,7 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn return $currentArgs; } - protected function unwrapExpression(Stmt $stmt): Node + protected function unwrapExpression(Stmt $stmt): Expr | Stmt { if ($stmt instanceof Expression) { return $stmt->expr;