forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TemplateTypeArgumentStrategy.php
51 lines (41 loc) · 1.13 KB
/
TemplateTypeArgumentStrategy.php
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
47
48
49
50
51
<?php declare(strict_types = 1);
namespace PHPStan\Type\Generic;
use PHPStan\TrinaryLogic;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
/**
* Template type strategy suitable for return type acceptance contexts
*/
class TemplateTypeArgumentStrategy implements TemplateTypeStrategy
{
public function accepts(TemplateType $left, Type $right, bool $strictTypes): TrinaryLogic
{
if ($right instanceof IntersectionType) {
foreach ($right->getTypes() as $type) {
if ($this->accepts($left, $type, $strictTypes)->yes()) {
return TrinaryLogic::createYes();
}
}
return TrinaryLogic::createNo();
}
if ($right instanceof TemplateType) {
$accepts = $right->isAcceptedBy($left, $strictTypes);
} else {
$accepts = $left->getBound()->accepts($right, $strictTypes)
->and(TrinaryLogic::createMaybe());
}
return $accepts->or(TrinaryLogic::createFromBoolean($right->equals(new MixedType())));
}
public function isArgument(): bool
{
return true;
}
/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): self
{
return new self();
}
}