Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
use Rector\PHPStanStaticTypeMapper\TypeMapper\ConditionalTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ConstantArrayTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\FloatTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\GenericClassStringTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\HasMethodTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\HasOffsetTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\HasOffsetValueTypeTypeMapper;
Expand All @@ -165,11 +164,9 @@
use Rector\PHPStanStaticTypeMapper\TypeMapper\OversizedArrayTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ParentStaticTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ResourceTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\SelfObjectTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\StaticTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\StrictMixedTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\StringTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ThisTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\TypeWithClassNameTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\UnionTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\VoidTypeMapper;
Expand Down Expand Up @@ -303,7 +300,6 @@ final class LazyContainerFactory
ConditionalTypeForParameterMapper::class,
ConditionalTypeMapper::class,
FloatTypeMapper::class,
GenericClassStringTypeMapper::class,
HasMethodTypeMapper::class,
HasOffsetTypeMapper::class,
HasOffsetValueTypeTypeMapper::class,
Expand All @@ -320,11 +316,9 @@ final class LazyContainerFactory
OversizedArrayTypeMapper::class,
ParentStaticTypeMapper::class,
ResourceTypeMapper::class,
SelfObjectTypeMapper::class,
StaticTypeMapper::class,
StrictMixedTypeMapper::class,
StringTypeMapper::class,
ThisTypeMapper::class,
TypeWithClassNameTypeMapper::class,
UnionTypeMapper::class,
VoidTypeMapper::class,
Expand Down

This file was deleted.

38 changes: 0 additions & 38 deletions src/PHPStanStaticTypeMapper/TypeMapper/SelfObjectTypeMapper.php

This file was deleted.

38 changes: 0 additions & 38 deletions src/PHPStanStaticTypeMapper/TypeMapper/ThisTypeMapper.php

This file was deleted.

49 changes: 49 additions & 0 deletions tests/PHPStanStaticTypeMapper/TypeMapperOrderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\PHPStanStaticTypeMapper;

use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;

final class TypeMapperOrderTest extends AbstractLazyTestCase
{
/**
* The mappers are matched with is_a() in registration order, so a mapper for a child type
* must come before the mapper for its parent type. Otherwise the parent one always wins
* and the child one is never reached.
*/
public function testChildTypeMapperIsRegisteredBeforeItsParent(): void
{
$typeMappers = $this->resolveTypeMappers();

foreach ($typeMappers as $position => $typeMapper) {
$nodeClass = $typeMapper->getNodeClass();

for ($earlierPosition = 0; $earlierPosition < $position; ++$earlierPosition) {
$earlierNodeClass = $typeMappers[$earlierPosition]->getNodeClass();

$this->assertFalse(is_a($nodeClass, $earlierNodeClass, true), sprintf(
'The "%s" is registered after "%s", but "%s" is a "%s". It can never be reached, register it earlier.',
$typeMapper::class,
$typeMappers[$earlierPosition]::class,
$nodeClass,
$earlierNodeClass
));
}
}
}

/**
* @return TypeMapperInterface[]
*/
private function resolveTypeMappers(): array
{
$typeMappers = iterator_to_array(self::getContainer()->tagged(TypeMapperInterface::class));

$this->assertNotEmpty($typeMappers);

return array_values($typeMappers);
}
}
Loading