33namespace PHPStan \Rules \Functions ;
44
55use PHPStan \ShouldNotHappenException ;
6+ use PHPStan \Type \Accessory \AccessoryNumericStringType ;
67use PHPStan \Type \ErrorType ;
78use PHPStan \Type \FloatType ;
89use PHPStan \Type \IntegerType ;
10+ use PHPStan \Type \IntersectionType ;
11+ use PHPStan \Type \NullType ;
912use PHPStan \Type \StringAlwaysAcceptingObjectWithToStringType ;
13+ use PHPStan \Type \StringType ;
1014use PHPStan \Type \Type ;
1115use PHPStan \Type \TypeCombinator ;
1216
@@ -34,7 +38,11 @@ public function doesArgumentTypeMatchPlaceholder(Type $argumentType, bool $stric
3438 : ! $ argumentType ->toInteger () instanceof ErrorType;
3539 case 'float ' :
3640 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 ()
3846 : ! $ argumentType ->toFloat () instanceof ErrorType;
3947 case 'string ' :
4048 case 'mixed ' :
@@ -46,6 +54,8 @@ public function doesArgumentTypeMatchPlaceholder(Type $argumentType, bool $stric
4654 new StringAlwaysAcceptingObjectWithToStringType (),
4755 // float also accepts int.
4856 new FloatType (),
57+ // null is allowed for consistency with phpstan-strict-rules (e.g. $string . $null).
58+ new NullType (),
4959 )->accepts ($ argumentType , true )->yes ();
5060 // Without this PHPStan with PHP 7.4 reports "...should return bool but return statement is missing."
5161 // Presumably, because promoted properties are turned into regular properties and the phpdoc isn't applied to the property.
0 commit comments