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
@@ -122,6 +127,92 @@ public function testBug11883(): void
122127 ]);
123128 }
124129
130+ public function testBug13775 (): void
131+ {
132+ $ errors = [
133+ [
134+ 'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, string> given. ' ,
135+ 13 ,
136+ ],
137+ [
138+ 'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, string> given. ' ,
139+ 19 ,
140+ ],
141+ [
142+ 'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, string> given. ' ,
143+ 22 ,
144+ ],
145+ [
146+ 'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, string> given. ' ,
147+ 25 ,
148+ ],
149+ [
150+ 'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, array> given. ' ,
151+ 28 ,
152+ ],
153+ [
154+ 'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, stdClass> given. ' ,
155+ 31 ,
156+ ],
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 ));
214+ }
215+
125216 public function testBug12146 (): void
126217 {
127218 $ this ->analyse ([__DIR__ . '/data/bug-12146.php ' ], $ this ->hackPhp74ErrorMessages ([
0 commit comments