Completed
Pull Request — master (#164)
by Juliette
08:33 queued 06:00
created

NewFunctionParametersSniff   C

Complexity

Total Complexity 16

Size/Duplication

Total Lines 813
Duplicated Lines 9.47 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 10
Bugs 4 Features 3
Metric Value
wmc 16
c 10
b 4
f 3
lcom 1
cbo 3
dl 77
loc 813
rs 5.2093

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 14 14 3
B process() 39 39 6
C addError() 24 24 7

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