mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-19 01:22:22 +00:00
Updated Rector to commit 97d095f5bd3fe561dafd06f56f898f0aec535ba0
97d095f5bd
[TypeDeclaration] Skip default numeric string on param int on ParamTypeByMethodCallTypeRector (#5210)
This commit is contained in:
parent
b60b85beb4
commit
5869e2ab60
|
@ -3,8 +3,10 @@
|
||||||
declare (strict_types=1);
|
declare (strict_types=1);
|
||||||
namespace Rector\TypeDeclaration\NodeAnalyzer;
|
namespace Rector\TypeDeclaration\NodeAnalyzer;
|
||||||
|
|
||||||
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Arg;
|
use PhpParser\Node\Arg;
|
||||||
use PhpParser\Node\ComplexType;
|
use PhpParser\Node\ComplexType;
|
||||||
|
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\StaticCall;
|
use PhpParser\Node\Expr\StaticCall;
|
||||||
|
@ -19,6 +21,8 @@ use PHPStan\Analyser\Scope;
|
||||||
use PHPStan\Reflection\ClassReflection;
|
use PHPStan\Reflection\ClassReflection;
|
||||||
use Rector\Core\PhpParser\AstResolver;
|
use Rector\Core\PhpParser\AstResolver;
|
||||||
use Rector\NodeNameResolver\NodeNameResolver;
|
use Rector\NodeNameResolver\NodeNameResolver;
|
||||||
|
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;
|
||||||
|
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||||
final class CallerParamMatcher
|
final class CallerParamMatcher
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -31,10 +35,22 @@ final class CallerParamMatcher
|
||||||
* @var \Rector\Core\PhpParser\AstResolver
|
* @var \Rector\Core\PhpParser\AstResolver
|
||||||
*/
|
*/
|
||||||
private $astResolver;
|
private $astResolver;
|
||||||
public function __construct(NodeNameResolver $nodeNameResolver, AstResolver $astResolver)
|
/**
|
||||||
|
* @readonly
|
||||||
|
* @var \Rector\StaticTypeMapper\StaticTypeMapper
|
||||||
|
*/
|
||||||
|
private $staticTypeMapper;
|
||||||
|
/**
|
||||||
|
* @readonly
|
||||||
|
* @var \Rector\NodeTypeResolver\TypeComparator\TypeComparator
|
||||||
|
*/
|
||||||
|
private $typeComparator;
|
||||||
|
public function __construct(NodeNameResolver $nodeNameResolver, AstResolver $astResolver, StaticTypeMapper $staticTypeMapper, TypeComparator $typeComparator)
|
||||||
{
|
{
|
||||||
$this->nodeNameResolver = $nodeNameResolver;
|
$this->nodeNameResolver = $nodeNameResolver;
|
||||||
$this->astResolver = $astResolver;
|
$this->astResolver = $astResolver;
|
||||||
|
$this->staticTypeMapper = $staticTypeMapper;
|
||||||
|
$this->typeComparator = $typeComparator;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\FuncCall $call
|
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\FuncCall $call
|
||||||
|
@ -46,7 +62,21 @@ final class CallerParamMatcher
|
||||||
if (!$callParam instanceof Param) {
|
if (!$callParam instanceof Param) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return $callParam->type;
|
if (!$param->default instanceof Expr) {
|
||||||
|
return $callParam->type;
|
||||||
|
}
|
||||||
|
if (!$callParam->type instanceof Node) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$callParamType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($callParam->type);
|
||||||
|
$defaultType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->default);
|
||||||
|
if ($this->typeComparator->areTypesEqual($callParamType, $defaultType)) {
|
||||||
|
return $callParam->type;
|
||||||
|
}
|
||||||
|
if ($this->typeComparator->isSubtype($defaultType, $callParamType)) {
|
||||||
|
return $callParam->type;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
public function matchParentParam(StaticCall $parentStaticCall, Param $param, Scope $scope) : ?Param
|
public function matchParentParam(StaticCall $parentStaticCall, Param $param, Scope $scope) : ?Param
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = '6f330105bef70bec222f1cc6f86c09b137dff44f';
|
public const PACKAGE_VERSION = '97d095f5bd3fe561dafd06f56f898f0aec535ba0';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2023-10-28 19:40:43';
|
public const RELEASE_DATE = '2023-10-28 23:32:49';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user