-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathInstanceOfClassTypeTraverser.php
More file actions
46 lines (38 loc) · 1.01 KB
/
InstanceOfClassTypeTraverser.php
File metadata and controls
46 lines (38 loc) · 1.01 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\Constant\ConstantStringType;
use PHPStan\Type\Generic\GenericClassStringType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
final class InstanceOfClassTypeTraverser
{
private bool $uncertainty = false;
/**
* @param callable(Type): Type $traverse
*/
public function __invoke(Type $type, callable $traverse): Type
{
if ($type instanceof UnionType || $type instanceof IntersectionType) {
return $traverse($type);
}
if ($type->getObjectClassNames() !== []) {
$this->uncertainty = true;
return $type;
}
if ($type instanceof GenericClassStringType) {
$this->uncertainty = true;
return $type->getGenericType();
}
if ($type instanceof ConstantStringType) {
return new ObjectType($type->getValue());
}
return new MixedType();
}
public function getUncertainty(): bool
{
return $this->uncertainty;
}
}