|
5 | 5 | use PhpParser\Node\Expr\FuncCall; |
6 | 6 | use PHPStan\Analyser\Scope; |
7 | 7 | use PHPStan\DependencyInjection\AutowiredService; |
| 8 | +use PHPStan\Php\PhpVersion; |
8 | 9 | use PHPStan\Reflection\FunctionReflection; |
9 | 10 | use PHPStan\Rules\Functions\PrintfHelper; |
10 | 11 | use PHPStan\Type\Accessory\AccessoryNonEmptyStringType; |
|
16 | 17 | use PHPStan\Type\FloatType; |
17 | 18 | use PHPStan\Type\IntegerType; |
18 | 19 | use PHPStan\Type\IntersectionType; |
| 20 | +use PHPStan\Type\NeverType; |
19 | 21 | use PHPStan\Type\NullType; |
20 | 22 | use PHPStan\Type\StringType; |
21 | 23 | use PHPStan\Type\Type; |
|
28 | 30 | final class SscanfFunctionDynamicReturnTypeExtension implements DynamicFunctionReturnTypeExtension |
29 | 31 | { |
30 | 32 |
|
31 | | - public function __construct(private PrintfHelper $printfHelper) |
| 33 | + public function __construct( |
| 34 | + private PrintfHelper $printfHelper, |
| 35 | + private PhpVersion $phpVersion, |
| 36 | + ) |
32 | 37 | { |
33 | 38 | } |
34 | 39 |
|
@@ -56,7 +61,7 @@ public function getTypeFromFunctionCall( |
56 | 61 |
|
57 | 62 | $placeholderCount = $this->printfHelper->getScanfPlaceholdersCount($formatType->getValue()); |
58 | 63 | if ($placeholderCount === null) { |
59 | | - return new NullType(); |
| 64 | + return $this->phpVersion->throwsValueErrorForInternalFunctions() ? new NeverType() : new NullType(); |
60 | 65 | } |
61 | 66 |
|
62 | 67 | if (preg_match_all('/%(\d*)(\[[^\]]+\]|[cdeEfosux]{1})/', $formatType->getValue(), $matches) > 0) { |
|
0 commit comments