rector/rules/Arguments/NodeAnalyzer/ChangedArgumentsDetector.php
Tomas Votruba 503a6059f8 Updated Rector to commit a8922f7431c9c9188be501107ee7819e0130da4c
a8922f7431 skip temporarily match + throws downagrade in symfony/console, very unlikely to run
2023-06-11 23:01:39 +00:00

57 lines
1.7 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\Arguments\NodeAnalyzer;
use PhpParser\Node\Expr;
use PhpParser\Node\Param;
use PHPStan\Type\Type;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;
use Rector\StaticTypeMapper\StaticTypeMapper;
final class ChangedArgumentsDetector
{
/**
* @readonly
* @var \Rector\Core\PhpParser\Node\Value\ValueResolver
*/
private $valueResolver;
/**
* @readonly
* @var \Rector\StaticTypeMapper\StaticTypeMapper
*/
private $staticTypeMapper;
/**
* @readonly
* @var \Rector\NodeTypeResolver\TypeComparator\TypeComparator
*/
private $typeComparator;
public function __construct(ValueResolver $valueResolver, StaticTypeMapper $staticTypeMapper, TypeComparator $typeComparator)
{
$this->valueResolver = $valueResolver;
$this->staticTypeMapper = $staticTypeMapper;
$this->typeComparator = $typeComparator;
}
/**
* @param mixed $value
*/
public function isDefaultValueChanged(Param $param, $value) : bool
{
if (!$param->default instanceof Expr) {
return \false;
}
return !$this->valueResolver->isValue($param->default, $value);
}
public function isTypeChanged(Param $param, ?Type $newType) : bool
{
if ($param->type === null) {
return \false;
}
if (!$newType instanceof Type) {
return \true;
}
$currentParamType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
return !$this->typeComparator->areTypesEqual($currentParamType, $newType);
}
}