mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 00:40:52 +00:00
Updated Rector to commit 48fc55d89350f24521a197c04b5512452a3b50fc
48fc55d893
[StaticTypeMapper] Clean up NameNodeMapper check Scalar and class exists (#5865)
This commit is contained in:
parent
fe891363d5
commit
322f3ad55c
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '558f44d5939be4314d76f4850a34be3590e65bfd';
|
||||
public const PACKAGE_VERSION = '48fc55d89350f24521a197c04b5512452a3b50fc';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-05-10 10:10:29';
|
||||
public const RELEASE_DATE = '2024-05-10 10:25:34';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -234,7 +234,7 @@ final class LazyContainerFactory
|
|||
/**
|
||||
* @var array<class-string<PhpParserNodeMapperInterface>>
|
||||
*/
|
||||
private const PHP_PARSER_NODE_MAPPER_CLASSES = [ExprNodeMapper::class, FullyQualifiedNodeMapper::class, IdentifierNodeMapper::class, IntersectionTypeNodeMapper::class, NameNodeMapper::class, NullableTypeNodeMapper::class, StringNodeMapper::class, UnionTypeNodeMapper::class];
|
||||
private const PHP_PARSER_NODE_MAPPER_CLASSES = [FullyQualifiedNodeMapper::class, IdentifierNodeMapper::class, IntersectionTypeNodeMapper::class, NameNodeMapper::class, NullableTypeNodeMapper::class, StringNodeMapper::class, UnionTypeNodeMapper::class, ExprNodeMapper::class];
|
||||
/**
|
||||
* @var array<class-string<SkipVoterInterface>>
|
||||
*/
|
||||
|
|
|
@ -4,10 +4,8 @@ declare (strict_types=1);
|
|||
namespace Rector\StaticTypeMapper\Mapper;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Exception\NotImplementedYetException;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
|
@ -33,14 +31,7 @@ final class PhpParserNodeMapper
|
|||
if (!\is_a($nameOrExpr, $phpParserNodeMapper->getNodeType())) {
|
||||
continue;
|
||||
}
|
||||
// do not let Expr collect all the types
|
||||
// note: can be solve later with priorities on mapper interface, making this last
|
||||
if ($phpParserNodeMapper->getNodeType() !== Expr::class) {
|
||||
return $phpParserNodeMapper->mapToPHPStan($nameOrExpr);
|
||||
}
|
||||
if (!$nameOrExpr instanceof String_) {
|
||||
return $phpParserNodeMapper->mapToPHPStan($nameOrExpr);
|
||||
}
|
||||
return $phpParserNodeMapper->mapToPHPStan($nameOrExpr);
|
||||
}
|
||||
throw new NotImplementedYetException(\get_class($nameOrExpr));
|
||||
}
|
||||
|
|
|
@ -6,23 +6,13 @@ namespace Rector\StaticTypeMapper\PhpParser;
|
|||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use PHPStan\Type\Constant\ConstantBooleanType;
|
||||
use PHPStan\Type\FloatType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\ObjectWithoutClassType;
|
||||
use PHPStan\Type\StaticType;
|
||||
use PHPStan\Type\StringType;
|
||||
use PHPStan\Type\ThisType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Configuration\RenamedClassesDataCollector;
|
||||
use Rector\Enum\ObjectReference;
|
||||
use Rector\Reflection\ReflectionResolver;
|
||||
use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ParentObjectWithoutClassType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ParentStaticType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\SelfStaticType;
|
||||
|
@ -31,25 +21,13 @@ use Rector\StaticTypeMapper\ValueObject\Type\SelfStaticType;
|
|||
*/
|
||||
final class NameNodeMapper implements PhpParserNodeMapperInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Configuration\RenamedClassesDataCollector
|
||||
*/
|
||||
private $renamedClassesDataCollector;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \PHPStan\Reflection\ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Reflection\ReflectionResolver
|
||||
*/
|
||||
private $reflectionResolver;
|
||||
public function __construct(RenamedClassesDataCollector $renamedClassesDataCollector, ReflectionProvider $reflectionProvider, ReflectionResolver $reflectionResolver)
|
||||
public function __construct(ReflectionResolver $reflectionResolver)
|
||||
{
|
||||
$this->renamedClassesDataCollector = $renamedClassesDataCollector;
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
$this->reflectionResolver = $reflectionResolver;
|
||||
}
|
||||
public function getNodeType() : string
|
||||
|
@ -62,22 +40,10 @@ final class NameNodeMapper implements PhpParserNodeMapperInterface
|
|||
public function mapToPHPStan(Node $node) : Type
|
||||
{
|
||||
$name = $node->toString();
|
||||
if ($this->isExistingClass($name)) {
|
||||
return new FullyQualifiedObjectType($name);
|
||||
}
|
||||
if (\in_array($name, [ObjectReference::STATIC, ObjectReference::SELF, ObjectReference::PARENT], \true)) {
|
||||
if ($node->isSpecialClassName()) {
|
||||
return $this->createClassReferenceType($node, $name);
|
||||
}
|
||||
return $this->createScalarType($name);
|
||||
}
|
||||
private function isExistingClass(string $name) : bool
|
||||
{
|
||||
if ($this->reflectionProvider->hasClass($name)) {
|
||||
return \true;
|
||||
}
|
||||
// to be existing class names
|
||||
$oldToNewClasses = $this->renamedClassesDataCollector->getOldToNewClasses();
|
||||
return \in_array($name, $oldToNewClasses, \true);
|
||||
return new MixedType();
|
||||
}
|
||||
/**
|
||||
* @return \PHPStan\Type\MixedType|\PHPStan\Type\StaticType|\Rector\StaticTypeMapper\ValueObject\Type\SelfStaticType|\PHPStan\Type\ObjectWithoutClassType
|
||||
|
@ -94,38 +60,10 @@ final class NameNodeMapper implements PhpParserNodeMapperInterface
|
|||
if ($reference === ObjectReference::SELF) {
|
||||
return new SelfStaticType($classReflection);
|
||||
}
|
||||
if ($reference === ObjectReference::PARENT) {
|
||||
$parentClassReflection = $classReflection->getParentClass();
|
||||
if ($parentClassReflection instanceof ClassReflection) {
|
||||
return new ParentStaticType($parentClassReflection);
|
||||
}
|
||||
return new ParentObjectWithoutClassType();
|
||||
$parentClassReflection = $classReflection->getParentClass();
|
||||
if ($parentClassReflection instanceof ClassReflection) {
|
||||
return new ParentStaticType($parentClassReflection);
|
||||
}
|
||||
return new ThisType($classReflection);
|
||||
}
|
||||
/**
|
||||
* @return \PHPStan\Type\ArrayType|\PHPStan\Type\IntegerType|\PHPStan\Type\FloatType|\PHPStan\Type\StringType|\PHPStan\Type\Constant\ConstantBooleanType|\PHPStan\Type\BooleanType|\PHPStan\Type\MixedType
|
||||
*/
|
||||
private function createScalarType(string $name)
|
||||
{
|
||||
if ($name === 'array') {
|
||||
return new ArrayType(new MixedType(), new MixedType());
|
||||
}
|
||||
if ($name === 'int') {
|
||||
return new IntegerType();
|
||||
}
|
||||
if ($name === 'float') {
|
||||
return new FloatType();
|
||||
}
|
||||
if ($name === 'string') {
|
||||
return new StringType();
|
||||
}
|
||||
if ($name === 'false') {
|
||||
return new ConstantBooleanType(\false);
|
||||
}
|
||||
if ($name === 'bool') {
|
||||
return new BooleanType();
|
||||
}
|
||||
return new MixedType();
|
||||
return new ParentObjectWithoutClassType();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user