mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 06:18:07 +01:00
Updated Rector to commit 9a794f4ac4a100c1bffbf6af5a0c15f9628f3b90
9a794f4ac4
[TypeDeclaration] Handle with default null on ParamTypeByMethodCallTypeRector (#5437)
This commit is contained in:
parent
8728d93e41
commit
3c0a61462c
@ -3,6 +3,7 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\TypeDeclaration\NodeAnalyzer;
|
||||
|
||||
use PHPStan\Type\NullType;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\ComplexType;
|
||||
@ -12,6 +13,7 @@ use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\IntersectionType;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\NullableType;
|
||||
use PhpParser\Node\Param;
|
||||
@ -62,20 +64,33 @@ final class CallerParamMatcher
|
||||
if (!$callParam instanceof Param) {
|
||||
return null;
|
||||
}
|
||||
if (!$param->default instanceof Expr) {
|
||||
if (!$param->default instanceof Expr && !$callParam->default instanceof Expr) {
|
||||
return $callParam->type;
|
||||
}
|
||||
if (!$callParam->type instanceof Node) {
|
||||
return null;
|
||||
}
|
||||
$default = $param->default ?? $callParam->default;
|
||||
if (!$default instanceof Expr) {
|
||||
return null;
|
||||
}
|
||||
$callParamType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($callParam->type);
|
||||
$defaultType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->default);
|
||||
$defaultType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($default);
|
||||
if ($this->typeComparator->areTypesEqual($callParamType, $defaultType)) {
|
||||
return $callParam->type;
|
||||
}
|
||||
if ($this->typeComparator->isSubtype($defaultType, $callParamType)) {
|
||||
return $callParam->type;
|
||||
}
|
||||
if (!$defaultType instanceof NullType) {
|
||||
return null;
|
||||
}
|
||||
if ($callParam->type instanceof Name || $callParam->type instanceof Identifier) {
|
||||
return new NullableType($callParam->type);
|
||||
}
|
||||
if ($callParam->type instanceof IntersectionType || $callParam->type instanceof UnionType) {
|
||||
return new UnionType(\array_merge($callParam->type->types, [new Identifier('null')]));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function matchParentParam(StaticCall $parentStaticCall, Param $param, Scope $scope) : ?Param
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '55a787b9a2a18d7b131e74f0bc0d244989f6c92e';
|
||||
public const PACKAGE_VERSION = '9a794f4ac4a100c1bffbf6af5a0c15f9628f3b90';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-01-06 12:23:50';
|
||||
public const RELEASE_DATE = '2024-01-06 12:59:16';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user