|
7 | 7 | use PHPStan\Analyser\Scope; |
8 | 8 | use PHPStan\DependencyInjection\AutowiredService; |
9 | 9 | use PHPStan\Reflection\MethodReflection; |
10 | | -use PHPStan\Type\Accessory\AccessoryLowercaseStringType; |
| 10 | +use PHPStan\Type\Accessory\AccessoryLiteralStringType; |
11 | 11 | use PHPStan\Type\Accessory\AccessoryNonEmptyStringType; |
12 | | -use PHPStan\Type\Accessory\AccessoryNonFalsyStringType; |
13 | | -use PHPStan\Type\Accessory\AccessoryNumericStringType; |
14 | | -use PHPStan\Type\Accessory\AccessoryUppercaseStringType; |
| 12 | +use PHPStan\Type\Constant\ConstantStringType; |
15 | 13 | use PHPStan\Type\DynamicMethodReturnTypeExtension; |
| 14 | +use PHPStan\Type\GeneralizePrecision; |
16 | 15 | use PHPStan\Type\IntersectionType; |
17 | 16 | use PHPStan\Type\StringType; |
18 | 17 | use PHPStan\Type\Type; |
@@ -53,37 +52,18 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method |
53 | 52 | return null; |
54 | 53 | } |
55 | 54 |
|
56 | | - // The worst case scenario for the non-falsy-string check is that every number are 0. |
| 55 | + // The worst case scenario for the non-falsy-string check is that every number is 0. |
57 | 56 | $dateInterval = new DateInterval('P0D'); |
58 | 57 |
|
59 | 58 | $possibleReturnTypes = []; |
60 | 59 | foreach ($constantStrings as $string) { |
61 | 60 | $value = $dateInterval->format($string->getValue()); |
62 | | - |
63 | | - $accessories = []; |
64 | | - if (is_numeric($value)) { |
65 | | - $accessories[] = new AccessoryNumericStringType(); |
66 | | - } |
67 | | - if ($value !== '0' && $value !== '') { |
68 | | - $accessories[] = new AccessoryNonFalsyStringType(); |
69 | | - } elseif ($value !== '') { |
70 | | - $accessories[] = new AccessoryNonEmptyStringType(); |
71 | | - } |
72 | | - if (strtolower($value) === $value) { |
73 | | - $accessories[] = new AccessoryLowercaseStringType(); |
74 | | - } |
75 | | - if (strtoupper($value) === $value) { |
76 | | - $accessories[] = new AccessoryUppercaseStringType(); |
77 | | - } |
78 | | - |
79 | | - if (count($accessories) === 0) { |
80 | | - return null; |
81 | | - } |
82 | | - |
83 | | - $possibleReturnTypes[] = new IntersectionType([new StringType(), ...$accessories]); |
| 61 | + $possibleReturnTypes[] = new ConstantStringType($value); |
84 | 62 | } |
85 | 63 |
|
86 | | - return TypeCombinator::union(...$possibleReturnTypes); |
| 64 | + $result = TypeCombinator::union(...$possibleReturnTypes)->generalize(GeneralizePrecision::moreSpecific()); |
| 65 | + |
| 66 | + return TypeCombinator::remove($result, new AccessoryLiteralStringType()); |
87 | 67 | } |
88 | 68 |
|
89 | 69 | } |
0 commit comments