1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Php;
4:
5: use PHPStan\TrinaryLogic;
6: use PHPStan\Turbo\ReferencedByTurboExtension;
7: use PHPStan\Type\IntegerRangeType;
8: use PHPStan\Type\Type;
9:
10: /**
11: * Range-aware PHP version check that handles version uncertainty.
12: *
13: * Unlike PhpVersion (which represents a single known version), PhpVersions wraps
14: * a Type representing the possible PHP versions. When the exact version is known,
15: * queries return Yes/No. When a range of versions is possible, queries return Maybe.
16: *
17: * This is the return type of Scope::getPhpVersion().
18: *
19: * @api
20: */
21: #[ReferencedByTurboExtension(key: 'phpVersions')]
22: final class PhpVersions
23: {
24:
25: public function __construct(
26: private Type $phpVersions,
27: )
28: {
29: }
30:
31: public function getType(): Type
32: {
33: return $this->phpVersions;
34: }
35:
36: public function supportsNoncapturingCatches(): TrinaryLogic
37: {
38: return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
39: }
40:
41: public function producesWarningForFinalPrivateMethods(): TrinaryLogic
42: {
43: return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
44: }
45:
46: public function supportsNamedArguments(): TrinaryLogic
47: {
48: return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
49: }
50:
51: public function supportsNamedArgumentAfterUnpackedArgument(): TrinaryLogic
52: {
53: return IntegerRangeType::fromInterval(80100, null)->isSuperTypeOf($this->phpVersions)->result;
54: }
55:
56: public function supportsNativeTypesInClassConstants(): TrinaryLogic
57: {
58: return IntegerRangeType::fromInterval(80300, null)->isSuperTypeOf($this->phpVersions)->result;
59: }
60:
61: public function supportsConstantsInTraits(): TrinaryLogic
62: {
63: return IntegerRangeType::fromInterval(80200, null)->isSuperTypeOf($this->phpVersions)->result;
64: }
65:
66: public function supportsNeverReturnTypeInArrowFunction(): TrinaryLogic
67: {
68: return IntegerRangeType::fromInterval(80200, null)->isSuperTypeOf($this->phpVersions)->result;
69: }
70:
71: public function supportsArrayUnpackingWithStringKeys(): TrinaryLogic
72: {
73: return IntegerRangeType::fromInterval(80100, null)->isSuperTypeOf($this->phpVersions)->result;
74: }
75:
76: public function supportsPropertyHooks(): TrinaryLogic
77: {
78: return IntegerRangeType::fromInterval(80400, null)->isSuperTypeOf($this->phpVersions)->result;
79: }
80:
81: public function supportsFinalProperties(): TrinaryLogic
82: {
83: return IntegerRangeType::fromInterval(80400, null)->isSuperTypeOf($this->phpVersions)->result;
84: }
85:
86: public function supportsAsymmetricVisibilityForStaticProperties(): TrinaryLogic
87: {
88: return IntegerRangeType::fromInterval(80500, null)->isSuperTypeOf($this->phpVersions)->result;
89: }
90:
91: public function supportsOverrideAttributeOnProperty(): TrinaryLogic
92: {
93: return IntegerRangeType::fromInterval(80500, null)->isSuperTypeOf($this->phpVersions)->result;
94: }
95:
96: public function supportsAttributesOnGlobalConstants(): TrinaryLogic
97: {
98: return IntegerRangeType::fromInterval(80500, null)->isSuperTypeOf($this->phpVersions)->result;
99: }
100:
101: public function supportsUnsetCast(): TrinaryLogic
102: {
103: return IntegerRangeType::fromInterval(null, 79999)->isSuperTypeOf($this->phpVersions)->result;
104: }
105:
106: public function supportsTrueAndFalseStandaloneType(): TrinaryLogic
107: {
108: return IntegerRangeType::fromInterval(80200, null)->isSuperTypeOf($this->phpVersions)->result;
109: }
110:
111: public function throwsTypeErrorForInternalFunctions(): TrinaryLogic
112: {
113: return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
114: }
115:
116: public function throwsValueErrorForInternalFunctions(): TrinaryLogic
117: {
118: return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
119: }
120:
121: public function supportsMaxMemoryLimit(): TrinaryLogic
122: {
123: return IntegerRangeType::fromInterval(80500, null)->isSuperTypeOf($this->phpVersions)->result;
124: }
125:
126: public function supportsThrowExpression(): TrinaryLogic
127: {
128: return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
129: }
130:
131: public function supportsClassConstantOnExpression(): TrinaryLogic
132: {
133: return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
134: }
135:
136: public function supportsPromotedProperties(): TrinaryLogic
137: {
138: return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
139: }
140:
141: public function supportsNativeUnionTypes(): TrinaryLogic
142: {
143: return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
144: }
145:
146: public function supportsFinalConstants(): TrinaryLogic
147: {
148: return IntegerRangeType::fromInterval(80100, null)->isSuperTypeOf($this->phpVersions)->result;
149: }
150:
151: public function supportsReadOnlyProperties(): TrinaryLogic
152: {
153: return IntegerRangeType::fromInterval(80100, null)->isSuperTypeOf($this->phpVersions)->result;
154: }
155:
156: public function supportsFirstClassCallables(): TrinaryLogic
157: {
158: return IntegerRangeType::fromInterval(80100, null)->isSuperTypeOf($this->phpVersions)->result;
159: }
160:
161: public function supportsReadOnlyClasses(): TrinaryLogic
162: {
163: return IntegerRangeType::fromInterval(80200, null)->isSuperTypeOf($this->phpVersions)->result;
164: }
165:
166: public function supportsDynamicClassConstantFetch(): TrinaryLogic
167: {
168: return IntegerRangeType::fromInterval(80300, null)->isSuperTypeOf($this->phpVersions)->result;
169: }
170:
171: public function supportsReadOnlyAnonymousClasses(): TrinaryLogic
172: {
173: return IntegerRangeType::fromInterval(80300, null)->isSuperTypeOf($this->phpVersions)->result;
174: }
175:
176: public function supportsFinalPromotedProperties(): TrinaryLogic
177: {
178: return IntegerRangeType::fromInterval(80500, null)->isSuperTypeOf($this->phpVersions)->result;
179: }
180:
181: public function supportsVoidCast(): TrinaryLogic
182: {
183: return IntegerRangeType::fromInterval(80500, null)->isSuperTypeOf($this->phpVersions)->result;
184: }
185:
186: public function supportsDeprecatedTraits(): TrinaryLogic
187: {
188: return IntegerRangeType::fromInterval(80500, null)->isSuperTypeOf($this->phpVersions)->result;
189: }
190:
191: public function supportsHhPrintfSpecifier(): TrinaryLogic
192: {
193: return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
194: }
195:
196: }
197: