mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit 0817980433aaf92d2b71e4d9804ec1988afbf908
0817980433
[TypeDeclaration] Return new static from different object on ReturnTypeFromStrictTypedCallRector (#5357)
This commit is contained in:
parent
e3e6cff9bd
commit
b571b1cd51
|
@ -19,11 +19,16 @@ use PhpParser\Node\Scalar\LNumber;
|
|||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\FunctionVariantWithPhpDocs;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\StaticType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeTraverser;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\TypeDeclaration\NodeAnalyzer\TypeNodeUnwrapper;
|
||||
final class ReturnStrictTypeAnalyzer
|
||||
{
|
||||
|
@ -103,8 +108,26 @@ final class ReturnStrictTypeAnalyzer
|
|||
if ($returnType instanceof MixedType) {
|
||||
return null;
|
||||
}
|
||||
$returnType = $this->normalizeStaticType($call, $returnType);
|
||||
return $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($returnType, TypeKind::RETURN);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\FuncCall $call
|
||||
*/
|
||||
private function normalizeStaticType($call, Type $type) : Type
|
||||
{
|
||||
$reflectionClass = $this->reflectionResolver->resolveClassReflection($call);
|
||||
if (!$reflectionClass instanceof ClassReflection) {
|
||||
return $type;
|
||||
}
|
||||
$currentClassName = $reflectionClass->getName();
|
||||
return TypeTraverser::map($type, static function (Type $currentType, callable $traverseCallback) use($currentClassName) : Type {
|
||||
if ($currentType instanceof StaticType && $currentClassName !== $currentType->getClassName()) {
|
||||
return new FullyQualifiedObjectType($currentType->getClassName());
|
||||
}
|
||||
return $traverseCallback($currentType);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\Array_|\PhpParser\Node\Scalar $returnedExpr
|
||||
*/
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'fea5d6c0034746e050851887a7900bf94a22069d';
|
||||
public const PACKAGE_VERSION = '0817980433aaf92d2b71e4d9804ec1988afbf908';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-12-12 22:44:49';
|
||||
public const RELEASE_DATE = '2023-12-13 19:58:49';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -504,8 +504,8 @@
|
|||
},
|
||||
{
|
||||
"name": "illuminate\/container",
|
||||
"version": "v10.35.0",
|
||||
"version_normalized": "10.35.0.0",
|
||||
"version": "v10.37.1",
|
||||
"version_normalized": "10.37.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/illuminate\/container.git",
|
||||
|
@ -561,8 +561,8 @@
|
|||
},
|
||||
{
|
||||
"name": "illuminate\/contracts",
|
||||
"version": "v10.35.0",
|
||||
"version_normalized": "10.35.0.0",
|
||||
"version": "v10.37.1",
|
||||
"version_normalized": "10.37.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/illuminate\/contracts.git",
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue