Skip to content

Commit

Permalink
add NonExistingObjectType
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Oct 7, 2021
1 parent cb84ffc commit b144c21
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpParser\Node\Name;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\AbstractNodeTypeResolverTest;
use Rector\Tests\NodeTypeResolver\Source\AnotherClass;

Expand All @@ -23,7 +24,7 @@ public function test(string $file, int $nodePosition, Type $expectedType): void
{
$nameNodes = $this->getNodesForFileOfType($file, Name::class);

$resolvedType = $this->nodeTypeResolver->resolve($nameNodes[$nodePosition]);
$resolvedType = $this->nodeTypeResolver->getType($nameNodes[$nodePosition]);
$this->assertEquals($expectedType, $resolvedType);
}

Expand All @@ -32,7 +33,7 @@ public function test(string $file, int $nodePosition, Type $expectedType): void
*/
public function provideData(): Iterator
{
$expectedObjectType = new ObjectType(AnotherClass::class);
$expectedObjectType = new FullyQualifiedObjectType(AnotherClass::class);

# test new
yield [__DIR__ . '/Source/ParentCall.php', 2, $expectedObjectType];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\PropertyFetchTypeRes

use Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\PropertyFetchTypeResolver\Source\ClassWithTypedPropertyTypes;

final class NonExistingObjectType
final class SomeNonExistingObjectType
{
public function run(ClassWithTypedPropertyTypes $props): void
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Rector\StaticTypeMapper\ValueObject\Type;

use PHPStan\Type\ObjectType;

final class NonExistingObjectType extends ObjectType
{
public function __construct(string $className)
{
parent::__construct($className);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function __construct(

public function isSuperTypeOf(Type $type): TrinaryLogic
{
$fullyQualifiedObjectType = new GenericObjectType($this->fullyQualifiedName, $this->getTypes());
return $fullyQualifiedObjectType->isSuperTypeOf($type);
$genericObjectType = new GenericObjectType($this->fullyQualifiedName, $this->getTypes());
return $genericObjectType->isSuperTypeOf($type);
}

public function getShortName(): string
Expand Down
3 changes: 2 additions & 1 deletion rules/TypeDeclaration/PHPStan/Type/ObjectTypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\NonExistingObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedGenericObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;

Expand Down Expand Up @@ -63,7 +64,7 @@ public function narrowToFullyQualifiedOrAliasedObjectType(
}

// invalid type
return new MixedType();
return new NonExistingObjectType($className);
}

private function matchAliasedObjectType(Node $node, ObjectType $objectType): ?AliasedObjectType
Expand Down

0 comments on commit b144c21

Please sign in to comment.