Completed
Pull Request — master (#291)
by Juliette
02:26
created

NewFunctionParametersSniff::getErrorInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
/**
3
 * PHPCompatibility_Sniffs_PHP_NewFunctionParametersSniff.
4
 *
5
 * @category  PHP
6
 * @package   PHPCompatibility
7
 * @author    Wim Godden <[email protected]>
8
 */
9
10
/**
11
 * PHPCompatibility_Sniffs_PHP_newFunctionParametersSniff.
12
 *
13
 * @category  PHP
14
 * @package   PHPCompatibility
15
 * @author    Wim Godden <[email protected]>
16
 */
17
class PHPCompatibility_Sniffs_PHP_NewFunctionParametersSniff
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
18
    extends PHPCompatibility_AbstractNewFeatureSniff
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
19
{
20
    /**
21
     * A list of new functions, not present in older versions.
22
     *
23
     * The array lists : version number with false (not present) or true (present).
24
     * The index is the location of the parameter in the parameter list, starting at 0 !
25
     * If's sufficient to list the first version where the function appears.
26
     *
27
     * @var array
28
     */
29
    protected $newFunctionParameters = array(
30
                                        'array_filter' => array(
31
                                            2 => array(
32
                                                'name' => 'flag',
33
                                                '5.5' => false,
34
                                                '5.6' => true
35
                                            ),
36
                                        ),
37
                                        'array_slice' => array(
38
                                            1 => array(
39
                                                'name' => 'preserve_keys',
40
                                                '5.0.1' => false,
41
                                                '5.0.2' => true
42
                                            ),
43
                                        ),
44
                                        'array_unique' => array(
45
                                            1 => array(
46
                                                'name' => 'sort_flags',
47
                                                '5.2.8' => false,
48
                                                '5.2.9' => true
49
                                            ),
50
                                        ),
51
                                        'assert' => array(
52
                                            1 => array(
53
                                                'name' => 'description',
54
                                                '5.4.7' => false,
55
                                                '5.4.8' => true
56
                                            ),
57
                                        ),
58
                                        'base64_decode' => array(
59
                                            1 => array(
60
                                                'name' => 'strict',
61
                                                '5.1' => false,
62
                                                '5.2' => true
63
                                            ),
64
                                        ),
65
                                        'class_implements' => array(
66
                                            1 => array(
67
                                                'name' => 'autoload',
68
                                                '5.0' => false,
69
                                                '5.1' => true
70
                                            ),
71
                                        ),
72
                                        'class_parents' => array(
73
                                            1 => array(
74
                                                'name' => 'autoload',
75
                                                '5.0' => false,
76
                                                '5.1' => true
77
                                            ),
78
                                        ),
79
                                        'clearstatcache' => array(
80
                                            0 => array(
81
                                                'name' => 'clear_realpath_cache',
82
                                                '5.2' => false,
83
                                                '5.3' => true
84
                                            ),
85
                                            1 => array(
86
                                                'name' => 'filename',
87
                                                '5.2' => false,
88
                                                '5.3' => true
89
                                            ),
90
                                        ),
91
                                        'copy' => array(
92
                                            2 => array(
93
                                                'name' => 'context',
94
                                                '5.2' => false,
95
                                                '5.3' => true
96
                                            ),
97
                                        ),
98
                                        'curl_multi_info_read' => array(
99
                                            1 => array(
100
                                                'name' => 'msgs_in_queue',
101
                                                '5.1' => false,
102
                                                '5.2' => true
103
                                            ),
104
                                        ),
105
                                        'debug_backtrace' => array(
106
                                            0 => array(
107
                                                'name' => 'options',
108
                                                '5.2.4' => false,
109
                                                '5.2.5' => true
110
                                            ),
111
                                            1 => array(
112
                                                'name' => 'limit',
113
                                                '5.3' => false,
114
                                                '5.4' => true
115
                                            ),
116
                                        ),
117
                                        'debug_print_backtrace' => array(
118
                                            0 => array(
119
                                                'name' => 'options',
120
                                                '5.3.5' => false,
121
                                                '5.3.6' => true
122
                                            ),
123
                                            1 => array(
124
                                                'name' => 'limit',
125
                                                '5.3' => false,
126
                                                '5.4' => true
127
                                            ),
128
                                        ),
129
                                        'dirname' => array(
130
                                            1 => array(
131
                                                'name' => 'levels',
132
                                                '5.6' => false,
133
                                                '7.0' => true
134
                                            ),
135
                                        ),
136
                                        'dns_get_record' => array(
137
                                            4 => array(
138
                                                'name' => 'raw',
139
                                                '5.3' => false,
140
                                                '5.4' => true
141
                                            ),
142
                                        ),
143
                                        'fgetcsv' => array(
144
                                            4 => array(
145
                                                'name' => 'escape',
146
                                                '5.2' => false,
147
                                                '5.3' => true
148
                                            ),
149
                                        ),
150
                                        'fputcsv' => array(
151
                                            4 => array(
152
                                                'name' => 'escape_char',
153
                                                '5.5.3' => false,
154
                                                '5.5.4' => true
155
                                            ),
156
                                        ),
157
                                        'file_get_contents' => array(
158
                                            3 => array(
159
                                                'name' => 'offset',
160
                                                '5.0' => false,
161
                                                '5.1' => true
162
                                            ),
163
                                            4 => array(
164
                                                'name' => 'maxlen',
165
                                                '5.0' => false,
166
                                                '5.1' => true
167
                                            ),
168
                                        ),
169
                                        'filter_input_array' => array(
170
                                            2 => array(
171
                                                'name' => 'add_empty',
172
                                                '5.3' => false,
173
                                                '5.4' => true
174
                                            ),
175
                                        ),
176
                                        'filter_var_array' => array(
177
                                            2 => array(
178
                                                'name' => 'add_empty',
179
                                                '5.3' => false,
180
                                                '5.4' => true
181
                                            ),
182
                                        ),
183
                                        'gettimeofday' => array(
184
                                            0 => array(
185
                                                'name' => 'return_float',
186
                                                '5.0' => false,
187
                                                '5.1' => true
188
                                            ),
189
                                        ),
190
                                        'get_html_translation_table' => array(
191
                                            2 => array(
192
                                                'name' => 'encoding',
193
                                                '5.3.3' => false,
194
                                                '5.3.4' => true
195
                                            ),
196
                                        ),
197
                                        'get_loaded_extensions' => array(
198
                                            0 => array(
199
                                                'name' => 'zend_extensions',
200
                                                '5.2.3' => false,
201
                                                '5.2.4' => true
202
                                            ),
203
                                        ),
204
                                        'gzcompress' => array(
205
                                            2 => array(
206
                                                'name' => 'encoding',
207
                                                '5.3' => false,
208
                                                '5.4' => true
209
                                            ),
210
                                        ),
211
                                        'gzdeflate' => array(
212
                                            2 => array(
213
                                                'name' => 'encoding',
214
                                                '5.3' => false,
215
                                                '5.4' => true
216
                                            ),
217
                                        ),
218
                                        'htmlentities' => array(
219
                                            3 => array(
220
                                                'name' => 'double_encode',
221
                                                '5.2.2' => false,
222
                                                '5.2.3' => true
223
                                            ),
224
                                        ),
225
                                        'htmlspecialchars' => array(
226
                                            3 => array(
227
                                                'name' => 'double_encode',
228
                                                '5.2.2' => false,
229
                                                '5.2.3' => true
230
                                            ),
231
                                        ),
232
                                        'http_build_query' => array(
233
                                            2 => array(
234
                                                'name' => 'arg_separator',
235
                                                '5.1.1' => false,
236
                                                '5.1.2' => true
237
                                            ),
238
                                            3 => array(
239
                                                'name' => 'enc_type',
240
                                                '5.3' => false,
241
                                                '5.4' => true
242
                                            ),
243
                                        ),
244
                                        'idn_to_ascii' => array(
245
                                            2 => array(
246
                                                'name' => 'variant',
247
                                                '5.3' => false,
248
                                                '5.4' => true
249
                                            ),
250
                                            3 => array(
251
                                                'name' => 'idna_info',
252
                                                '5.3' => false,
253
                                                '5.4' => true
254
                                            ),
255
                                        ),
256
                                        'idn_to_utf8' => array(
257
                                            2 => array(
258
                                                'name' => 'variant',
259
                                                '5.3' => false,
260
                                                '5.4' => true
261
                                            ),
262
                                            3 => array(
263
                                                'name' => 'idna_info',
264
                                                '5.3' => false,
265
                                                '5.4' => true
266
                                            ),
267
                                        ),
268
                                        'imagecolorset' => array(
269
                                            5 => array(
270
                                                'name' => 'alpha',
271
                                                '5.3' => false,
272
                                                '5.4' => true
273
                                            ),
274
                                        ),
275
                                        'imagepng' => array(
276
                                            2 => array(
277
                                                'name' => 'quality',
278
                                                '5.1.1' => false,
279
                                                '5.1.2' => true
280
                                            ),
281
                                            3 => array(
282
                                                'name' => 'filters',
283
                                                '5.1.2' => false,
284
                                                '5.1.3' => true
285
                                            ),
286
                                        ),
287
                                        'imagerotate' => array(
288
                                            3 => array(
289
                                                'name' => 'ignore_transparent',
290
                                                '5.0' => false,
291
                                                '5.1' => true
292
                                            ),
293
                                        ),
294
                                        'imap_open' => array(
295
                                            4 => array(
296
                                                'name' => 'n_retries',
297
                                                '5.1' => false,
298
                                                '5.2' => true
299
                                            ),
300
                                            5 => array(
301
                                                'name' => 'params',
302
                                                '5.3.1' => false,
303
                                                '5.3.2' => true
304
                                            ),
305
                                        ),
306
                                        'imap_reopen' => array(
307
                                            3 => array(
308
                                                'name' => 'n_retries',
309
                                                '5.1' => false,
310
                                                '5.2' => true
311
                                            ),
312
                                        ),
313
                                        'ini_get_all' => array(
314
                                            1 => array(
315
                                                'name' => 'details',
316
                                                '5.2' => false,
317
                                                '5.3' => true
318
                                            ),
319
                                        ),
320
                                        'is_a' => array(
321
                                            2 => array(
322
                                                'name' => 'allow_string',
323
                                                '5.3.8' => false,
324
                                                '5.3.9' => true
325
                                            ),
326
                                        ),
327
                                        'is_subclass_of' => array(
328
                                            2 => array(
329
                                                'name' => 'allow_string',
330
                                                '5.3.8' => false,
331
                                                '5.3.9' => true
332
                                            ),
333
                                        ),
334
                                        'iterator_to_array' => array(
335
                                            1 => array(
336
                                                'name' => 'use_keys',
337
                                                '5.2' => false,
338
                                                '5.2.1' => true
339
                                            ),
340
                                        ),
341
                                        'json_decode' => array(
342
                                            2 => array(
343
                                                'name' => 'depth',
344
                                                '5.2' => false,
345
                                                '5.3' => true
346
                                            ),
347
                                            3 => array(
348
                                                'name' => 'options',
349
                                                '5.3' => false,
350
                                                '5.4' => true
351
                                            ),
352
                                        ),
353
                                        'json_encode' => array(
354
                                            1 => array(
355
                                                'name' => 'options',
356
                                                '5.2' => false,
357
                                                '5.3' => true
358
                                            ),
359
                                            2 => array(
360
                                                'name' => 'depth',
361
                                                '5.4' => false,
362
                                                '5.5' => true
363
                                            ),
364
                                        ),
365
                                        'memory_get_peak_usage' => array(
366
                                            0 => array(
367
                                                'name' => 'real_usage',
368
                                                '5.1' => false,
369
                                                '5.2' => true
370
                                            ),
371
                                        ),
372
                                        'memory_get_usage' => array(
373
                                            0 => array(
374
                                                'name' => 'real_usage',
375
                                                '5.1' => false,
376
                                                '5.2' => true
377
                                            ),
378
                                        ),
379
                                        'mb_encode_numericentity' => array(
380
                                            3 => array(
381
                                                'name' => 'is_hex',
382
                                                '5.3' => false,
383
                                                '5.4' => true
384
                                            ),
385
                                        ),
386
                                        'mb_strrpos' => array(
387
                                            /*
388
                                             * Note: the actual position is 2, but the original 3rd
389
                                             * parameter 'encoding' was moved to the 4th position.
390
                                             * So the only way to detect if offset is used is when
391
                                             * both offset and encoding are set.
392
                                             */
393
                                            3 => array(
394
                                                'name' => 'offset',
395
                                                '5.1' => false,
396
                                                '5.2' => true
397
                                            ),
398
                                        ),
399
                                        'mssql_connect' => array(
400
                                            3 => array(
401
                                                'name' => 'new_link',
402
                                                '5.0' => false,
403
                                                '5.1' => true
404
                                            ),
405
                                        ),
406
                                        'mysqli_commit' => array(
407
                                            1 => array(
408
                                                'name' => 'flags',
409
                                                '5.4' => false,
410
                                                '5.5' => true
411
                                            ),
412
                                            2 => array(
413
                                                'name' => 'name',
414
                                                '5.4' => false,
415
                                                '5.5' => true
416
                                            ),
417
                                        ),
418
                                        'mysqli_rollback' => array(
419
                                            1 => array(
420
                                                'name' => 'flags',
421
                                                '5.4' => false,
422
                                                '5.5' => true
423
                                            ),
424
                                            2 => array(
425
                                                'name' => 'name',
426
                                                '5.4' => false,
427
                                                '5.5' => true
428
                                            ),
429
                                        ),
430
                                        'nl2br' => array(
431
                                            1 => array(
432
                                                'name' => 'is_xhtml',
433
                                                '5.2' => false,
434
                                                '5.3' => true
435
                                            ),
436
                                        ),
437
                                        'openssl_decrypt' => array(
438
                                            4 => array(
439
                                                'name' => 'iv',
440
                                                '5.3.2' => false,
441
                                                '5.3.3' => true
442
                                            ),
443
                                            5 => array(
444
                                                'name' => 'tag',
445
                                                '7.0' => false,
446
                                                '7.1' => true
447
                                            ),
448
                                            6 => array(
449
                                                'name' => 'aad',
450
                                                '7.0' => false,
451
                                                '7.1' => true
452
                                            ),
453
                                        ),
454
                                        'openssl_encrypt' => array(
455
                                            4 => array(
456
                                                'name' => 'iv',
457
                                                '5.3.2' => false,
458
                                                '5.3.3' => true
459
                                            ),
460
                                            5 => array(
461
                                                'name' => 'tag',
462
                                                '7.0' => false,
463
                                                '7.1' => true
464
                                            ),
465
                                            6 => array(
466
                                                'name' => 'aad',
467
                                                '7.0' => false,
468
                                                '7.1' => true
469
                                            ),
470
                                            7 => array(
471
                                                'name' => 'tag_length',
472
                                                '7.0' => false,
473
                                                '7.1' => true
474
                                            ),
475
                                        ),
476
                                        'openssl_pkcs7_verify' => array(
477
                                            5 => array(
478
                                                'name' => 'content',
479
                                                '5.0' => false,
480
                                                '5.1' => true
481
                                            ),
482
                                        ),
483
                                        'openssl_seal' => array(
484
                                            4 => array(
485
                                                'name' => 'method',
486
                                                '5.2' => false,
487
                                                '5.3' => true
488
                                            ),
489
                                        ),
490
                                        'openssl_verify' => array(
491
                                            3 => array(
492
                                                'name' => 'signature_alg',
493
                                                '5.1' => false,
494
                                                '5.2' => true
495
                                            ),
496
                                        ),
497
                                        'parse_ini_file' => array(
498
                                            2 => array(
499
                                                'name' => 'scanner_mode',
500
                                                '5.2' => false,
501
                                                '5.3' => true
502
                                            ),
503
                                        ),
504
                                        'parse_url' => array(
505
                                            1 => array(
506
                                                'name' => 'component',
507
                                                '5.1.1' => false,
508
                                                '5.1.2' => true
509
                                            ),
510
                                        ),
511
                                        'pg_lo_create' => array(
512
                                            1 => array(
513
                                                'name' => 'object_id',
514
                                                '5.2' => false,
515
                                                '5.3' => true
516
                                            ),
517
                                        ),
518
                                        'pg_lo_import' => array(
519
                                            2 => array(
520
                                                'name' => 'object_id',
521
                                                '5.2' => false,
522
                                                '5.3' => true
523
                                            ),
524
                                        ),
525
                                        'preg_replace' => array(
526
                                            4 => array(
527
                                                'name' => 'count',
528
                                                '5.0' => false,
529
                                                '5.1' => true
530
                                            ),
531
                                        ),
532
                                        'preg_replace_callback' => array(
533
                                            4 => array(
534
                                                'name' => 'count',
535
                                                '5.0' => false,
536
                                                '5.1' => true
537
                                            ),
538
                                        ),
539
                                        'round' => array(
540
                                            2 => array(
541
                                                'name' => 'mode',
542
                                                '5.2' => false,
543
                                                '5.3' => true
544
                                            ),
545
                                        ),
546
                                        'sem_acquire' => array(
547
                                            1 => array(
548
                                                'name' => 'nowait',
549
                                                '5.6' => false,
550
                                                '5.6.1' => true
551
                                            ),
552
                                        ),
553
                                        'session_regenerate_id' => array(
554
                                            0 => array(
555
                                                'name' => 'delete_old_session',
556
                                                '5.0' => false,
557
                                                '5.1' => true
558
                                            ),
559
                                        ),
560
                                        'session_set_cookie_params' => array(
561
                                            4 => array(
562
                                                'name' => 'httponly',
563
                                                '5.1' => false,
564
                                                '5.2' => true
565
                                            ),
566
                                        ),
567
                                        'session_set_save_handler' => array(
568
                                            6 => array(
569
                                                'name' => 'create_sid',
570
                                                '5.5' => false,
571
                                                '5.5.1' => true
572
                                            ),
573
                                        ),
574
                                        'session_start' => array(
575
                                            0 => array(
576
                                                'name' => 'options',
577
                                                '5.6' => false,
578
                                                '7.0' => true
579
                                            ),
580
                                        ),
581
                                        'setcookie' => array(
582
                                            6 => array(
583
                                                'name' => 'httponly',
584
                                                '5.1' => false,
585
                                                '5.2' => true
586
                                            ),
587
                                        ),
588
                                        'setrawcookie' => array(
589
                                            6 => array(
590
                                                'name' => 'httponly',
591
                                                '5.1' => false,
592
                                                '5.2' => true
593
                                            ),
594
                                        ),
595
                                        'simplexml_load_file' => array(
596
                                            4 => array(
597
                                                'name' => 'is_prefix',
598
                                                '5.1' => false,
599
                                                '5.2' => true
600
                                            ),
601
                                        ),
602
                                        'simplexml_load_string' => array(
603
                                            4 => array(
604
                                                'name' => 'is_prefix',
605
                                                '5.1' => false,
606
                                                '5.2' => true
607
                                            ),
608
                                        ),
609
                                        'spl_autoload_register' => array(
610
                                            2 => array(
611
                                                'name' => 'prepend',
612
                                                '5.2' => false,
613
                                                '5.3' => true
614
                                            ),
615
                                        ),
616
                                        'stream_context_create' => array(
617
                                            1 => array(
618
                                                'name' => 'params',
619
                                                '5.2' => false,
620
                                                '5.3' => true
621
                                            ),
622
                                        ),
623
                                        'stream_copy_to_stream' => array(
624
                                            3 => array(
625
                                                'name' => 'offset',
626
                                                '5.0' => false,
627
                                                '5.1' => true
628
                                            ),
629
                                        ),
630
                                        'stream_get_contents' => array(
631
                                            2 => array(
632
                                                'name' => 'offset',
633
                                                '5.0' => false,
634
                                                '5.1' => true
635
                                            ),
636
                                        ),
637
                                        'stream_wrapper_register' => array(
638
                                            2 => array(
639
                                                'name' => 'flags',
640
                                                '5.2.3' => false,
641
                                                '5.2.4' => true
642
                                            ),
643
                                        ),
644
                                        'stristr' => array(
645
                                            2 => array(
646
                                                'name' => 'before_needle',
647
                                                '5.2' => false,
648
                                                '5.3' => true
649
                                            ),
650
                                        ),
651
                                        'strstr' => array(
652
                                            2 => array(
653
                                                'name' => 'before_needle',
654
                                                '5.2' => false,
655
                                                '5.3' => true
656
                                            ),
657
                                        ),
658
                                        'str_word_count' => array(
659
                                            2 => array(
660
                                                'name' => 'charlist',
661
                                                '5.0' => false,
662
                                                '5.1' => true
663
                                            ),
664
                                        ),
665
                                        'substr_count' => array(
666
                                            2 => array(
667
                                                'name' => 'offset',
668
                                                '5.0' => false,
669
                                                '5.1' => true
670
                                            ),
671
                                            3 => array(
672
                                                'name' => 'length',
673
                                                '5.0' => false,
674
                                                '5.1' => true
675
                                            ),
676
                                        ),
677
                                        'sybase_connect' => array(
678
                                            5 => array(
679
                                                'name' => 'new',
680
                                                '5.2' => false,
681
                                                '5.3' => true
682
                                            ),
683
                                        ),
684
                                        'timezone_transitions_get' => array(
685
                                            1 => array(
686
                                                'name' => 'timestamp_begin',
687
                                                '5.2' => false,
688
                                                '5.3' => true
689
                                            ),
690
                                            2 => array(
691
                                                'name' => 'timestamp_end',
692
                                                '5.2' => false,
693
                                                '5.3' => true
694
                                            ),
695
                                        ),
696
                                        'timezone_identifiers_list' => array(
697
                                            0 => array(
698
                                                'name' => 'what',
699
                                                '5.2' => false,
700
                                                '5.3' => true
701
                                            ),
702
                                            1 => array(
703
                                                'name' => 'country',
704
                                                '5.2' => false,
705
                                                '5.3' => true
706
                                            ),
707
                                        ),
708
                                        'token_get_all' => array(
709
                                            1 => array(
710
                                                'name' => 'flags',
711
                                                '5.6' => false,
712
                                                '7.0' => true
713
                                            ),
714
                                        ),
715
                                        'ucwords' => array(
716
                                            1 => array(
717
                                                'name' => 'delimiters',
718
                                                '5.4.31' => false,
719
                                                '5.5.15' => false,
720
                                                '5.4.32' => true,
721
                                                '5.5.16' => true
722
                                            ),
723
                                        ),
724
                                        'unserialize' => array(
725
                                            1 => array(
726
                                                'name' => 'options',
727
                                                '5.6' => false,
728
                                                '7.0' => true
729
                                            ),
730
                                        ),
731
                                    );
732
733
734
    /**
735
     * Returns an array of tokens this test wants to listen for.
736
     *
737
     * @return array
738
     */
739
    public function register()
740
    {
741
        // Handle case-insensitivity of function names.
742
        $this->newFunctionParameters = $this->arrayKeysToLowercase($this->newFunctionParameters);
743
744
        return array(T_STRING);
745
    }//end register()
746
747
    /**
748
     * Processes this test, when one of its tokens is encountered.
749
     *
750
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
751
     * @param int                  $stackPtr  The position of the current token in
752
     *                                        the stack passed in $tokens.
753
     *
754
     * @return void
755
     */
756 View Code Duplication
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
757
    {
758
        $tokens = $phpcsFile->getTokens();
759
760
        $ignore = array(
761
                T_DOUBLE_COLON,
762
                T_OBJECT_OPERATOR,
763
                T_FUNCTION,
764
                T_CONST,
765
        );
766
767
        $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
768
        if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
769
            // Not a call to a PHP function.
770
            return;
771
        }
772
773
        $function   = $tokens[$stackPtr]['content'];
774
        $functionLc = strtolower($function);
775
776
        if (isset($this->newFunctionParameters[$functionLc]) === false) {
777
            return;
778
        }
779
780
        $parameterCount = $this->getFunctionCallParameterCount($phpcsFile, $stackPtr);
781
        if ($parameterCount === 0) {
782
            return;
783
        }
784
785
        // If the parameter count returned > 0, we know there will be valid open parenthesis.
786
        $openParenthesis = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
787
        $parameterOffsetFound = $parameterCount - 1;
788
789
        foreach($this->newFunctionParameters[$functionLc] as $offset => $parameterDetails) {
790
            if ($offset <= $parameterOffsetFound) {
791
                $itemInfo = array(
792
                    'name'   => $function,
793
                    'nameLc' => $functionLc,
794
                    'offset' => $offset,
795
                );
796
                $this->handleFeature($phpcsFile, $openParenthesis, $itemInfo);
0 ignored issues
show
Security Bug introduced by
It seems like $openParenthesis defined by $phpcsFile->findNext(\PH...null, true, null, true) on line 786 can also be of type false; however, PHPCompatibility_Abstrac...nSniff::handleFeature() does only seem to accept integer, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
797
            }
798
        }
799
800
    }//end process()
801
802
803
    /**
804
     * Get the relevant sub-array for a specific item from a multi-dimensional array.
805
     *
806
     * @param array $itemInfo Base information about the item.
807
     *
808
     * @return array Version and other information about the item.
809
     */
810
    public function getItemArray(array $itemInfo)
811
    {
812
        return $this->newFunctionParameters[$itemInfo['nameLc']][$itemInfo['offset']];
813
    }
814
815
816
    /**
817
     * Get an array of the non-PHP-version array keys used in a sub-array.
818
     *
819
     * @return array
820
     */
821
    protected function getNonVersionArrayKeys()
822
    {
823
        return array('name');
824
    }
825
826
827
    /**
828
     * Retrieve the relevant detail (version) information for use in an error message.
829
     *
830
     * @param array $itemArray Version and other information about the item.
831
     * @param array $itemInfo  Base information about the item.
832
     *
833
     * @return array
834
     */
835
    public function getErrorInfo(array $itemArray, array $itemInfo)
836
    {
837
        $errorInfo = parent::getErrorInfo($itemArray, $itemInfo);
838
        $errorInfo['paramName'] = $itemArray['name'];
839
840
        return $errorInfo;
841
    }
842
843
844
    /**
845
     * Get the item name to be used for the creation of the error code.
846
     *
847
     * @param array $itemInfo  Base information about the item.
848
     * @param array $errorInfo Detail information about an item.
849
     *
850
     * @return string
851
     */
852
    protected function getItemName(array $itemInfo, array $errorInfo)
853
    {
854
        return $itemInfo['name'].'_'.$errorInfo['paramName'];
855
    }
856
857
858
    /**
859
     * Get the error message template for this sniff.
860
     *
861
     * @return string
862
     */
863
    protected function getErrorMsgTemplate()
864
    {
865
        return 'The function %s() does not have a parameter "%s" in PHP version %s or earlier';
866
    }
867
868
869
    /**
870
     * Allow for concrete child classes to filter the error data before it's passed to PHPCS.
871
     *
872
     * @param array $data      The error data array which was created.
873
     * @param array $itemInfo  Base information about the item this error message applied to.
874
     * @param array $errorInfo Detail information about an item this error message applied to.
875
     *
876
     * @return array
877
     */
878
    protected function filterErrorData(array $data, array $itemInfo, array $errorInfo)
879
    {
880
        array_shift($data);
881
        array_unshift($data, $itemInfo['name'], $errorInfo['paramName']);
882
        return $data;
883
    }
884
885
886
}//end class
887