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: | public function __construct( |
19: | TemplateTypeScope $scope, |
20: | TemplateTypeStrategy $templateTypeStrategy, |
21: | TemplateTypeVariance $templateTypeVariance, |
22: | string $name, |
23: | MixedType $bound, |
24: | ) |
25: | { |
26: | parent::__construct(true); |
27: | |
28: | $this->scope = $scope; |
29: | $this->strategy = $templateTypeStrategy; |
30: | $this->variance = $templateTypeVariance; |
31: | $this->name = $name; |
32: | $this->bound = $bound; |
33: | } |
34: | |
35: | public function isSuperTypeOfMixed(MixedType $type): TrinaryLogic |
36: | { |
37: | return $this->isSuperTypeOf($type); |
38: | } |
39: | |
40: | public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic |
41: | { |
42: | return $this->isAcceptedWithReasonBy($acceptingType, $strictTypes)->result; |
43: | } |
44: | |
45: | public function isAcceptedWithReasonBy(Type $acceptingType, bool $strictTypes): AcceptsResult |
46: | { |
47: | $isSuperType = new AcceptsResult($this->isSuperTypeOf($acceptingType), []); |
48: | if ($isSuperType->no()) { |
49: | return $isSuperType; |
50: | } |
51: | return AcceptsResult::createYes(); |
52: | } |
53: | |
54: | public function toStrictMixedType(): TemplateStrictMixedType |
55: | { |
56: | return new TemplateStrictMixedType( |
57: | $this->scope, |
58: | $this->strategy, |
59: | $this->variance, |
60: | $this->name, |
61: | new StrictMixedType(), |
62: | ); |
63: | } |
64: | |
65: | } |
66: | |