[TypeDeclaration][Php 8] Enable ReturnTypeDeclarationRector (#184)

Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Tomas Votruba <tomas.vot@gmail.com>
This commit is contained in:
Abdul Malik Ikhsan 2021-06-19 00:19:36 +07:00 committed by GitHub
parent e783801584
commit dce60231f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 83 additions and 133 deletions

View File

@ -4,7 +4,11 @@ declare(strict_types=1);
namespace Rector\BetterPhpDocParser\PhpDocParser; 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 PHPStan\PhpDocParser\Lexer\Lexer;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\ArrayParser; use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\ArrayParser;
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\PlainValueParser; use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\PlainValueParser;
use Rector\BetterPhpDocParser\ValueObject\Parser\BetterTokenIterator; 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 * @see https://github.com/doctrine/annotations/blob/c66f06b7c83e9a2a7523351a9d5a4b55f885e574/lib/Doctrine/Common/Annotations/DocParser.php#L1215-L1224
* @return mixed|mixed[] * @return array<mixed>
*/ */
public function resolveAnnotationValue(BetterTokenIterator $tokenIterator) public function resolveAnnotationValue(
{ BetterTokenIterator $tokenIterator
): CurlyListNode | string | array | ConstExprFalseNode | ConstExprTrueNode | ConstExprIntegerNode | DoctrineAnnotationTagValueNode {
// skips dummy tokens like newlines // skips dummy tokens like newlines
$tokenIterator->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL); $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 // 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); $key = $this->parseValue($tokenIterator);
$tokenIterator->consumeTokenType(Lexer::TOKEN_EQUAL); $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 * @see https://github.com/doctrine/annotations/blob/c66f06b7c83e9a2a7523351a9d5a4b55f885e574/lib/Doctrine/Common/Annotations/DocParser.php#L1051-L1079
* @return array<mixed, mixed> * @return array<mixed>
*/ */
private function resolveAnnotationValues(BetterTokenIterator $tokenIterator): array private function resolveAnnotationValues(BetterTokenIterator $tokenIterator): array
{ {
@ -101,10 +107,11 @@ final class StaticDoctrineAnnotationParser
} }
/** /**
* @return bool|int|mixed|mixed[]|string * @return array<mixed>
*/ */
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)) { if ($tokenIterator->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET)) {
$items = $this->arrayParser->parseCurlyArray($tokenIterator); $items = $this->arrayParser->parseCurlyArray($tokenIterator);
return new CurlyListNode($items); return new CurlyListNode($items);

View File

@ -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(); $currentTokenValue = $tokenIterator->currentTokenValue();
// temporary hackaround multi-line doctrine annotations // temporary hackaround multi-line doctrine annotations

View File

@ -471,9 +471,8 @@ final class NodeRepository
return; return;
} }
$this->arrayCallablesByTypeAndMethod[$arrayCallable->getClass()][strtolower( $methodName = strtolower($arrayCallable->getMethod());
$arrayCallable->getMethod() $this->arrayCallablesByTypeAndMethod[$arrayCallable->getClass()][$methodName][] = $arrayCallable;
)][] = $arrayCallable;
} }
private function addMethod(ClassMethod $classMethod): void private function addMethod(ClassMethod $classMethod): void

View File

@ -10,11 +10,10 @@ use PHPStan\Type\FloatType;
use PHPStan\Type\IntegerType; use PHPStan\Type\IntegerType;
use PHPStan\Type\MixedType; use PHPStan\Type\MixedType;
use PHPStan\Type\StringType; use PHPStan\Type\StringType;
use PHPStan\Type\Type;
final class IdentifierTypeResolver final class IdentifierTypeResolver
{ {
public function resolve(Identifier $identifier): Type public function resolve(Identifier $identifier): StringType | BooleanType | IntegerType | FloatType | MixedType
{ {
if ($identifier->toLowerString() === 'string') { if ($identifier->toLowerString() === 'string') {
return new StringType(); return new StringType();

View File

@ -46,10 +46,7 @@ final class NameTypeResolver implements NodeTypeResolverInterface
return new ObjectType($fullyQualifiedName); return new ObjectType($fullyQualifiedName);
} }
/** private function resolveParent(Name $name): MixedType | ObjectType | UnionType
* @return ObjectType|UnionType|MixedType
*/
private function resolveParent(Name $name): Type
{ {
$className = $name->getAttribute(AttributeKey::CLASS_NAME); $className = $name->getAttribute(AttributeKey::CLASS_NAME);
if ($className === null) { if ($className === null) {

View File

@ -16,7 +16,6 @@ use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\Generic\GenericClassStringType; use PHPStan\Type\Generic\GenericClassStringType;
use PHPStan\Type\ObjectType; use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType; use PHPStan\Type\UnionType;
use Rector\Core\Contract\Rector\RectorInterface; use Rector\Core\Contract\Rector\RectorInterface;
use Rector\NodeTypeResolver\NodeTypeCorrector\GenericClassStringTypeCorrector; use Rector\NodeTypeResolver\NodeTypeCorrector\GenericClassStringTypeCorrector;
@ -64,10 +63,7 @@ final class UnionTypeCommonTypeNarrower
return null; return null;
} }
/** public function narrowToGenericClassStringType(UnionType $unionType): UnionType | GenericClassStringType
* @return GenericClassStringType|UnionType
*/
public function narrowToGenericClassStringType(UnionType $unionType): Type
{ {
$availableTypes = []; $availableTypes = [];

View File

@ -13,7 +13,6 @@ use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType; use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType; use PHPStan\Type\ObjectType;
use PHPStan\Type\StaticType; use PHPStan\Type\StaticType;
use PHPStan\Type\SubtractableType;
use PHPStan\Type\Type; use PHPStan\Type\Type;
use Rector\NodeCollector\ScopeResolver\ParentClassScopeResolver; use Rector\NodeCollector\ScopeResolver\ParentClassScopeResolver;
use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\Node\AttributeKey;
@ -81,7 +80,7 @@ final class IdentifierTypeMapper implements PhpDocTypeMapperInterface
return $this->objectTypeSpecifier->narrowToFullyQualifiedOrAliasedObjectType($node, $objectType); return $this->objectTypeSpecifier->narrowToFullyQualifiedOrAliasedObjectType($node, $objectType);
} }
private function mapSelf(Node $node): SubtractableType private function mapSelf(Node $node): MixedType | SelfObjectType
{ {
/** @var string|null $className */ /** @var string|null $className */
$className = $node->getAttribute(AttributeKey::CLASS_NAME); $className = $node->getAttribute(AttributeKey::CLASS_NAME);
@ -93,7 +92,7 @@ final class IdentifierTypeMapper implements PhpDocTypeMapperInterface
return new SelfObjectType($className); return new SelfObjectType($className);
} }
private function mapParent(Node $node): Type private function mapParent(Node $node): ParentStaticType | MixedType
{ {
$parentClassName = $this->parentClassScopeResolver->resolveParentClassName($node); $parentClassName = $this->parentClassScopeResolver->resolveParentClassName($node);
if ($parentClassName !== null) { if ($parentClassName !== null) {
@ -103,7 +102,7 @@ final class IdentifierTypeMapper implements PhpDocTypeMapperInterface
return new MixedType(); return new MixedType();
} }
private function mapStatic(Node $node): Type private function mapStatic(Node $node): MixedType | StaticType
{ {
/** @var string|null $className */ /** @var string|null $className */
$className = $node->getAttribute(AttributeKey::CLASS_NAME); $className = $node->getAttribute(AttributeKey::CLASS_NAME);

View File

@ -67,7 +67,7 @@ final class NameNodeMapper implements PhpParserNodeMapperInterface
return in_array($name, $oldToNewClasses, true); 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); $className = $name->getAttribute(AttributeKey::CLASS_NAME);
if ($className === null) { if ($className === null) {
@ -86,8 +86,9 @@ final class NameNodeMapper implements PhpParserNodeMapperInterface
return new ThisType($className); 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') { if ($name === 'array') {
return new ArrayType(new MixedType(), new MixedType()); return new ArrayType(new MixedType(), new MixedType());
} }

View File

@ -86,8 +86,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
SplitStringClassConstantToClassConstFetchRector::class, SplitStringClassConstantToClassConstFetchRector::class,
// to be enabled when all rules for php 8 syntax applied // to be enabled when all rules for php 8 syntax applied
// PhpVersionFeature::STATIC_RETURN_TYPE
ReturnTypeDeclarationRector::class,
RenamePropertyToMatchTypeRector::class, RenamePropertyToMatchTypeRector::class,
RemoveUnreachableStatementRector::class => [ RemoveUnreachableStatementRector::class => [

View File

@ -6,7 +6,6 @@ namespace Rector\CodeQuality\Rector\Concat;
use Nette\Utils\Strings; use Nette\Utils\Strings;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Concat; use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Scalar\String_; use PhpParser\Node\Scalar\String_;
use Rector\Core\Rector\AbstractRector; use Rector\Core\Rector\AbstractRector;
@ -93,10 +92,7 @@ CODE_SAMPLE
return ! $parent instanceof Concat; return ! $parent instanceof Concat;
} }
/** private function joinConcatIfStrings(Concat $node): Concat | String_
* @return Concat|String_
*/
private function joinConcatIfStrings(Concat $node): Expr
{ {
$concat = clone $node; $concat = clone $node;

View File

@ -150,10 +150,7 @@ CODE_SAMPLE
return null; return null;
} }
/** private function resolveCount(bool $isNegated, FuncCall $funcCall): Identical | Greater
* @return Identical|Greater
*/
private function resolveCount(bool $isNegated, FuncCall $funcCall): BinaryOp
{ {
$lNumber = new LNumber(0); $lNumber = new LNumber(0);
@ -184,10 +181,7 @@ CODE_SAMPLE
return new NotIdentical($expr, $array); return new NotIdentical($expr, $array);
} }
/** private function resolveString(bool $isNegated, Expr $expr): Identical | NotIdentical
* @return Identical|NotIdentical
*/
private function resolveString(bool $isNegated, Expr $expr): BinaryOp
{ {
$string = new String_(''); $string = new String_('');
@ -199,10 +193,7 @@ CODE_SAMPLE
return new NotIdentical($expr, $string); return new NotIdentical($expr, $string);
} }
/** private function resolveInteger(bool $isNegated, Expr $expr): Identical | NotIdentical
* @return Identical|NotIdentical
*/
private function resolveInteger(bool $isNegated, Expr $expr): BinaryOp
{ {
$lNumber = new LNumber(0); $lNumber = new LNumber(0);
@ -213,7 +204,7 @@ CODE_SAMPLE
return new NotIdentical($expr, $lNumber); 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); $dNumber = new DNumber(0.0);
@ -224,10 +215,7 @@ CODE_SAMPLE
return new NotIdentical($expr, $dNumber); return new NotIdentical($expr, $dNumber);
} }
/** private function resolveNullable(bool $isNegated, Expr $expr): Identical | NotIdentical
* @return Identical|NotIdentical
*/
private function resolveNullable(bool $isNegated, Expr $expr): BinaryOp
{ {
$constFetch = $this->nodeFactory->createNull(); $constFetch = $this->nodeFactory->createNull();

View File

@ -129,7 +129,7 @@ CODE_SAMPLE
return $expr->name->toString() === 'PHP_VERSION'; return $expr->name->toString() === 'PHP_VERSION';
} }
private function getNewNodeForArg(Expr $expr): Expr private function getNewNodeForArg(Expr $expr): ConstFetch | LNumber
{ {
if ($this->isPhpVersionConstant($expr)) { if ($this->isPhpVersionConstant($expr)) {
return new ConstFetch(new Name('PHP_VERSION_ID')); return new ConstFetch(new Name('PHP_VERSION_ID'));

View File

@ -96,10 +96,7 @@ CODE_SAMPLE
return $node instanceof Expression; return $node instanceof Expression;
} }
/** private function processPrePost(PostInc | PostDec $node): PreInc | PreDec
* @param PostInc|PostDec $node
*/
private function processPrePost(Node $node): Expr
{ {
if ($node instanceof PostInc) { if ($node instanceof PostInc) {
return new PreInc($node->var); return new PreInc($node->var);
@ -108,10 +105,7 @@ CODE_SAMPLE
return new PreDec($node->var); return new PreDec($node->var);
} }
/** private function processPreArray(PostInc | PostDec $node, ArrayDimFetch $arrayDimFetch): ?Expr
* @param PostInc|PostDec $node
*/
private function processPreArray(Node $node, ArrayDimFetch $arrayDimFetch): ?Expr
{ {
$parentOfArrayDimFetch = $arrayDimFetch->getAttribute(AttributeKey::PARENT_NODE); $parentOfArrayDimFetch = $arrayDimFetch->getAttribute(AttributeKey::PARENT_NODE);
if (! $this->isAnExpression($parentOfArrayDimFetch)) { if (! $this->isAnExpression($parentOfArrayDimFetch)) {
@ -127,7 +121,7 @@ CODE_SAMPLE
/** /**
* @param PostInc|PostDec $node * @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)]; $for->loop = [$this->processPrePost($node)];
return $for->loop[0]; return $for->loop[0];

View File

@ -19,10 +19,7 @@ final class NameAndParent
) { ) {
} }
/** public function getNameNode(): Identifier | Name
* @return Name|Identifier
*/
public function getNameNode(): Node
{ {
return $this->nameNode; return $this->nameNode;
} }

View File

@ -5,9 +5,9 @@ declare(strict_types=1);
namespace Rector\DeadCode\Rector\MethodCall; namespace Rector\DeadCode\Rector\MethodCall;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\ClassMethod;
@ -136,7 +136,7 @@ CODE_SAMPLE
return (array) $classMethod->stmts !== []; 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); $parentOfParent = $arrowFunction->getAttribute(AttributeKey::PARENT_NODE);
if ($parentOfParent instanceof Expression) { if ($parentOfParent instanceof Expression) {

View File

@ -9,6 +9,7 @@ use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Return_;
use PhpParser\NodeFinder; use PhpParser\NodeFinder;
@ -186,7 +187,7 @@ final class FluentChainMethodCallNodeAnalyzer
->yes(); ->yes();
} }
public function resolveRootExpr(MethodCall $methodCall): Node public function resolveRootExpr(MethodCall $methodCall): Expr | Name
{ {
$callerNode = $methodCall->var; $callerNode = $methodCall->var;

View File

@ -154,8 +154,11 @@ CODE_SAMPLE
* @param MethodCall|StaticCall $node * @param MethodCall|StaticCall $node
* @param Arg[] $args * @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; $params = $classMethod->params;
/** @var Arg[] $newArgs */ /** @var Arg[] $newArgs */
$newArgs = []; $newArgs = [];

View File

@ -102,7 +102,7 @@ CODE_SAMPLE
return $funcCall; return $funcCall;
} }
private function joinStringWithNode(string $string, Expr $expr): Expr private function joinStringWithNode(string $string, Expr $expr): String_ | Concat
{ {
if ($expr instanceof String_) { if ($expr instanceof String_) {
return new String_($string . ' ' . $expr->value); return new String_($string . ' ' . $expr->value);

View File

@ -74,7 +74,7 @@ CODE_SAMPLE
return $node; return $node;
} }
private function joinStringWithNode(string $string, Expr $expr): Expr private function joinStringWithNode(string $string, Expr $expr): String_ | Concat
{ {
if ($expr instanceof String_) { if ($expr instanceof String_) {
return new String_($string . $expr->value); return new String_($string . $expr->value);

View File

@ -35,10 +35,7 @@ final class VariableAndCallAssign
return $this->variable; return $this->variable;
} }
/** public function getCall(): FuncCall | MethodCall | StaticCall
* @return FuncCall|StaticCall|MethodCall
*/
public function getCall(): Expr
{ {
return $this->call; return $this->call;
} }
@ -48,10 +45,7 @@ final class VariableAndCallAssign
return $this->variableName; return $this->variableName;
} }
/** public function getFunctionLike(): Closure | ClassMethod | Function_
* @return ClassMethod|Function_|Closure
*/
public function getFunctionLike(): FunctionLike
{ {
return $this->functionLike; return $this->functionLike;
} }

View File

@ -33,10 +33,7 @@ final class VariableAndCallForeach
return $this->variable; return $this->variable;
} }
/** public function getCall(): FuncCall | MethodCall | StaticCall
* @return FuncCall|StaticCall|MethodCall
*/
public function getCall(): Expr
{ {
return $this->call; return $this->call;
} }
@ -46,10 +43,7 @@ final class VariableAndCallForeach
return $this->variableName; return $this->variableName;
} }
/** public function getFunctionLike(): Closure | ClassMethod | Function_
* @return ClassMethod|Function_|Closure
*/
public function getFunctionLike(): FunctionLike
{ {
return $this->functionLike; return $this->functionLike;
} }

View File

@ -7,7 +7,6 @@ namespace Rector\Php52\Rector\Switch_;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Break_; use PhpParser\Node\Stmt\Break_;
use PhpParser\Node\Stmt\Continue_; use PhpParser\Node\Stmt\Continue_;
use PhpParser\Node\Stmt\Switch_; use PhpParser\Node\Stmt\Switch_;
@ -84,7 +83,7 @@ CODE_SAMPLE
return $node; return $node;
} }
private function processContinueStatement(Continue_ $continue): Stmt private function processContinueStatement(Continue_ $continue): Break_ | Continue_
{ {
if ($continue->num === null) { if ($continue->num === null) {
return new Break_(); return new Break_();
@ -102,7 +101,7 @@ CODE_SAMPLE
return $continue; return $continue;
} }
private function processVariableNum(Continue_ $continue, Variable $numVariable): Stmt private function processVariableNum(Continue_ $continue, Variable $numVariable): Continue_ | Break_
{ {
$staticType = $this->getStaticType($numVariable); $staticType = $this->getStaticType($numVariable);
if (! $staticType instanceof ConstantType) { if (! $staticType instanceof ConstantType) {

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Php70\ValueObject; namespace Rector\Php70\ValueObject;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\AssignOp; use PhpParser\Node\Expr\AssignOp;
@ -26,18 +25,12 @@ final class VariableAssignPair
) { ) {
} }
/** public function getVariable(): ArrayDimFetch | PropertyFetch | StaticPropertyFetch | Variable
* @return Variable|ArrayDimFetch|PropertyFetch|StaticPropertyFetch
*/
public function getVariable(): Expr
{ {
return $this->variable; return $this->variable;
} }
/** public function getAssign(): Assign | AssignOp | AssignRef
* @return Assign|AssignOp|AssignRef
*/
public function getAssign(): Expr
{ {
return $this->assign; return $this->assign;
} }

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Php80\NodeFactory; namespace Rector\Php80\NodeFactory;
use PhpParser\Node\Arg; use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name; use PhpParser\Node\Name;
@ -13,10 +12,7 @@ use Rector\Php80\ValueObject\StrStartsWith;
final class StrStartsWithFuncCallFactory final class StrStartsWithFuncCallFactory
{ {
/** public function createStrStartsWith(StrStartsWith $strStartsWith): FuncCall | BooleanNot
* @return FuncCall|BooleanNot
*/
public function createStrStartsWith(StrStartsWith $strStartsWith): Expr
{ {
$args = [new Arg($strStartsWith->getHaystackExpr()), new Arg($strStartsWith->getNeedleExpr())]; $args = [new Arg($strStartsWith->getHaystackExpr()), new Arg($strStartsWith->getNeedleExpr())];

View File

@ -297,7 +297,7 @@ final class TokenManipulator
return false; return false;
} }
private function matchParentNodeInCaseOfIdenticalTrue(FuncCall $funcCall): Expr private function matchParentNodeInCaseOfIdenticalTrue(FuncCall $funcCall): Identical | FuncCall
{ {
$parentNode = $funcCall->getAttribute(AttributeKey::PARENT_NODE); $parentNode = $funcCall->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof Identical) { if ($parentNode instanceof Identical) {

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Rector\Transform\NodeAnalyzer; namespace Rector\Transform\NodeAnalyzer;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
@ -34,10 +33,12 @@ final class FuncCallStaticCallToMethodCallAnalyzer
/** /**
* @param ClassMethod|Function_ $functionLike * @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( $expr = $this->typeProvidingExprFromClassResolver->resolveTypeProvidingExprFromClass(
$class, $class,
$functionLike, $functionLike,

View File

@ -7,7 +7,6 @@ namespace Rector\Transform\Rector\FileWithoutNamespace;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Namespace_; use PhpParser\Node\Stmt\Namespace_;
@ -173,9 +172,8 @@ CODE_SAMPLE
/** /**
* @param Namespace_|FileWithoutNamespace $node * @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_) { if ($node instanceof Namespace_) {
return new Namespace_($node->name, [$class]); return new Namespace_($node->name, [$class]);

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Transform\Rector\FuncCall; namespace Rector\Transform\Rector\FuncCall;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\PropertyFetch;
@ -224,13 +223,10 @@ CODE_SAMPLE
); );
} }
/**
* @return PropertyFetch|MethodCall
*/
private function refactorEmptyFuncCallArgs( private function refactorEmptyFuncCallArgs(
ArgumentFuncCallToMethodCall $argumentFuncCallToMethodCall, ArgumentFuncCallToMethodCall $argumentFuncCallToMethodCall,
PropertyFetch $propertyFetch PropertyFetch $propertyFetch
): Expr { ): MethodCall | PropertyFetch {
if ($argumentFuncCallToMethodCall->getMethodIfNoArgs()) { if ($argumentFuncCallToMethodCall->getMethodIfNoArgs()) {
$methodName = $argumentFuncCallToMethodCall->getMethodIfNoArgs(); $methodName = $argumentFuncCallToMethodCall->getMethodIfNoArgs();
if (! is_string($methodName)) { if (! is_string($methodName)) {

View File

@ -14,7 +14,6 @@ use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider; use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\MixedType; use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType; use PHPStan\Type\ObjectType;
use PHPStan\Type\SubtractableType;
use PHPStan\Type\Type; use PHPStan\Type\Type;
use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType; use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
@ -31,8 +30,10 @@ final class ObjectTypeSpecifier
/** /**
* @return AliasedObjectType|FullyQualifiedObjectType|ObjectType|MixedType * @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 */ /** @var Use_[]|null $uses */
$uses = $node->getAttribute(AttributeKey::USE_NODES); $uses = $node->getAttribute(AttributeKey::USE_NODES);
if ($uses === null) { if ($uses === null) {

View File

@ -9,7 +9,6 @@ use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
use PhpParser\Node\Name; use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Name\FullyQualified;
@ -121,8 +120,11 @@ CODE_SAMPLE
/** /**
* @param ClassMethod|Function_|Closure $node * @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(); $types = $unionType->getTypes();
$returnType = $types[0] instanceof ObjectType && $types[1] instanceof NullType $returnType = $types[0] instanceof ObjectType && $types[1] instanceof NullType
? new NullableType(new FullyQualified($types[0]->getClassName())) ? new NullableType(new FullyQualified($types[0]->getClassName()))
@ -224,7 +226,7 @@ CODE_SAMPLE
Return_ $return, Return_ $return,
Identifier | Name | NullableType | PhpParserUnionType $returnedStrictTypeNode, Identifier | Name | NullableType | PhpParserUnionType $returnedStrictTypeNode,
ClassMethod | Function_ | Closure $functionLike ClassMethod | Function_ | Closure $functionLike
): FunctionLike { ): Closure | ClassMethod | Function_ {
$resolvedType = $this->nodeTypeResolver->resolve($return); $resolvedType = $this->nodeTypeResolver->resolve($return);
if ($resolvedType instanceof UnionType) { if ($resolvedType instanceof UnionType) {

View File

@ -157,7 +157,7 @@ final class PHPUnitDataProviderParamTypeInferer implements ParamTypeInfererInter
return $this->typeFactory->createMixedPassedOrUnionType($paramOnPositionTypes); return $this->typeFactory->createMixedPassedOrUnionType($paramOnPositionTypes);
} }
private function getTypeFromClassMethodYield(Array_ $classMethodYieldArrayNode): Type private function getTypeFromClassMethodYield(Array_ $classMethodYieldArrayNode): MixedType | ConstantArrayType
{ {
$arrayTypes = $this->nodeTypeResolver->resolve($classMethodYieldArrayNode); $arrayTypes = $this->nodeTypeResolver->resolve($classMethodYieldArrayNode);

View File

@ -109,7 +109,7 @@ final class ReturnedNodesReturnTypeInferer implements ReturnTypeInfererInterface
return $returns; return $returns;
} }
private function resolveNoLocalReturnNodes(ClassLike $classLike, FunctionLike $functionLike): Type private function resolveNoLocalReturnNodes(ClassLike $classLike, FunctionLike $functionLike): VoidType | MixedType
{ {
// void type // void type
if (! $this->isAbstractMethod($classLike, $functionLike)) { if (! $this->isAbstractMethod($classLike, $functionLike)) {

View File

@ -145,7 +145,7 @@ final class TypeNormalizer
/** /**
* @param NestedArrayType[] $collectedNestedArrayTypes * @param NestedArrayType[] $collectedNestedArrayTypes
*/ */
private function createUnionedTypesFromArrayTypes(array $collectedNestedArrayTypes): Type private function createUnionedTypesFromArrayTypes(array $collectedNestedArrayTypes): UnionType | ArrayType
{ {
$unionedTypes = []; $unionedTypes = [];
foreach ($collectedNestedArrayTypes as $collectedNestedArrayType) { foreach ($collectedNestedArrayTypes as $collectedNestedArrayType) {

View File

@ -409,7 +409,7 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn
return $currentArgs; return $currentArgs;
} }
protected function unwrapExpression(Stmt $stmt): Node protected function unwrapExpression(Stmt $stmt): Expr | Stmt
{ {
if ($stmt instanceof Expression) { if ($stmt instanceof Expression) {
return $stmt->expr; return $stmt->expr;