mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-20 23:41:57 +02:00
Updated Rector to commit a11fc615d18396cef284c18de269711114630676
a11fc615d1
[TypeDeclaration] Remove only void type on ReturnedNodesReturnTypeInfererTypeInferer (#6340)
This commit is contained in:
parent
a5a5200e52
commit
b86f33859b
@ -63,7 +63,7 @@ final class AddReturnTypeFromCast
|
||||
return null;
|
||||
}
|
||||
$returnType = $this->returnTypeInferer->inferFunctionLike($functionLike);
|
||||
if ($returnType instanceof UnionType || $returnType->isVoid()->yes()) {
|
||||
if ($returnType instanceof UnionType) {
|
||||
return null;
|
||||
}
|
||||
$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($returnType, TypeKind::RETURN);
|
||||
|
@ -6,10 +6,7 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\Yield_;
|
||||
use PhpParser\Node\Expr\YieldFrom;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Type\Type;
|
||||
@ -103,9 +100,6 @@ CODE_SAMPLE
|
||||
if ($node->returnType instanceof Node) {
|
||||
return null;
|
||||
}
|
||||
if ($this->hasYield($node)) {
|
||||
return null;
|
||||
}
|
||||
$returns = $this->betterNodeFinder->findReturnsScoped($node);
|
||||
if (!$this->returnAnalyzer->hasOnlyReturnWithExpr($node, $returns)) {
|
||||
return null;
|
||||
@ -145,11 +139,4 @@ CODE_SAMPLE
|
||||
}
|
||||
return $this->typeFactory->createMixedPassedOrUnionType($classConstFetchTypes);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
private function hasYield($functionLike) : bool
|
||||
{
|
||||
return $this->betterNodeFinder->hasInstancesOfInFunctionLikeScoped($functionLike, [Yield_::class, YieldFrom::class]);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ namespace Rector\TypeDeclaration\Rector\Closure;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PHPStan\Type\NeverType;
|
||||
use PHPStan\Type\VoidType;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
@ -67,7 +66,7 @@ CODE_SAMPLE
|
||||
}
|
||||
$closureReturnType = $this->returnTypeInferer->inferFunctionLike($node);
|
||||
// handled by other rules
|
||||
if ($closureReturnType instanceof VoidType || $closureReturnType instanceof NeverType) {
|
||||
if ($closureReturnType instanceof NeverType) {
|
||||
return null;
|
||||
}
|
||||
$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($closureReturnType, TypeKind::RETURN);
|
||||
|
@ -5,7 +5,6 @@ namespace Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
@ -72,41 +71,29 @@ final class ReturnedNodesReturnTypeInfererTypeInferer
|
||||
return new MixedType();
|
||||
}
|
||||
$types = [];
|
||||
// empty returns can have yield, use MixedType() instead
|
||||
$localReturnNodes = $this->betterNodeFinder->findReturnsScoped($functionLike);
|
||||
if ($localReturnNodes === []) {
|
||||
return $this->resolveNoLocalReturnNodes($functionLike, $classReflection);
|
||||
return new MixedType();
|
||||
}
|
||||
$hasVoid = \false;
|
||||
foreach ($localReturnNodes as $localReturnNode) {
|
||||
$returnedExprType = $localReturnNode->expr instanceof Expr ? $this->nodeTypeResolver->getNativeType($localReturnNode->expr) : new VoidType();
|
||||
if (!$localReturnNode->expr instanceof Expr) {
|
||||
$hasVoid = \true;
|
||||
$types[] = new VoidType();
|
||||
continue;
|
||||
}
|
||||
$returnedExprType = $this->nodeTypeResolver->getNativeType($localReturnNode->expr);
|
||||
$types[] = $this->splArrayFixedTypeNarrower->narrow($returnedExprType);
|
||||
}
|
||||
if ($this->silentVoidResolver->hasSilentVoid($functionLike)) {
|
||||
if (!$hasVoid && $this->silentVoidResolver->hasSilentVoid($functionLike)) {
|
||||
$types[] = new VoidType();
|
||||
}
|
||||
return $this->typeFactory->createMixedPassedOrUnionTypeAndKeepConstant($types);
|
||||
}
|
||||
/**
|
||||
* @return \PHPStan\Type\VoidType|\PHPStan\Type\MixedType
|
||||
*/
|
||||
private function resolveNoLocalReturnNodes(FunctionLike $functionLike, ?ClassReflection $classReflection)
|
||||
{
|
||||
// void type
|
||||
if (!$this->isAbstractMethod($functionLike, $classReflection)) {
|
||||
return new VoidType();
|
||||
$returnType = $this->typeFactory->createMixedPassedOrUnionTypeAndKeepConstant($types);
|
||||
// only void?
|
||||
if ($returnType->isVoid()->yes()) {
|
||||
return new MixedType();
|
||||
}
|
||||
return new MixedType();
|
||||
}
|
||||
private function isAbstractMethod(FunctionLike $functionLike, ?ClassReflection $classReflection) : bool
|
||||
{
|
||||
if ($functionLike instanceof ClassMethod && $functionLike->isAbstract()) {
|
||||
return \true;
|
||||
}
|
||||
if (!$classReflection instanceof ClassReflection) {
|
||||
return \false;
|
||||
}
|
||||
if (!$classReflection->isClass()) {
|
||||
return \false;
|
||||
}
|
||||
return $classReflection->isAbstract();
|
||||
return $returnType;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '54a66206986e685787d7e038929618a66e98ec42';
|
||||
public const PACKAGE_VERSION = 'a11fc615d18396cef284c18de269711114630676';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-10-01 12:25:35';
|
||||
public const RELEASE_DATE = '2024-10-01 16:53:21';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user