[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;
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<mixed>
*/
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<mixed, mixed>
* @return array<mixed>
*/
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)) {
$items = $this->arrayParser->parseCurlyArray($tokenIterator);
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();
// temporary hackaround multi-line doctrine annotations

View File

@ -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

View File

@ -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();

View File

@ -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) {

View File

@ -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 = [];

View File

@ -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);

View File

@ -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());
}

View File

@ -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 => [

View File

@ -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;

View File

@ -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();

View File

@ -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'));

View File

@ -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];

View File

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

View File

@ -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) {

View File

@ -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;

View File

@ -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 = [];

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;
}

View File

@ -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())];

View File

@ -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) {

View File

@ -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,

View File

@ -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]);

View File

@ -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)) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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);

View File

@ -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)) {

View File

@ -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) {

View File

@ -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;