Completed
Push — master ( bd0f66...26d0b6 )
by Wim
02:50
created

NewFunctionParametersSniff   C

Complexity

Total Complexity 14

Size/Duplication

Total Lines 799
Duplicated Lines 4.88 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 11
Bugs 4 Features 3
Metric Value
wmc 14
c 11
b 4
f 3
lcom 1
cbo 3
dl 39
loc 799
rs 6.9999

3 Methods

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