1414class PrintfParameterTypeRuleTest extends RuleTestCase
1515{
1616
17+ private bool $ checkStrictPrintfPlaceholderTypes = false ;
18+
1719 protected function getRule (): Rule
1820 {
1921 $ reflectionProvider = $ this ->createReflectionProvider ();
@@ -30,6 +32,7 @@ protected function getRule(): Rule
3032 true ,
3133 false ,
3234 ),
35+ $ this ->checkStrictPrintfPlaceholderTypes ,
3336 );
3437 }
3538
@@ -111,4 +114,139 @@ public function test(): void
111114 ]);
112115 }
113116
117+ public function testStrict (): void
118+ {
119+ $ this ->checkStrictPrintfPlaceholderTypes = true ;
120+ $ this ->analyse ([__DIR__ . '/data/printf-param-types.php ' ], [
121+ [
122+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%d"), PrintfParamTypes \\FooStringable given. ' ,
123+ 15 ,
124+ ],
125+ [
126+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%d"), int|PrintfParamTypes \\FooStringable given. ' ,
127+ 16 ,
128+ ],
129+ [
130+ 'Parameter #2 of function printf is expected to be float by placeholder #1 ("%f"), PrintfParamTypes \\FooStringable given. ' ,
131+ 17 ,
132+ ],
133+ [
134+ 'Parameter #2 of function sprintf is expected to be int by placeholder #1 ("%d"), PrintfParamTypes \\FooStringable given. ' ,
135+ 18 ,
136+ ],
137+ [
138+ 'Parameter #3 of function fprintf is expected to be float by placeholder #1 ("%f"), PrintfParamTypes \\FooStringable given. ' ,
139+ 19 ,
140+ ],
141+ [
142+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%*s" (width)), string given. ' ,
143+ 20 ,
144+ ],
145+ [
146+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%*s" (width)), float given. ' ,
147+ 21 ,
148+ ],
149+ [
150+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%*s" (width)), SimpleXMLElement given. ' ,
151+ 22 ,
152+ ],
153+ [
154+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%*s" (width)), null given. ' ,
155+ 23 ,
156+ ],
157+ [
158+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%*s" (width)), true given. ' ,
159+ 24 ,
160+ ],
161+ [
162+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%.*s" (precision)), string given. ' ,
163+ 25 ,
164+ ],
165+ [
166+ 'Parameter #2 of function printf is expected to be int by placeholder #2 ("%3$.*s" (precision)), string given. ' ,
167+ 26 ,
168+ ],
169+ [
170+ 'Parameter #2 of function printf is expected to be float by placeholder #1 ("%1$- \'X10.2f"), PrintfParamTypes \\FooStringable given. ' ,
171+ 27 ,
172+ ],
173+ [
174+ 'Parameter #2 of function printf is expected to be float by placeholder #2 ("%1$*.*f" (value)), PrintfParamTypes \\FooStringable given. ' ,
175+ 28 ,
176+ ],
177+ [
178+ 'Parameter #4 of function printf is expected to be float by placeholder #1 ("%3$f"), PrintfParamTypes \\FooStringable given. ' ,
179+ 29 ,
180+ ],
181+ [
182+ 'Parameter #2 of function printf is expected to be float by placeholder #1 ("%1$f"), PrintfParamTypes \\FooStringable given. ' ,
183+ 30 ,
184+ ],
185+ [
186+ 'Parameter #2 of function printf is expected to be int by placeholder #2 ("%1$d"), PrintfParamTypes \\FooStringable given. ' ,
187+ 30 ,
188+ ],
189+ [
190+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%1$*d" (width)), float given. ' ,
191+ 31 ,
192+ ],
193+ [
194+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%1$*d" (value)), float given. ' ,
195+ 31 ,
196+ ],
197+ [
198+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%d"), float given. ' ,
199+ 34 ,
200+ ],
201+ [
202+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%d"), float|int given. ' ,
203+ 35 ,
204+ ],
205+ [
206+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%d"), string given. ' ,
207+ 36 ,
208+ ],
209+ [
210+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%d"), string given. ' ,
211+ 37 ,
212+ ],
213+ [
214+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%d"), null given. ' ,
215+ 38 ,
216+ ],
217+ [
218+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%d"), true given. ' ,
219+ 39 ,
220+ ],
221+ [
222+ 'Parameter #2 of function printf is expected to be int by placeholder #1 ("%d"), SimpleXMLElement given. ' ,
223+ 40 ,
224+ ],
225+ [
226+ 'Parameter #2 of function printf is expected to be float by placeholder #1 ("%f"), string given. ' ,
227+ 42 ,
228+ ],
229+ [
230+ 'Parameter #2 of function printf is expected to be float by placeholder #1 ("%f"), null given. ' ,
231+ 43 ,
232+ ],
233+ [
234+ 'Parameter #2 of function printf is expected to be float by placeholder #1 ("%f"), true given. ' ,
235+ 44 ,
236+ ],
237+ [
238+ 'Parameter #2 of function printf is expected to be float by placeholder #1 ("%f"), SimpleXMLElement given. ' ,
239+ 45 ,
240+ ],
241+ [
242+ 'Parameter #2 of function printf is expected to be __stringandstringable by placeholder #1 ("%s"), null given. ' ,
243+ 47 ,
244+ ],
245+ [
246+ 'Parameter #2 of function printf is expected to be __stringandstringable by placeholder #1 ("%s"), true given. ' ,
247+ 48 ,
248+ ],
249+ ]);
250+ }
251+
114252}
0 commit comments