1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace PHPStan\Type\Generic; |
4: | |
5: | use PHPStan\TrinaryLogic; |
6: | use PHPStan\Type\AcceptsResult; |
7: | use PHPStan\Type\MixedType; |
8: | use PHPStan\Type\StrictMixedType; |
9: | use PHPStan\Type\Type; |
10: | |
11: | |
12: | final class TemplateMixedType extends MixedType implements TemplateType |
13: | { |
14: | |
15: | |
16: | use TemplateTypeTrait; |
17: | |
18: | |
19: | |
20: | |
21: | public function __construct( |
22: | TemplateTypeScope $scope, |
23: | TemplateTypeStrategy $templateTypeStrategy, |
24: | TemplateTypeVariance $templateTypeVariance, |
25: | string $name, |
26: | MixedType $bound, |
27: | ) |
28: | { |
29: | parent::__construct(true); |
30: | |
31: | $this->scope = $scope; |
32: | $this->strategy = $templateTypeStrategy; |
33: | $this->variance = $templateTypeVariance; |
34: | $this->name = $name; |
35: | $this->bound = $bound; |
36: | } |
37: | |
38: | public function isSuperTypeOfMixed(MixedType $type): TrinaryLogic |
39: | { |
40: | return $this->isSuperTypeOf($type); |
41: | } |
42: | |
43: | public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic |
44: | { |
45: | return $this->isAcceptedWithReasonBy($acceptingType, $strictTypes)->result; |
46: | } |
47: | |
48: | public function isAcceptedWithReasonBy(Type $acceptingType, bool $strictTypes): AcceptsResult |
49: | { |
50: | $isSuperType = new AcceptsResult($this->isSuperTypeOf($acceptingType), []); |
51: | if ($isSuperType->no()) { |
52: | return $isSuperType; |
53: | } |
54: | return AcceptsResult::createYes(); |
55: | } |
56: | |
57: | public function toStrictMixedType(): TemplateStrictMixedType |
58: | { |
59: | return new TemplateStrictMixedType( |
60: | $this->scope, |
61: | $this->strategy, |
62: | $this->variance, |
63: | $this->name, |
64: | new StrictMixedType(), |
65: | ); |
66: | } |
67: | |
68: | } |
69: | |