Skip to content

Commit 91f0ec8

Browse files
authored
[cleanup] Remove three unreachable PHPStan type mappers (#8230)
1 parent a0ad10f commit 91f0ec8

5 files changed

Lines changed: 49 additions & 132 deletions

File tree

‎src/DependencyInjection/LazyContainerFactory.php‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
use Rector\PHPStanStaticTypeMapper\TypeMapper\ConditionalTypeMapper;
149149
use Rector\PHPStanStaticTypeMapper\TypeMapper\ConstantArrayTypeMapper;
150150
use Rector\PHPStanStaticTypeMapper\TypeMapper\FloatTypeMapper;
151-
use Rector\PHPStanStaticTypeMapper\TypeMapper\GenericClassStringTypeMapper;
152151
use Rector\PHPStanStaticTypeMapper\TypeMapper\HasMethodTypeMapper;
153152
use Rector\PHPStanStaticTypeMapper\TypeMapper\HasOffsetTypeMapper;
154153
use Rector\PHPStanStaticTypeMapper\TypeMapper\HasOffsetValueTypeTypeMapper;
@@ -165,11 +164,9 @@
165164
use Rector\PHPStanStaticTypeMapper\TypeMapper\OversizedArrayTypeMapper;
166165
use Rector\PHPStanStaticTypeMapper\TypeMapper\ParentStaticTypeMapper;
167166
use Rector\PHPStanStaticTypeMapper\TypeMapper\ResourceTypeMapper;
168-
use Rector\PHPStanStaticTypeMapper\TypeMapper\SelfObjectTypeMapper;
169167
use Rector\PHPStanStaticTypeMapper\TypeMapper\StaticTypeMapper;
170168
use Rector\PHPStanStaticTypeMapper\TypeMapper\StrictMixedTypeMapper;
171169
use Rector\PHPStanStaticTypeMapper\TypeMapper\StringTypeMapper;
172-
use Rector\PHPStanStaticTypeMapper\TypeMapper\ThisTypeMapper;
173170
use Rector\PHPStanStaticTypeMapper\TypeMapper\TypeWithClassNameTypeMapper;
174171
use Rector\PHPStanStaticTypeMapper\TypeMapper\UnionTypeMapper;
175172
use Rector\PHPStanStaticTypeMapper\TypeMapper\VoidTypeMapper;
@@ -303,7 +300,6 @@ final class LazyContainerFactory
303300
ConditionalTypeForParameterMapper::class,
304301
ConditionalTypeMapper::class,
305302
FloatTypeMapper::class,
306-
GenericClassStringTypeMapper::class,
307303
HasMethodTypeMapper::class,
308304
HasOffsetTypeMapper::class,
309305
HasOffsetValueTypeTypeMapper::class,
@@ -320,11 +316,9 @@ final class LazyContainerFactory
320316
OversizedArrayTypeMapper::class,
321317
ParentStaticTypeMapper::class,
322318
ResourceTypeMapper::class,
323-
SelfObjectTypeMapper::class,
324319
StaticTypeMapper::class,
325320
StrictMixedTypeMapper::class,
326321
StringTypeMapper::class,
327-
ThisTypeMapper::class,
328322
TypeWithClassNameTypeMapper::class,
329323
UnionTypeMapper::class,
330324
VoidTypeMapper::class,

‎src/PHPStanStaticTypeMapper/TypeMapper/GenericClassStringTypeMapper.php‎

Lines changed: 0 additions & 50 deletions
This file was deleted.

‎src/PHPStanStaticTypeMapper/TypeMapper/SelfObjectTypeMapper.php‎

Lines changed: 0 additions & 38 deletions
This file was deleted.

‎src/PHPStanStaticTypeMapper/TypeMapper/ThisTypeMapper.php‎

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\PHPStanStaticTypeMapper;
6+
7+
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
8+
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
9+
10+
final class TypeMapperOrderTest extends AbstractLazyTestCase
11+
{
12+
/**
13+
* The mappers are matched with is_a() in registration order, so a mapper for a child type
14+
* must come before the mapper for its parent type. Otherwise the parent one always wins
15+
* and the child one is never reached.
16+
*/
17+
public function testChildTypeMapperIsRegisteredBeforeItsParent(): void
18+
{
19+
$typeMappers = $this->resolveTypeMappers();
20+
21+
foreach ($typeMappers as $position => $typeMapper) {
22+
$nodeClass = $typeMapper->getNodeClass();
23+
24+
for ($earlierPosition = 0; $earlierPosition < $position; ++$earlierPosition) {
25+
$earlierNodeClass = $typeMappers[$earlierPosition]->getNodeClass();
26+
27+
$this->assertFalse(is_a($nodeClass, $earlierNodeClass, true), sprintf(
28+
'The "%s" is registered after "%s", but "%s" is a "%s". It can never be reached, register it earlier.',
29+
$typeMapper::class,
30+
$typeMappers[$earlierPosition]::class,
31+
$nodeClass,
32+
$earlierNodeClass
33+
));
34+
}
35+
}
36+
}
37+
38+
/**
39+
* @return TypeMapperInterface[]
40+
*/
41+
private function resolveTypeMappers(): array
42+
{
43+
$typeMappers = iterator_to_array(self::getContainer()->tagged(TypeMapperInterface::class));
44+
45+
$this->assertNotEmpty($typeMappers);
46+
47+
return array_values($typeMappers);
48+
}
49+
}

0 commit comments

Comments
 (0)