|
6 | 6 | use PHPStan\Turbo\ReferencedByTurboExtension; |
7 | 7 | use PHPStan\Type\IntegerRangeType; |
8 | 8 | use PHPStan\Type\Type; |
| 9 | +use PHPStan\Type\TypeCombinator; |
9 | 10 |
|
10 | 11 | /** |
11 | 12 | * Range-aware PHP version check that handles version uncertainty. |
@@ -188,4 +189,120 @@ public function supportsDeprecatedTraits(): TrinaryLogic |
188 | 189 | return IntegerRangeType::fromInterval(80500, null)->isSuperTypeOf($this->phpVersions)->result; |
189 | 190 | } |
190 | 191 |
|
| 192 | + public function arrayFunctionsReturnNullWithNonArray(): TrinaryLogic |
| 193 | + { |
| 194 | + return IntegerRangeType::fromInterval(null, 79999)->isSuperTypeOf($this->phpVersions)->result; |
| 195 | + } |
| 196 | + |
| 197 | + public function hasDateTimeExceptions(): TrinaryLogic |
| 198 | + { |
| 199 | + return IntegerRangeType::fromInterval(80300, null)->isSuperTypeOf($this->phpVersions)->result; |
| 200 | + } |
| 201 | + |
| 202 | + public function hasFilterThrowOnFailureConstant(): TrinaryLogic |
| 203 | + { |
| 204 | + return IntegerRangeType::fromInterval(80500, null)->isSuperTypeOf($this->phpVersions)->result; |
| 205 | + } |
| 206 | + |
| 207 | + public function hasPDOSubclasses(): TrinaryLogic |
| 208 | + { |
| 209 | + return IntegerRangeType::fromInterval(80400, null)->isSuperTypeOf($this->phpVersions)->result; |
| 210 | + } |
| 211 | + |
| 212 | + public function hasStricterRoundFunctions(): TrinaryLogic |
| 213 | + { |
| 214 | + return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result; |
| 215 | + } |
| 216 | + |
| 217 | + public function highlightStringDoesNotReturnFalse(): TrinaryLogic |
| 218 | + { |
| 219 | + return IntegerRangeType::fromInterval(80400, null)->isSuperTypeOf($this->phpVersions)->result; |
| 220 | + } |
| 221 | + |
| 222 | + public function isEmptyStringValidAliasForNoneInMbSubstituteCharacter(): TrinaryLogic |
| 223 | + { |
| 224 | + return IntegerRangeType::fromInterval(null, 79999)->isSuperTypeOf($this->phpVersions)->result; |
| 225 | + } |
| 226 | + |
| 227 | + public function isNullValidArgInMbSubstituteCharacter(): TrinaryLogic |
| 228 | + { |
| 229 | + return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result; |
| 230 | + } |
| 231 | + |
| 232 | + public function isNumericStringValidArgInMbSubstituteCharacter(): TrinaryLogic |
| 233 | + { |
| 234 | + return IntegerRangeType::fromInterval(null, 79999)->isSuperTypeOf($this->phpVersions)->result; |
| 235 | + } |
| 236 | + |
| 237 | + public function strSplitReturnsEmptyArray(): TrinaryLogic |
| 238 | + { |
| 239 | + return IntegerRangeType::fromInterval(80200, null)->isSuperTypeOf($this->phpVersions)->result; |
| 240 | + } |
| 241 | + |
| 242 | + public function substrReturnFalseInsteadOfEmptyString(): TrinaryLogic |
| 243 | + { |
| 244 | + return IntegerRangeType::fromInterval(null, 79999)->isSuperTypeOf($this->phpVersions)->result; |
| 245 | + } |
| 246 | + |
| 247 | + public function supportsAllUnicodeScalarCodePointsInMbSubstituteCharacter(): TrinaryLogic |
| 248 | + { |
| 249 | + return IntegerRangeType::fromInterval(70200, null)->isSuperTypeOf($this->phpVersions)->result; |
| 250 | + } |
| 251 | + |
| 252 | + public function supportsHhPrintfSpecifier(): TrinaryLogic |
| 253 | + { |
| 254 | + return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result; |
| 255 | + } |
| 256 | + |
| 257 | + public function supportsPassNoneEncodings(): TrinaryLogic |
| 258 | + { |
| 259 | + return IntegerRangeType::fromInterval(null, 70299)->isSuperTypeOf($this->phpVersions)->result; |
| 260 | + } |
| 261 | + |
| 262 | + public function supportsPregCaptureOnlyNamedGroups(): TrinaryLogic |
| 263 | + { |
| 264 | + // https://php.watch/versions/8.2/preg-n-no-capture-modifier |
| 265 | + return IntegerRangeType::fromInterval(80200, null)->isSuperTypeOf($this->phpVersions)->result; |
| 266 | + } |
| 267 | + |
| 268 | + public function supportsPregUnmatchedAsNull(): TrinaryLogic |
| 269 | + { |
| 270 | + // while PREG_UNMATCHED_AS_NULL is defined in php-src since 7.2.x it starts working as expected with 7.4.x |
| 271 | + // https://3v4l.org/v3HE4 |
| 272 | + return IntegerRangeType::fromInterval(70400, null)->isSuperTypeOf($this->phpVersions)->result; |
| 273 | + } |
| 274 | + |
| 275 | + public function throwsOnInvalidMbStringEncoding(): TrinaryLogic |
| 276 | + { |
| 277 | + return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result; |
| 278 | + } |
| 279 | + |
| 280 | + /** |
| 281 | + * PHPStan's BetterReflection adapters keep their narrowed native return types only on PHP 8+; |
| 282 | + * the downgraded PHP 7 build widens them back to the core Reflection ones. |
| 283 | + */ |
| 284 | + public function supportsNativeReflectionAdapterReturnTypes(): TrinaryLogic |
| 285 | + { |
| 286 | + return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result; |
| 287 | + } |
| 288 | + |
| 289 | + /** |
| 290 | + * Resolves a version-dependent type. |
| 291 | + * |
| 292 | + * When the analysed PHP version range spans both sides of $versionCheck, |
| 293 | + * neither branch can be ruled out and the union of both is returned. |
| 294 | + */ |
| 295 | + public static function pickType(TrinaryLogic $versionCheck, Type $ifYes, Type $ifNo): Type |
| 296 | + { |
| 297 | + if ($versionCheck->yes()) { |
| 298 | + return $ifYes; |
| 299 | + } |
| 300 | + |
| 301 | + if ($versionCheck->no()) { |
| 302 | + return $ifNo; |
| 303 | + } |
| 304 | + |
| 305 | + return TypeCombinator::union($ifYes, $ifNo); |
| 306 | + } |
| 307 | + |
191 | 308 | } |
0 commit comments