1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type\Traits;
4:
5: use PHPStan\Type\IsSuperTypeOfResult;
6: use PHPStan\Type\LateResolvableType;
7: use PHPStan\Type\NeverType;
8: use PHPStan\Type\Type;
9:
10: /** @api */
11: trait LateResolvableTypeTrait
12: {
13:
14: use DelegatingTypeTrait;
15:
16: private ?Type $result = null;
17:
18: public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
19: {
20: return $this->isSuperTypeOfDefault($type);
21: }
22:
23: private function isSuperTypeOfDefault(Type $type): IsSuperTypeOfResult
24: {
25: if ($type instanceof NeverType) {
26: return IsSuperTypeOfResult::createYes();
27: }
28:
29: if ($type instanceof LateResolvableType) {
30: $type = $type->resolve();
31: }
32:
33: $isSuperType = $this->getDelegate()->isSuperTypeOf($type);
34:
35: if (!$this->isResolvable()) {
36: $isSuperType = $isSuperType->and(IsSuperTypeOfResult::createMaybe());
37: }
38:
39: return $isSuperType;
40: }
41:
42: public function resolve(): Type
43: {
44: return $this->result ??= $this->getResult();
45: }
46:
47: abstract protected function getResult(): Type;
48:
49: protected function getDelegate(): Type
50: {
51: return $this->resolve();
52: }
53:
54: public function hasTemplateOrLateResolvableType(): bool
55: {
56: return true;
57: }
58:
59: }
60: