22
33namespace PHPStan \Rules \Functions ;
44
5+ use PHPStan \Php \PhpVersion ;
56use PHPStan \Rules \ParameterCastableToStringCheck ;
67use PHPStan \Rules \Rule ;
78use PHPStan \Rules \RuleLevelHelper ;
@@ -20,7 +21,11 @@ class ParameterCastableToNumberRuleTest extends RuleTestCase
2021 protected function getRule (): Rule
2122 {
2223 $ broker = self ::createReflectionProvider ();
23- return new ParameterCastableToNumberRule ($ broker , new ParameterCastableToStringCheck (new RuleLevelHelper ($ broker , true , false , true , true , true , false , true )));
24+ return new ParameterCastableToNumberRule (
25+ $ broker ,
26+ new ParameterCastableToStringCheck (new RuleLevelHelper ($ broker , true , false , true , true , true , false , true )),
27+ self ::getContainer ()->getByType (PhpVersion::class),
28+ );
2429 }
2530
2631 public function testRule (): void
@@ -124,7 +129,7 @@ public function testBug11883(): void
124129
125130 public function testBug13775 (): void
126131 {
127- $ this -> analyse ([ __DIR__ . ' /data/bug-13775.php ' ], $ this -> hackPhp74ErrorMessages ( [
132+ $ errors = [
128133 [
129134 'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, string> given. ' ,
130135 13 ,
@@ -149,7 +154,63 @@ public function testBug13775(): void
149154 'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, stdClass> given. ' ,
150155 31 ,
151156 ],
152- ]));
157+ [
158+ 'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, GMP|stdClass> given. ' ,
159+ 34 ,
160+ ],
161+ ];
162+
163+ if (PHP_VERSION_ID < 80300 ) {
164+ $ errors [] = [
165+ 'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, GMP> given. ' ,
166+ 37 ,
167+ ];
168+ }
169+
170+ $ this ->analyse ([__DIR__ . '/data/bug-13775.php ' ], $ this ->hackPhp74ErrorMessages ($ errors ));
171+ }
172+
173+ public function testBug13775Bis (): void
174+ {
175+ $ errors = [
176+ [
177+ 'Parameter #1 $array of function array_sum expects an array of values castable to number, array<int, string> given. ' ,
178+ 13 ,
179+ ],
180+ [
181+ 'Parameter #1 $array of function array_sum expects an array of values castable to number, array<int, string> given. ' ,
182+ 19 ,
183+ ],
184+ [
185+ 'Parameter #1 $array of function array_sum expects an array of values castable to number, array<int, string> given. ' ,
186+ 22 ,
187+ ],
188+ [
189+ 'Parameter #1 $array of function array_sum expects an array of values castable to number, array<int, string> given. ' ,
190+ 25 ,
191+ ],
192+ [
193+ 'Parameter #1 $array of function array_sum expects an array of values castable to number, array<int, array> given. ' ,
194+ 28 ,
195+ ],
196+ [
197+ 'Parameter #1 $array of function array_sum expects an array of values castable to number, array<int, stdClass> given. ' ,
198+ 31 ,
199+ ],
200+ [
201+ 'Parameter #1 $array of function array_sum expects an array of values castable to number, array<int, GMP|stdClass> given. ' ,
202+ 34 ,
203+ ],
204+ ];
205+
206+ if (PHP_VERSION_ID < 80300 ) {
207+ $ errors [] = [
208+ 'Parameter #1 $array of function array_sum expects an array of values castable to number, array<int, GMP> given. ' ,
209+ 37 ,
210+ ];
211+ }
212+
213+ $ this ->analyse ([__DIR__ . '/data/bug-13775-bis.php ' ], $ this ->hackPhp74ErrorMessages ($ errors ));
153214 }
154215
155216 public function testBug12146 (): void
0 commit comments