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 supportsNativeUnionTypes(): bool
45: {
46: return $this->versionId >= 80000;
47: }
48:
49: public function deprecatesRequiredParameterAfterOptional(): bool
50: {
51: return $this->versionId >= 80000;
52: }
53:
54: public function supportsLessOverridenParametersWithVariadic(): bool
55: {
56: return $this->versionId >= 80000;
57: }
58:
59: public function supportsThrowExpression(): bool
60: {
61: return $this->versionId >= 80000;
62: }
63:
64: public function supportsClassConstantOnExpression(): bool
65: {
66: return $this->versionId >= 80000;
67: }
68:
69: public function supportsLegacyConstructor(): bool
70: {
71: return $this->versionId < 80000;
72: }
73:
74: public function supportsPromotedProperties(): bool
75: {
76: return $this->versionId >= 80000;
77: }
78:
79: public function supportsParameterTypeWidening(): bool
80: {
81: return $this->versionId >= 70200;
82: }
83:
84: public function supportsUnsetCast(): bool
85: {
86: return $this->versionId < 80000;
87: }
88:
89: public function supportsNamedArguments(): bool
90: {
91: return $this->versionId >= 80000;
92: }
93:
94: public function throwsTypeErrorForInternalFunctions(): bool
95: {
96: return $this->versionId >= 80000;
97: }
98:
99: public function throwsValueErrorForInternalFunctions(): bool
100: {
101: return $this->versionId >= 80000;
102: }
103:
104: public function supportsHhPrintfSpecifier(): bool
105: {
106: return $this->versionId >= 80000;
107: }
108:
109: public function isEmptyStringValidAliasForNoneInMbSubstituteCharacter(): bool
110: {
111: return $this->versionId < 80000;
112: }
113:
114: public function supportsAllUnicodeScalarCodePointsInMbSubstituteCharacter(): bool
115: {
116: return $this->versionId >= 70200;
117: }
118:
119: public function isNumericStringValidArgInMbSubstituteCharacter(): bool
120: {
121: return $this->versionId < 80000;
122: }
123:
124: public function isNullValidArgInMbSubstituteCharacter(): bool
125: {
126: return $this->versionId >= 80000;
127: }
128:
129: public function isInterfaceConstantImplicitlyFinal(): bool
130: {
131: return $this->versionId < 80100;
132: }
133:
134: public function supportsFinalConstants(): bool
135: {
136: return $this->versionId >= 80100;
137: }
138:
139: public function supportsReadOnlyProperties(): bool
140: {
141: return $this->versionId >= 80100;
142: }
143:
144: public function supportsEnums(): bool
145: {
146: return $this->versionId >= 80100;
147: }
148:
149: public function supportsPureIntersectionTypes(): bool
150: {
151: return $this->versionId >= 80100;
152: }
153:
154: public function supportsCaseInsensitiveConstantNames(): bool
155: {
156: return $this->versionId < 80000;
157: }
158:
159: public function hasStricterRoundFunctions(): bool
160: {
161: return $this->versionId >= 80000;
162: }
163:
164: public function hasTentativeReturnTypes(): bool
165: {
166: return $this->versionId >= 80100;
167: }
168:
169: public function supportsFirstClassCallables(): bool
170: {
171: return $this->versionId >= 80100;
172: }
173:
174: public function supportsArrayUnpackingWithStringKeys(): bool
175: {
176: return $this->versionId >= 80100;
177: }
178:
179: public function throwsOnInvalidMbStringEncoding(): bool
180: {
181: return $this->versionId >= 80000;
182: }
183:
184: public function supportsPassNoneEncodings(): bool
185: {
186: return $this->versionId < 70300;
187: }
188:
189: public function producesWarningForFinalPrivateMethods(): bool
190: {
191: return $this->versionId >= 80000;
192: }
193:
194: public function deprecatesDynamicProperties(): bool
195: {
196: return $this->versionId >= 80200;
197: }
198:
199: public function strSplitReturnsEmptyArray(): bool
200: {
201: return $this->versionId >= 80200;
202: }
203:
204: public function supportsDisjunctiveNormalForm(): bool
205: {
206: return $this->versionId >= 80200;
207: }
208:
209: public function serializableRequiresMagicMethods(): bool
210: {
211: return $this->versionId >= 80100;
212: }
213:
214: public function arrayFunctionsReturnNullWithNonArray(): bool
215: {
216: return $this->versionId < 80000;
217: }
218:
219: }
220: