forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructorClassTemplateTraverser.php
More file actions
46 lines (38 loc) · 1.06 KB
/
ConstructorClassTemplateTraverser.php
File metadata and controls
46 lines (38 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php declare(strict_types = 1);
namespace PHPStan\Analyser\Traverser;
use PHPStan\Type\Generic\TemplateType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeTraverserCallable;
use function array_key_exists;
final class ConstructorClassTemplateTraverser implements TypeTraverserCallable
{
/**
* @param array<string, Type> $classTemplateTypes
*/
public function __construct(
private array $classTemplateTypes,
)
{
}
/**
* @param callable(Type): Type $traverse
*/
public function traverse(Type $type, callable $traverse): Type
{
if ($type instanceof TemplateType && array_key_exists($type->getName(), $this->classTemplateTypes)) {
$classTemplateType = $this->classTemplateTypes[$type->getName()];
if ($classTemplateType instanceof TemplateType && $classTemplateType->getScope()->equals($type->getScope())) {
unset($this->classTemplateTypes[$type->getName()]);
}
return $type;
}
return $traverse($type);
}
/**
* @return array<string, Type>
*/
public function getClassTemplateTypes(): array
{
return $this->classTemplateTypes;
}
}