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