1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Php;
4:
5: use function floor;
6:
7: /** @api */
8: class PhpVersion
9: {
10:
11: public function __construct(private int $versionId)
12: {
13: }
14:
15: public function getVersionId(): int
16: {
17: return $this->versionId;
18: }
19:
20: public function getVersionString(): string
21: {
22: $first = (int) floor($this->versionId / 10000);
23: $second = (int) floor(($this->versionId % 10000) / 100);
24: $third = (int) floor($this->versionId % 100);
25:
26: return $first . '.' . $second . ($third !== 0 ? '.' . $third : '');
27: }
28:
29: public function supportsNullCoalesceAssign(): bool
30: {
31: return $this->versionId >= 70400;
32: }
33:
34: public function supportsParameterContravariance(): bool
35: {
36: return $this->versionId >= 70400;
37: }
38:
39: public function supportsReturnCovariance(): bool
40: {
41: return $this->versionId >= 70400;
42: }
43:
44: public function supportsNoncapturingCatches(): bool
45: {
46: return $this->versionId >= 80000;
47: }
48:
49: public function supportsNativeUnionTypes(): bool
50: {
51: return $this->versionId >= 80000;
52: }
53:
54: public function deprecatesRequiredParameterAfterOptional(): bool
55: {
56: return $this->versionId >= 80000;
57: }
58:
59: public function deprecatesRequiredParameterAfterOptionalNullableAndDefaultNull(): bool
60: {
61: return $this->versionId >= 80100;
62: }
63:
64: public function deprecatesRequiredParameterAfterOptionalUnionOrMixed(): bool
65: {
66: return $this->versionId >= 80300;
67: }
68:
69: public function supportsLessOverridenParametersWithVariadic(): bool
70: {
71: return $this->versionId >= 80000;
72: }
73:
74: public function supportsThrowExpression(): bool
75: {
76: return $this->versionId >= 80000;
77: }
78:
79: public function supportsClassConstantOnExpression(): bool
80: {
81: return $this->versionId >= 80000;
82: }
83:
84: public function supportsLegacyConstructor(): bool
85: {
86: return $this->versionId < 80000;
87: }
88:
89: public function supportsPromotedProperties(): bool
90: {
91: return $this->versionId >= 80000;
92: }
93:
94: public function supportsParameterTypeWidening(): bool
95: {
96: return $this->versionId >= 70200;
97: }
98:
99: public function supportsUnsetCast(): bool
100: {
101: return $this->versionId < 80000;
102: }
103:
104: public function supportsNamedArguments(): bool
105: {
106: return $this->versionId >= 80000;
107: }
108:
109: public function throwsTypeErrorForInternalFunctions(): bool
110: {
111: return $this->versionId >= 80000;
112: }
113:
114: public function throwsValueErrorForInternalFunctions(): bool
115: {
116: return $this->versionId >= 80000;
117: }
118:
119: public function supportsHhPrintfSpecifier(): bool
120: {
121: return $this->versionId >= 80000;
122: }
123:
124: public function isEmptyStringValidAliasForNoneInMbSubstituteCharacter(): bool
125: {
126: return $this->versionId < 80000;
127: }
128:
129: public function supportsAllUnicodeScalarCodePointsInMbSubstituteCharacter(): bool
130: {
131: return $this->versionId >= 70200;
132: }
133:
134: public function isNumericStringValidArgInMbSubstituteCharacter(): bool
135: {
136: return $this->versionId < 80000;
137: }
138:
139: public function isNullValidArgInMbSubstituteCharacter(): bool
140: {
141: return $this->versionId >= 80000;
142: }
143:
144: public function isInterfaceConstantImplicitlyFinal(): bool
145: {
146: return $this->versionId < 80100;
147: }
148:
149: public function supportsFinalConstants(): bool
150: {
151: return $this->versionId >= 80100;
152: }
153:
154: public function supportsReadOnlyProperties(): bool
155: {
156: return $this->versionId >= 80100;
157: }
158:
159: public function supportsEnums(): bool
160: {
161: return $this->versionId >= 80100;
162: }
163:
164: public function supportsPureIntersectionTypes(): bool
165: {
166: return $this->versionId >= 80100;
167: }
168:
169: public function supportsCaseInsensitiveConstantNames(): bool
170: {
171: return $this->versionId < 80000;
172: }
173:
174: public function hasStricterRoundFunctions(): bool
175: {
176: return $this->versionId >= 80000;
177: }
178:
179: public function hasTentativeReturnTypes(): bool
180: {
181: return $this->versionId >= 80100;
182: }
183:
184: public function supportsFirstClassCallables(): bool
185: {
186: return $this->versionId >= 80100;
187: }
188:
189: public function supportsArrayUnpackingWithStringKeys(): bool
190: {
191: return $this->versionId >= 80100;
192: }
193:
194: public function throwsOnInvalidMbStringEncoding(): bool
195: {
196: return $this->versionId >= 80000;
197: }
198:
199: public function supportsPassNoneEncodings(): bool
200: {
201: return $this->versionId < 70300;
202: }
203:
204: public function producesWarningForFinalPrivateMethods(): bool
205: {
206: return $this->versionId >= 80000;
207: }
208:
209: public function deprecatesDynamicProperties(): bool
210: {
211: return $this->versionId >= 80200;
212: }
213:
214: public function strSplitReturnsEmptyArray(): bool
215: {
216: return $this->versionId >= 80200;
217: }
218:
219: public function supportsDisjunctiveNormalForm(): bool
220: {
221: return $this->versionId >= 80200;
222: }
223:
224: public function serializableRequiresMagicMethods(): bool
225: {
226: return $this->versionId >= 80100;
227: }
228:
229: public function arrayFunctionsReturnNullWithNonArray(): bool
230: {
231: return $this->versionId < 80000;
232: }
233:
234: // see https://www.php.net/manual/en/migration80.incompatible.php#migration80.incompatible.core.string-number-comparision
235: public function castsNumbersToStringsOnLooseComparison(): bool
236: {
237: return $this->versionId >= 80000;
238: }
239:
240: public function supportsCallableInstanceMethods(): bool
241: {
242: return $this->versionId < 80000;
243: }
244:
245: public function supportsJsonValidate(): bool
246: {
247: return $this->versionId >= 80300;
248: }
249:
250: public function supportsConstantsInTraits(): bool
251: {
252: return $this->versionId >= 80200;
253: }
254:
255: public function supportsNativeTypesInClassConstants(): bool
256: {
257: return $this->versionId >= 80300;
258: }
259:
260: public function supportsAbstractTraitMethods(): bool
261: {
262: return $this->versionId >= 80000;
263: }
264:
265: public function supportsOverrideAttribute(): bool
266: {
267: return $this->versionId >= 80300;
268: }
269:
270: public function supportsDynamicClassConstantFetch(): bool
271: {
272: return $this->versionId >= 80300;
273: }
274:
275: public function supportsReadOnlyClasses(): bool
276: {
277: return $this->versionId >= 80200;
278: }
279:
280: public function supportsReadOnlyAnonymousClasses(): bool
281: {
282: return $this->versionId >= 80300;
283: }
284:
285: public function supportsNeverReturnTypeInArrowFunction(): bool
286: {
287: return $this->versionId >= 80200;
288: }
289:
290: }
291: