3
3
namespace PHPStan \Rules \Functions ;
4
4
5
5
use PHPStan \ShouldNotHappenException ;
6
+ use PHPStan \Type \Accessory \AccessoryNumericStringType ;
6
7
use PHPStan \Type \ErrorType ;
7
8
use PHPStan \Type \FloatType ;
8
9
use PHPStan \Type \IntegerType ;
10
+ use PHPStan \Type \IntersectionType ;
11
+ use PHPStan \Type \NullType ;
9
12
use PHPStan \Type \StringAlwaysAcceptingObjectWithToStringType ;
13
+ use PHPStan \Type \StringType ;
10
14
use PHPStan \Type \Type ;
11
15
use PHPStan \Type \TypeCombinator ;
12
16
@@ -34,7 +38,11 @@ public function doesArgumentTypeMatchPlaceholder(Type $argumentType, bool $stric
34
38
: ! $ argumentType ->toInteger () instanceof ErrorType;
35
39
case 'float ' :
36
40
return $ strictPlaceholderTypes
37
- ? (new FloatType ())->accepts ($ argumentType , true )->yes ()
41
+ ? TypeCombinator::union (
42
+ new FloatType (),
43
+ // numeric-string is allowed for consistency with phpstan-strict-rules.
44
+ new IntersectionType ([new StringType (), new AccessoryNumericStringType ()]),
45
+ )->accepts ($ argumentType , true )->yes ()
38
46
: ! $ argumentType ->toFloat () instanceof ErrorType;
39
47
case 'string ' :
40
48
case 'mixed ' :
@@ -46,6 +54,8 @@ public function doesArgumentTypeMatchPlaceholder(Type $argumentType, bool $stric
46
54
new StringAlwaysAcceptingObjectWithToStringType (),
47
55
// float also accepts int.
48
56
new FloatType (),
57
+ // null is allowed for consistency with phpstan-strict-rules (e.g. $string . $null).
58
+ new NullType (),
49
59
)->accepts ($ argumentType , true )->yes ();
50
60
// Without this PHPStan with PHP 7.4 reports "...should return bool but return statement is missing."
51
61
// Presumably, because promoted properties are turned into regular properties and the phpdoc isn't applied to the property.
0 commit comments