NewFunctionParametersSniff   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 971
Duplicated Lines 4.63 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 13
c 0
b 0
f 0
lcom 1
cbo 1
dl 45
loc 971
rs 9.629

8 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 7 1
B process() 45 45 6
A getItemArray() 0 4 1
A getNonVersionArrayKeys() 0 4 1
A getErrorInfo() 0 7 1
A getItemName() 0 4 1
A getErrorMsgTemplate() 0 4 1
A filterErrorData() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * \PHPCompatibility\Sniffs\PHP\NewFunctionParametersSniff.
4
 *
5
 * @category PHP
6
 * @package  PHPCompatibility
7
 * @author   Wim Godden <[email protected]>
8
 */
9
10
namespace PHPCompatibility\Sniffs\PHP;
11
12
use PHPCompatibility\AbstractNewFeatureSniff;
13
14
/**
15
 * \PHPCompatibility\Sniffs\PHP\newFunctionParametersSniff.
16
 *
17
 * @category PHP
18
 * @package  PHPCompatibility
19
 * @author   Wim Godden <[email protected]>
20
 */
21
class NewFunctionParametersSniff extends AbstractNewFeatureSniff
22
{
23
    /**
24
     * A list of new functions, not present in older versions.
25
     *
26
     * The array lists : version number with false (not present) or true (present).
27
     * The index is the location of the parameter in the parameter list, starting at 0 !
28
     * If's sufficient to list the first version where the function appears.
29
     *
30
     * @var array
31
     */
32
    protected $newFunctionParameters = array(
33
        'array_filter' => array(
34
            2 => array(
35
                'name' => 'flag',
36
                '5.5'  => false,
37
                '5.6'  => true,
38
            ),
39
        ),
40
        'array_slice' => array(
41
            1 => array(
42
                'name'  => 'preserve_keys',
43
                '5.0.1' => false,
44
                '5.0.2' => true,
45
            ),
46
        ),
47
        'array_unique' => array(
48
            1 => array(
49
                'name'  => 'sort_flags',
50
                '5.2.8' => false,
51
                '5.2.9' => true,
52
            ),
53
        ),
54
        'assert' => array(
55
            1 => array(
56
                'name'  => 'description',
57
                '5.4.7' => false,
58
                '5.4.8' => true,
59
            ),
60
        ),
61
        'base64_decode' => array(
62
            1 => array(
63
                'name' => 'strict',
64
                '5.1'  => false,
65
                '5.2'  => true,
66
            ),
67
        ),
68
        'bcmod' => array(
69
            2 => array(
70
                'name' => 'scale',
71
                '7.1'  => false,
72
                '7.2'  => true,
73
            ),
74
        ),
75
        'class_implements' => array(
76
            1 => array(
77
                'name' => 'autoload',
78
                '5.0'  => false,
79
                '5.1'  => true,
80
            ),
81
        ),
82
        'class_parents' => array(
83
            1 => array(
84
                'name' => 'autoload',
85
                '5.0'  => false,
86
                '5.1'  => true,
87
            ),
88
        ),
89
        'clearstatcache' => array(
90
            0 => array(
91
                'name' => 'clear_realpath_cache',
92
                '5.2'  => false,
93
                '5.3'  => true,
94
            ),
95
            1 => array(
96
                'name' => 'filename',
97
                '5.2'  => false,
98
                '5.3'  => true,
99
            ),
100
        ),
101
        'copy' => array(
102
            2 => array(
103
                'name' => 'context',
104
                '5.2'  => false,
105
                '5.3'  => true,
106
            ),
107
        ),
108
        'curl_multi_info_read' => array(
109
            1 => array(
110
                'name' => 'msgs_in_queue',
111
                '5.1'  => false,
112
                '5.2'  => true,
113
            ),
114
        ),
115
        'debug_backtrace' => array(
116
            0 => array(
117
                'name'  => 'options',
118
                '5.2.4' => false,
119
                '5.2.5' => true,
120
            ),
121
            1 => array(
122
                'name' => 'limit',
123
                '5.3'  => false,
124
                '5.4'  => true,
125
            ),
126
        ),
127
        'debug_print_backtrace' => array(
128
            0 => array(
129
                'name'  => 'options',
130
                '5.3.5' => false,
131
                '5.3.6' => true,
132
            ),
133
            1 => array(
134
                'name' => 'limit',
135
                '5.3'  => false,
136
                '5.4'  => true,
137
            ),
138
        ),
139
        'dirname' => array(
140
            1 => array(
141
                'name' => 'levels',
142
                '5.6'  => false,
143
                '7.0'  => true,
144
            ),
145
        ),
146
        'dns_get_record' => array(
147
            4 => array(
148
                'name' => 'raw',
149
                '5.3'  => false,
150
                '5.4'  => true,
151
            ),
152
        ),
153
        'fgetcsv' => array(
154
            4 => array(
155
                'name' => 'escape',
156
                '5.2'  => false,
157
                '5.3'  => true,
158
            ),
159
        ),
160
        'fputcsv' => array(
161
            4 => array(
162
                'name'  => 'escape_char',
163
                '5.5.3' => false,
164
                '5.5.4' => true,
165
            ),
166
        ),
167
        'file_get_contents' => array(
168
            3 => array(
169
                'name' => 'offset',
170
                '5.0'  => false,
171
                '5.1'  => true,
172
            ),
173
            4 => array(
174
                'name' => 'maxlen',
175
                '5.0'  => false,
176
                '5.1'  => true,
177
            ),
178
        ),
179
        'filter_input_array' => array(
180
            2 => array(
181
                'name' => 'add_empty',
182
                '5.3'  => false,
183
                '5.4'  => true,
184
            ),
185
        ),
186
        'filter_var_array' => array(
187
            2 => array(
188
                'name' => 'add_empty',
189
                '5.3'  => false,
190
                '5.4'  => true,
191
            ),
192
        ),
193
        'getenv' => array(
194
            1 => array(
195
                'name' => 'local_only',
196
                '5.5.37'  => false,
197
                '5.5.38'  => true, // Also introduced in PHP 5.6.24 and 7.0.9.
198
            ),
199
        ),
200
        'getopt' => array(
201
            2 => array(
202
                'name' => 'optind',
203
                '7.0'  => false,
204
                '7.1'  => true,
205
            ),
206
        ),
207
        'gettimeofday' => array(
208
            0 => array(
209
                'name' => 'return_float',
210
                '5.0'  => false,
211
                '5.1'  => true,
212
            ),
213
        ),
214
        'get_defined_functions' => array(
215
            0 => array(
216
                'name'   => 'exclude_disabled',
217
                '7.0.14' => false,
218
                '7.0.15' => true,
219
            ),
220
        ),
221
        'get_headers' => array(
222
            2 => array(
223
                'name' => 'context',
224
                '7.0'  => false,
225
                '7.1'  => true,
226
            ),
227
        ),
228
        'get_html_translation_table' => array(
229
            2 => array(
230
                'name'  => 'encoding',
231
                '5.3.3' => false,
232
                '5.3.4' => true,
233
            ),
234
        ),
235
        'get_loaded_extensions' => array(
236
            0 => array(
237
                'name'  => 'zend_extensions',
238
                '5.2.3' => false,
239
                '5.2.4' => true,
240
            ),
241
        ),
242
        'gzcompress' => array(
243
            2 => array(
244
                'name' => 'encoding',
245
                '5.3'  => false,
246
                '5.4'  => true,
247
            ),
248
        ),
249
        'gzdeflate' => array(
250
            2 => array(
251
                'name' => 'encoding',
252
                '5.3'  => false,
253
                '5.4'  => true,
254
            ),
255
        ),
256
        'htmlentities' => array(
257
            3 => array(
258
                'name'  => 'double_encode',
259
                '5.2.2' => false,
260
                '5.2.3' => true,
261
            ),
262
        ),
263
        'htmlspecialchars' => array(
264
            3 => array(
265
                'name'  => 'double_encode',
266
                '5.2.2' => false,
267
                '5.2.3' => true,
268
            ),
269
        ),
270
        'http_build_query' => array(
271
            2 => array(
272
                'name'  => 'arg_separator',
273
                '5.1.1' => false,
274
                '5.1.2' => true,
275
            ),
276
            3 => array(
277
                'name' => 'enc_type',
278
                '5.3'  => false,
279
                '5.4'  => true,
280
            ),
281
        ),
282
        'idn_to_ascii' => array(
283
            2 => array(
284
                'name' => 'variant',
285
                '5.3'  => false,
286
                '5.4'  => true,
287
            ),
288
            3 => array(
289
                'name' => 'idna_info',
290
                '5.3'  => false,
291
                '5.4'  => true,
292
            ),
293
        ),
294
        'idn_to_utf8' => array(
295
            2 => array(
296
                'name' => 'variant',
297
                '5.3'  => false,
298
                '5.4'  => true,
299
            ),
300
            3 => array(
301
                'name' => 'idna_info',
302
                '5.3'  => false,
303
                '5.4'  => true,
304
            ),
305
        ),
306
        'imagecolorset' => array(
307
            5 => array(
308
                'name' => 'alpha',
309
                '5.3'  => false,
310
                '5.4'  => true,
311
            ),
312
        ),
313
        'imagepng' => array(
314
            2 => array(
315
                'name'  => 'quality',
316
                '5.1.1' => false,
317
                '5.1.2' => true,
318
            ),
319
            3 => array(
320
                'name'  => 'filters',
321
                '5.1.2' => false,
322
                '5.1.3' => true,
323
            ),
324
        ),
325
        'imagerotate' => array(
326
            3 => array(
327
                'name' => 'ignore_transparent',
328
                '5.0'  => false,
329
                '5.1'  => true,
330
            ),
331
        ),
332
        'imap_open' => array(
333
            4 => array(
334
                'name' => 'n_retries',
335
                '5.1'  => false,
336
                '5.2'  => true,
337
            ),
338
            5 => array(
339
                'name'  => 'params',
340
                '5.3.1' => false,
341
                '5.3.2' => true,
342
            ),
343
        ),
344
        'imap_reopen' => array(
345
            3 => array(
346
                'name' => 'n_retries',
347
                '5.1'  => false,
348
                '5.2'  => true,
349
            ),
350
        ),
351
        'ini_get_all' => array(
352
            1 => array(
353
                'name' => 'details',
354
                '5.2'  => false,
355
                '5.3'  => true,
356
            ),
357
        ),
358
        'is_a' => array(
359
            2 => array(
360
                'name'  => 'allow_string',
361
                '5.3.8' => false,
362
                '5.3.9' => true,
363
            ),
364
        ),
365
        'is_subclass_of' => array(
366
            2 => array(
367
                'name'  => 'allow_string',
368
                '5.3.8' => false,
369
                '5.3.9' => true,
370
            ),
371
        ),
372
        'iterator_to_array' => array(
373
            1 => array(
374
                'name'  => 'use_keys',
375
                '5.2.0' => false,
376
                '5.2.1' => true,
377
            ),
378
        ),
379
        'json_decode' => array(
380
            2 => array(
381
                'name' => 'depth',
382
                '5.2'  => false,
383
                '5.3'  => true,
384
            ),
385
            3 => array(
386
                'name' => 'options',
387
                '5.3'  => false,
388
                '5.4'  => true,
389
            ),
390
        ),
391
        'json_encode' => array(
392
            1 => array(
393
                'name' => 'options',
394
                '5.2'  => false,
395
                '5.3'  => true,
396
            ),
397
            2 => array(
398
                'name' => 'depth',
399
                '5.4'  => false,
400
                '5.5'  => true,
401
            ),
402
        ),
403
        'memory_get_peak_usage' => array(
404
            0 => array(
405
                'name' => 'real_usage',
406
                '5.1'  => false,
407
                '5.2'  => true,
408
            ),
409
        ),
410
        'memory_get_usage' => array(
411
            0 => array(
412
                'name' => 'real_usage',
413
                '5.1'  => false,
414
                '5.2'  => true,
415
            ),
416
        ),
417
        'mb_encode_numericentity' => array(
418
            3 => array(
419
                'name' => 'is_hex',
420
                '5.3'  => false,
421
                '5.4'  => true,
422
            ),
423
        ),
424
        'mb_strrpos' => array(
425
            /*
426
             * Note: the actual position is 2, but the original 3rd
427
             * parameter 'encoding' was moved to the 4th position.
428
             * So the only way to detect if offset is used is when
429
             * both offset and encoding are set.
430
             */
431
            3 => array(
432
                'name' => 'offset',
433
                '5.1'  => false,
434
                '5.2'  => true,
435
            ),
436
        ),
437
        'mssql_connect' => array(
438
            3 => array(
439
                'name' => 'new_link',
440
                '5.0'  => false,
441
                '5.1'  => true,
442
            ),
443
        ),
444
        'mysqli_commit' => array(
445
            1 => array(
446
                'name' => 'flags',
447
                '5.4'  => false,
448
                '5.5'  => true,
449
            ),
450
            2 => array(
451
                'name' => 'name',
452
                '5.4'  => false,
453
                '5.5'  => true,
454
            ),
455
        ),
456
        'mysqli_rollback' => array(
457
            1 => array(
458
                'name' => 'flags',
459
                '5.4'  => false,
460
                '5.5'  => true,
461
            ),
462
            2 => array(
463
                'name' => 'name',
464
                '5.4'  => false,
465
                '5.5'  => true,
466
            ),
467
        ),
468
        'nl2br' => array(
469
            1 => array(
470
                'name' => 'is_xhtml',
471
                '5.2'  => false,
472
                '5.3'  => true,
473
            ),
474
        ),
475
        'openssl_decrypt' => array(
476
            4 => array(
477
                'name'  => 'iv',
478
                '5.3.2' => false,
479
                '5.3.3' => true,
480
            ),
481
            5 => array(
482
                'name' => 'tag',
483
                '7.0'  => false,
484
                '7.1'  => true,
485
            ),
486
            6 => array(
487
                'name' => 'aad',
488
                '7.0'  => false,
489
                '7.1'  => true,
490
            ),
491
        ),
492
        'openssl_encrypt' => array(
493
            4 => array(
494
                'name'  => 'iv',
495
                '5.3.2' => false,
496
                '5.3.3' => true,
497
            ),
498
            5 => array(
499
                'name' => 'tag',
500
                '7.0'  => false,
501
                '7.1'  => true,
502
            ),
503
            6 => array(
504
                'name' => 'aad',
505
                '7.0'  => false,
506
                '7.1'  => true,
507
            ),
508
            7 => array(
509
                'name' => 'tag_length',
510
                '7.0'  => false,
511
                '7.1'  => true,
512
            ),
513
        ),
514
        'openssl_open' => array(
515
            4 => array(
516
                'name' => 'method',
517
                '5.2'  => false,
518
                '5.3'  => true,
519
            ),
520
            5 => array(
521
                'name' => 'iv',
522
                '5.6'  => false,
523
                '7.0'  => true,
524
            ),
525
        ),
526
        'openssl_pkcs7_verify' => array(
527
            5 => array(
528
                'name' => 'content',
529
                '5.0'  => false,
530
                '5.1'  => true,
531
            ),
532
            6 => array(
533
                'name' => 'p7bfilename',
534
                '7.1'  => false,
535
                '7.2'  => true,
536
            ),
537
        ),
538
        'openssl_seal' => array(
539
            4 => array(
540
                'name' => 'method',
541
                '5.2'  => false,
542
                '5.3'  => true,
543
            ),
544
            5 => array(
545
                'name' => 'iv',
546
                '5.6'  => false,
547
                '7.0'  => true,
548
            ),
549
        ),
550
        'openssl_verify' => array(
551
            3 => array(
552
                'name' => 'signature_alg',
553
                '5.1'  => false,
554
                '5.2'  => true,
555
            ),
556
        ),
557
        'parse_ini_file' => array(
558
            2 => array(
559
                'name' => 'scanner_mode',
560
                '5.2'  => false,
561
                '5.3'  => true,
562
            ),
563
        ),
564
        'parse_url' => array(
565
            1 => array(
566
                'name'  => 'component',
567
                '5.1.1' => false,
568
                '5.1.2' => true,
569
            ),
570
        ),
571
        'pg_fetch_all' => array(
572
            1 => array(
573
                'name' => 'result_type',
574
                '7.0'  => false,
575
                '7.1'  => true,
576
            ),
577
        ),
578
        'pg_last_notice' => array(
579
            1 => array(
580
                'name' => 'option',
581
                '7.0'  => false,
582
                '7.1'  => true,
583
            ),
584
        ),
585
        'pg_lo_create' => array(
586
            1 => array(
587
                'name' => 'object_id',
588
                '5.2'  => false,
589
                '5.3'  => true,
590
            ),
591
        ),
592
        'pg_lo_import' => array(
593
            2 => array(
594
                'name' => 'object_id',
595
                '5.2'  => false,
596
                '5.3'  => true,
597
            ),
598
        ),
599
        'pg_select' => array(
600
            4 => array(
601
                'name' => 'result_type',
602
                '7.0'  => false,
603
                '7.1'  => true,
604
            ),
605
        ),
606
        'php_uname' => array(
607
            0 => array(
608
                'name' => 'mode',
609
                '5.6'  => false,
610
                '7.0'  => true,
611
            ),
612
        ),
613
        'preg_replace' => array(
614
            4 => array(
615
                'name' => 'count',
616
                '5.0'  => false,
617
                '5.1'  => true,
618
            ),
619
        ),
620
        'preg_replace_callback' => array(
621
            4 => array(
622
                'name' => 'count',
623
                '5.0'  => false,
624
                '5.1'  => true,
625
            ),
626
        ),
627
        'round' => array(
628
            2 => array(
629
                'name' => 'mode',
630
                '5.2'  => false,
631
                '5.3'  => true,
632
            ),
633
        ),
634
        'sem_acquire' => array(
635
            1 => array(
636
                'name'  => 'nowait',
637
                '5.6'   => false,
638
                '5.6.1' => true,
639
            ),
640
        ),
641
        'session_regenerate_id' => array(
642
            0 => array(
643
                'name' => 'delete_old_session',
644
                '5.0'  => false,
645
                '5.1'  => true,
646
            ),
647
        ),
648
        'session_set_cookie_params' => array(
649
            4 => array(
650
                'name' => 'httponly',
651
                '5.1'  => false,
652
                '5.2'  => true,
653
            ),
654
        ),
655
        'session_set_save_handler' => array(
656
            6 => array(
657
                'name'  => 'create_sid',
658
                '5.5.0' => false,
659
                '5.5.1' => true,
660
            ),
661
            7 => array(
662
                'name'  => 'validate_sid',
663
                '5.6' => false,
664
                '7.0' => true,
665
            ),
666
            8 => array(
667
                'name' => 'update_timestamp',
668
                '5.6'  => false,
669
                '7.0'  => true,
670
            ),
671
        ),
672
        'session_start' => array(
673
            0 => array(
674
                'name' => 'options',
675
                '5.6'  => false,
676
                '7.0'  => true,
677
            ),
678
        ),
679
        'setcookie' => array(
680
            6 => array(
681
                'name' => 'httponly',
682
                '5.1'  => false,
683
                '5.2'  => true,
684
            ),
685
        ),
686
        'setrawcookie' => array(
687
            6 => array(
688
                'name' => 'httponly',
689
                '5.1'  => false,
690
                '5.2'  => true,
691
            ),
692
        ),
693
        'simplexml_load_file' => array(
694
            4 => array(
695
                'name' => 'is_prefix',
696
                '5.1'  => false,
697
                '5.2'  => true,
698
            ),
699
        ),
700
        'simplexml_load_string' => array(
701
            4 => array(
702
                'name' => 'is_prefix',
703
                '5.1'  => false,
704
                '5.2'  => true,
705
            ),
706
        ),
707
        'spl_autoload_register' => array(
708
            2 => array(
709
                'name' => 'prepend',
710
                '5.2'  => false,
711
                '5.3'  => true,
712
            ),
713
        ),
714
        'stream_context_create' => array(
715
            1 => array(
716
                'name' => 'params',
717
                '5.2'  => false,
718
                '5.3'  => true,
719
            ),
720
        ),
721
        'stream_copy_to_stream' => array(
722
            3 => array(
723
                'name' => 'offset',
724
                '5.0'  => false,
725
                '5.1'  => true,
726
            ),
727
        ),
728
        'stream_get_contents' => array(
729
            2 => array(
730
                'name' => 'offset',
731
                '5.0'  => false,
732
                '5.1'  => true,
733
            ),
734
        ),
735
        'stream_wrapper_register' => array(
736
            2 => array(
737
                'name'  => 'flags',
738
                '5.2.3' => false,
739
                '5.2.4' => true,
740
            ),
741
        ),
742
        'stristr' => array(
743
            2 => array(
744
                'name' => 'before_needle',
745
                '5.2'  => false,
746
                '5.3'  => true,
747
            ),
748
        ),
749
        'strstr' => array(
750
            2 => array(
751
                'name' => 'before_needle',
752
                '5.2'  => false,
753
                '5.3'  => true,
754
            ),
755
        ),
756
        'str_word_count' => array(
757
            2 => array(
758
                'name' => 'charlist',
759
                '5.0'  => false,
760
                '5.1'  => true,
761
            ),
762
        ),
763
        'substr_count' => array(
764
            2 => array(
765
                'name' => 'offset',
766
                '5.0'  => false,
767
                '5.1'  => true,
768
            ),
769
            3 => array(
770
                'name' => 'length',
771
                '5.0'  => false,
772
                '5.1'  => true,
773
            ),
774
        ),
775
        'sybase_connect' => array(
776
            5 => array(
777
                'name' => 'new',
778
                '5.2'  => false,
779
                '5.3'  => true,
780
            ),
781
        ),
782
        'timezone_transitions_get' => array(
783
            1 => array(
784
                'name' => 'timestamp_begin',
785
                '5.2'  => false,
786
                '5.3'  => true,
787
            ),
788
            2 => array(
789
                'name' => 'timestamp_end',
790
                '5.2'  => false,
791
                '5.3'  => true,
792
            ),
793
        ),
794
        'timezone_identifiers_list' => array(
795
            0 => array(
796
                'name' => 'what',
797
                '5.2'  => false,
798
                '5.3'  => true,
799
            ),
800
            1 => array(
801
                'name' => 'country',
802
                '5.2'  => false,
803
                '5.3'  => true,
804
            ),
805
        ),
806
        'token_get_all' => array(
807
            1 => array(
808
                'name' => 'flags',
809
                '5.6'  => false,
810
                '7.0'  => true,
811
            ),
812
        ),
813
        'ucwords' => array(
814
            1 => array(
815
                'name'   => 'delimiters',
816
                '5.4.31' => false,
817
                '5.5.15' => false,
818
                '5.4.32' => true,
819
                '5.5.16' => true,
820
            ),
821
        ),
822
        'unpack' => array(
823
            2 => array(
824
                'name' => 'offset',
825
                '7.0'  => false,
826
                '7.1'  => true,
827
            ),
828
        ),
829
        'unserialize' => array(
830
            1 => array(
831
                'name' => 'options',
832
                '5.6'  => false,
833
                '7.0'  => true,
834
            ),
835
        ),
836
    );
837
838
839
    /**
840
     * Returns an array of tokens this test wants to listen for.
841
     *
842
     * @return array
843
     */
844
    public function register()
845
    {
846
        // Handle case-insensitivity of function names.
847
        $this->newFunctionParameters = $this->arrayKeysToLowercase($this->newFunctionParameters);
848
849
        return array(T_STRING);
850
    }//end register()
851
852
    /**
853
     * Processes this test, when one of its tokens is encountered.
854
     *
855
     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
856
     * @param int                   $stackPtr  The position of the current token in
857
     *                                         the stack passed in $tokens.
858
     *
859
     * @return void
860
     */
861 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...
862
    {
863
        $tokens = $phpcsFile->getTokens();
864
865
        $ignore = array(
866
            T_DOUBLE_COLON,
867
            T_OBJECT_OPERATOR,
868
            T_FUNCTION,
869
            T_CONST,
870
        );
871
872
        $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
873
        if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
874
            // Not a call to a PHP function.
875
            return;
876
        }
877
878
        $function   = $tokens[$stackPtr]['content'];
879
        $functionLc = strtolower($function);
880
881
        if (isset($this->newFunctionParameters[$functionLc]) === false) {
882
            return;
883
        }
884
885
        $parameterCount = $this->getFunctionCallParameterCount($phpcsFile, $stackPtr);
886
        if ($parameterCount === 0) {
887
            return;
888
        }
889
890
        // If the parameter count returned > 0, we know there will be valid open parenthesis.
891
        $openParenthesis      = $phpcsFile->findNext(\PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
892
        $parameterOffsetFound = $parameterCount - 1;
893
894
        foreach ($this->newFunctionParameters[$functionLc] as $offset => $parameterDetails) {
895
            if ($offset <= $parameterOffsetFound) {
896
                $itemInfo = array(
897
                    'name'   => $function,
898
                    'nameLc' => $functionLc,
899
                    'offset' => $offset,
900
                );
901
                $this->handleFeature($phpcsFile, $openParenthesis, $itemInfo);
902
            }
903
        }
904
905
    }//end process()
906
907
908
    /**
909
     * Get the relevant sub-array for a specific item from a multi-dimensional array.
910
     *
911
     * @param array $itemInfo Base information about the item.
912
     *
913
     * @return array Version and other information about the item.
914
     */
915
    public function getItemArray(array $itemInfo)
916
    {
917
        return $this->newFunctionParameters[$itemInfo['nameLc']][$itemInfo['offset']];
918
    }
919
920
921
    /**
922
     * Get an array of the non-PHP-version array keys used in a sub-array.
923
     *
924
     * @return array
925
     */
926
    protected function getNonVersionArrayKeys()
927
    {
928
        return array('name');
929
    }
930
931
932
    /**
933
     * Retrieve the relevant detail (version) information for use in an error message.
934
     *
935
     * @param array $itemArray Version and other information about the item.
936
     * @param array $itemInfo  Base information about the item.
937
     *
938
     * @return array
939
     */
940
    public function getErrorInfo(array $itemArray, array $itemInfo)
941
    {
942
        $errorInfo = parent::getErrorInfo($itemArray, $itemInfo);
943
        $errorInfo['paramName'] = $itemArray['name'];
944
945
        return $errorInfo;
946
    }
947
948
949
    /**
950
     * Get the item name to be used for the creation of the error code.
951
     *
952
     * @param array $itemInfo  Base information about the item.
953
     * @param array $errorInfo Detail information about an item.
954
     *
955
     * @return string
956
     */
957
    protected function getItemName(array $itemInfo, array $errorInfo)
958
    {
959
        return $itemInfo['name'].'_'.$errorInfo['paramName'];
960
    }
961
962
963
    /**
964
     * Get the error message template for this sniff.
965
     *
966
     * @return string
967
     */
968
    protected function getErrorMsgTemplate()
969
    {
970
        return 'The function %s() does not have a parameter "%s" in PHP version %s or earlier';
971
    }
972
973
974
    /**
975
     * Allow for concrete child classes to filter the error data before it's passed to PHPCS.
976
     *
977
     * @param array $data      The error data array which was created.
978
     * @param array $itemInfo  Base information about the item this error message applied to.
979
     * @param array $errorInfo Detail information about an item this error message applied to.
980
     *
981
     * @return array
982
     */
983
    protected function filterErrorData(array $data, array $itemInfo, array $errorInfo)
984
    {
985
        array_shift($data);
986
        array_unshift($data, $itemInfo['name'], $errorInfo['paramName']);
987
        return $data;
988
    }
989
990
991
}//end class
992