Completed
Push — code-coverage ( 83c44c...faec82 )
by Wim
03:12
created

PHPCompatibility_Sniffs_PHP_NewFunctionsSniff   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 1333
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 7
Bugs 2 Features 2
Metric Value
wmc 17
c 7
b 2
f 2
lcom 1
cbo 2
dl 1333
loc 1333
rs 9.2173

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 17 17 3
C process() 49 49 7
C addError() 28 28 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_NewFunctionsSniff.
4
 *
5
 * @category  PHP
6
 * @package   PHPCompatibility
7
 * @author    Wim Godden <[email protected]>
8
 */
9
10
/**
11
 * PHPCompatibility_Sniffs_PHP_newFunctionsSniff.
12
 *
13
 * @category  PHP
14
 * @package   PHPCompatibility
15
 * @author    Wim Godden <[email protected]>
16
 */
17 View Code Duplication
class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff 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...
Duplication introduced by
This class 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...
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
     * If's sufficient to list the first version where the function appears.
32
     *
33
     * @var array(string => array(string => int|string|null))
34
     */
35
    protected $forbiddenFunctions = array(
36
                                        'array_fill_keys' => array(
37
                                            '5.1' => false,
38
                                            '5.2' => true
39
                                        ),
40
                                        'error_get_last' => array(
41
                                            '5.1' => false,
42
                                            '5.2' => true
43
                                        ),
44
                                        'image_type_to_extension' => array(
45
                                            '5.1' => false,
46
                                            '5.2' => true
47
                                        ),
48
                                        'memory_get_peak_usage' => array(
49
                                            '5.1' => false,
50
                                            '5.2' => true
51
                                        ),
52
                                        'sys_get_temp_dir' => array(
53
                                            '5.1' => false,
54
                                            '5.2' => true
55
                                        ),
56
                                        'timezone_abbreviations_list' => array(
57
                                            '5.1' => false,
58
                                            '5.2' => true
59
                                        ),
60
                                        'timezone_identifiers_list' => array(
61
                                            '5.1' => false,
62
                                            '5.2' => true
63
                                        ),
64
                                        'timezone_name_from_abbr' => array(
65
                                            '5.1' => false,
66
                                            '5.2' => true
67
                                        ),
68
                                        'stream_socket_shutdown' => array(
69
                                            '5.1' => false,
70
                                            '5.2' => true
71
                                        ),
72
                                        'imagegrabscreen' => array(
73
                                            '5.1' => false,
74
                                            '5.2' => true
75
                                        ),
76
                                        'imagegrabwindow' => array(
77
                                            '5.1' => false,
78
                                            '5.2' => true
79
                                        ),
80
                                        'libxml_disable_entity_loader' => array(
81
                                            '5.1' => false,
82
                                            '5.2' => true
83
                                        ),
84
                                        'mb_stripos' => array(
85
                                            '5.1' => false,
86
                                            '5.2' => true
87
                                        ),
88
                                        'mb_stristr' => array(
89
                                            '5.1' => false,
90
                                            '5.2' => true
91
                                        ),
92
                                        'mb_strrchr' => array(
93
                                            '5.1' => false,
94
                                            '5.2' => true
95
                                        ),
96
                                        'mb_strrichr' => array(
97
                                            '5.1' => false,
98
                                            '5.2' => true
99
                                        ),
100
                                        'mb_strripos' => array(
101
                                            '5.1' => false,
102
                                            '5.2' => true
103
                                        ),
104
                                        'ming_setSWFCompression' => array(
105
                                            '5.1' => false,
106
                                            '5.2' => true
107
                                        ),
108
                                        'openssl_csr_get_public_key' => array(
109
                                            '5.1' => false,
110
                                            '5.2' => true
111
                                        ),
112
                                        'openssl_csr_get_subject' => array(
113
                                            '5.1' => false,
114
                                            '5.2' => true
115
                                        ),
116
                                        'openssl_pkey_get_details' => array(
117
                                            '5.1' => false,
118
                                            '5.2' => true
119
                                        ),
120
                                        'spl_object_hash' => array(
121
                                            '5.1' => false,
122
                                            '5.2' => true
123
                                        ),
124
                                        'iterator_apply' => array(
125
                                            '5.1' => false,
126
                                            '5.2' => true
127
                                        ),
128
                                        'preg_last_error' => array(
129
                                            '5.1' => false,
130
                                            '5.2' => true
131
                                        ),
132
                                        'pg_field_table' => array(
133
                                            '5.1' => false,
134
                                            '5.2' => true
135
                                        ),
136
                                        'posix_initgroups' => array(
137
                                            '5.1' => false,
138
                                            '5.2' => true
139
                                        ),
140
                                        'gmp_nextprime' => array(
141
                                            '5.1' => false,
142
                                            '5.2' => true
143
                                        ),
144
                                        'xmlwriter_full_end_element' => array(
145
                                            '5.1' => false,
146
                                            '5.2' => true
147
                                        ),
148
                                        'xmlwriter_write_raw' => array(
149
                                            '5.1' => false,
150
                                            '5.2' => true
151
                                        ),
152
                                        'xmlwriter_start_dtd_entity' => array(
153
                                            '5.1' => false,
154
                                            '5.2' => true
155
                                        ),
156
                                        'xmlwriter_end_dtd_entity' => array(
157
                                            '5.1' => false,
158
                                            '5.2' => true
159
                                        ),
160
                                        'xmlwriter_write_dtd_entity' => array(
161
                                            '5.1' => false,
162
                                            '5.2' => true
163
                                        ),
164
                                        'filter_has_var' => array(
165
                                            '5.1' => false,
166
                                            '5.2' => true
167
                                        ),
168
                                        'filter_id' => array(
169
                                            '5.1' => false,
170
                                            '5.2' => true
171
                                        ),
172
                                        'filter_input_array' => array(
173
                                            '5.1' => false,
174
                                            '5.2' => true
175
                                        ),
176
                                        'filter_input' => array(
177
                                            '5.1' => false,
178
                                            '5.2' => true
179
                                        ),
180
                                        'filter_list' => array(
181
                                            '5.1' => false,
182
                                            '5.2' => true
183
                                        ),
184
                                        'filter_var_array' => array(
185
                                            '5.1' => false,
186
                                            '5.2' => true
187
                                        ),
188
                                        'filter_var' => array(
189
                                            '5.1' => false,
190
                                            '5.2' => true
191
                                        ),
192
                                        'json_decode' => array(
193
                                            '5.1' => false,
194
                                            '5.2' => true
195
                                        ),
196
                                        'json_encode' => array(
197
                                            '5.1' => false,
198
                                            '5.2' => true
199
                                        ),
200
                                        'zip_close' => array(
201
                                            '5.1' => false,
202
                                            '5.2' => true
203
                                        ),
204
                                        'zip_entry_close' => array(
205
                                            '5.1' => false,
206
                                            '5.2' => true
207
                                        ),
208
                                        'zip_entry_compressedsize' => array(
209
                                            '5.1' => false,
210
                                            '5.2' => true
211
                                        ),
212
                                        'zip_entry_compressionmethod' => array(
213
                                            '5.1' => false,
214
                                            '5.2' => true
215
                                        ),
216
                                        'zip_entry_filesize' => array(
217
                                            '5.1' => false,
218
                                            '5.2' => true
219
                                        ),
220
                                        'zip_entry_name' => array(
221
                                            '5.1' => false,
222
                                            '5.2' => true
223
                                        ),
224
                                        'zip_entry_open' => array(
225
                                            '5.1' => false,
226
                                            '5.2' => true
227
                                        ),
228
                                        'zip_entry_read' => array(
229
                                            '5.1' => false,
230
                                            '5.2' => true
231
                                        ),
232
                                        'zip_open' => array(
233
                                            '5.1' => false,
234
                                            '5.2' => true
235
                                        ),
236
                                        'zip_read' => array(
237
                                            '5.1' => false,
238
                                            '5.2' => true
239
                                        ),
240
241
                                        'array_replace' => array(
242
                                            '5.2' => false,
243
                                            '5.3' => true
244
                                        ),
245
                                        'array_replace_recursive' => array(
246
                                            '5.2' => false,
247
                                            '5.3' => true
248
                                        ),
249
                                        'class_alias' => array(
250
                                            '5.2' => false,
251
                                            '5.3' => true
252
                                        ),
253
                                        'forward_static_call' => array(
254
                                            '5.2' => false,
255
                                            '5.3' => true
256
                                        ),
257
                                        'forward_static_call_array' => array(
258
                                            '5.2' => false,
259
                                            '5.3' => true
260
                                        ),
261
                                        'gc_collect_cycles' => array(
262
                                            '5.2' => false,
263
                                            '5.3' => true
264
                                        ),
265
                                        'gc_disable' => array(
266
                                            '5.2' => false,
267
                                            '5.3' => true
268
                                        ),
269
                                        'gc_enable' => array(
270
                                            '5.2' => false,
271
                                            '5.3' => true
272
                                        ),
273
                                        'gc_enabled' => array(
274
                                            '5.2' => false,
275
                                            '5.3' => true
276
                                        ),
277
                                        'get_called_class' => array(
278
                                            '5.2' => false,
279
                                            '5.3' => true
280
                                        ),
281
                                        'gethostname' => array(
282
                                            '5.2' => false,
283
                                            '5.3' => true
284
                                        ),
285
                                        'header_remove' => array(
286
                                            '5.2' => false,
287
                                            '5.3' => true
288
                                        ),
289
                                        'lcfirst' => array(
290
                                            '5.2' => false,
291
                                            '5.3' => true
292
                                        ),
293
                                        'parse_ini_string' => array(
294
                                            '5.2' => false,
295
                                            '5.3' => true
296
                                        ),
297
                                        'quoted_printable_encode' => array(
298
                                            '5.2' => false,
299
                                            '5.3' => true
300
                                        ),
301
                                        'str_getcsv' => array(
302
                                            '5.2' => false,
303
                                            '5.3' => true
304
                                        ),
305
                                        'stream_context_set_default' => array(
306
                                            '5.2' => false,
307
                                            '5.3' => true
308
                                        ),
309
                                        'stream_supports_lock' => array(
310
                                            '5.2' => false,
311
                                            '5.3' => true
312
                                        ),
313
                                        'stream_context_get_params' => array(
314
                                            '5.2' => false,
315
                                            '5.3' => true
316
                                        ),
317
                                        'date_add' => array(
318
                                            '5.2' => false,
319
                                            '5.3' => true
320
                                        ),
321
                                        'date_create_from_format' => array(
322
                                            '5.2' => false,
323
                                            '5.3' => true
324
                                        ),
325
                                        'date_diff' => array(
326
                                            '5.2' => false,
327
                                            '5.3' => true
328
                                        ),
329
                                        'date_get_last_errors' => array(
330
                                            '5.2' => false,
331
                                            '5.3' => true
332
                                        ),
333
                                        'date_parse_from_format' => array(
334
                                            '5.2' => false,
335
                                            '5.3' => true
336
                                        ),
337
                                        'date_sub' => array(
338
                                            '5.2' => false,
339
                                            '5.3' => true
340
                                        ),
341
                                        'timezone_version_get' => array(
342
                                            '5.2' => false,
343
                                            '5.3' => true
344
                                        ),
345
                                        'gmp_testbit' => array(
346
                                            '5.2' => false,
347
                                            '5.3' => true
348
                                        ),
349
                                        'hash_copy' => array(
350
                                            '5.2' => false,
351
                                            '5.3' => true
352
                                        ),
353
                                        'imap_gc' => array(
354
                                            '5.2' => false,
355
                                            '5.3' => true
356
                                        ),
357
                                        'imap_utf8_to_mutf7' => array(
358
                                            '5.2' => false,
359
                                            '5.3' => true
360
                                        ),
361
                                        'imap_mutf7_to_utf8' => array(
362
                                            '5.2' => false,
363
                                            '5.3' => true
364
                                        ),
365
                                        'json_last_error' => array(
366
                                            '5.2' => false,
367
                                            '5.3' => true
368
                                        ),
369
                                        'mysqli_get_cache_stats' => array(
370
                                            '5.2' => false,
371
                                            '5.3' => true
372
                                        ),
373
                                        'mysqli_fetch_all' => array(
374
                                            '5.2' => false,
375
                                            '5.3' => true
376
                                        ),
377
                                        'mysqli_get_connection_status' => array(
378
                                            '5.2' => false,
379
                                            '5.3' => true
380
                                        ),
381
                                        'mysqli_poll' => array(
382
                                            '5.2' => false,
383
                                            '5.3' => true
384
                                        ),
385
                                        'mysqli_read_async_query' => array(
386
                                            '5.2' => false,
387
                                            '5.3' => true
388
                                        ),
389
                                        'openssl_random_pseudo_bytes' => array(
390
                                            '5.2' => false,
391
                                            '5.3' => true
392
                                        ),
393
                                        'pcntl_signal_dispatch' => array(
394
                                            '5.2' => false,
395
                                            '5.3' => true
396
                                        ),
397
                                        'pcntl_sigprocmask' => array(
398
                                            '5.2' => false,
399
                                            '5.3' => true
400
                                        ),
401
                                        'pcntl_sigtimedwait' => array(
402
                                            '5.2' => false,
403
                                            '5.3' => true
404
                                        ),
405
                                        'pcntl_sigwaitinfo' => array(
406
                                            '5.2' => false,
407
                                            '5.3' => true
408
                                        ),
409
                                        'preg_filter' => array(
410
                                            '5.2' => false,
411
                                            '5.3' => true
412
                                        ),
413
                                        'msg_queue_exists' => array(
414
                                            '5.2' => false,
415
                                            '5.3' => true
416
                                        ),
417
                                        'shm_has_vars' => array(
418
                                            '5.2' => false,
419
                                            '5.3' => true
420
                                        ),
421
                                        'acosh' => array(
422
                                            '5.2' => false,
423
                                            '5.3' => true
424
                                        ),
425
                                        'asinh' => array(
426
                                            '5.2' => false,
427
                                            '5.3' => true
428
                                        ),
429
                                        'atanh' => array(
430
                                            '5.2' => false,
431
                                            '5.3' => true
432
                                        ),
433
                                        'expm1' => array(
434
                                            '5.2' => false,
435
                                            '5.3' => true
436
                                        ),
437
                                        'log1p' => array(
438
                                            '5.2' => false,
439
                                            '5.3' => true
440
                                        ),
441
                                        'enchant_broker_describe' => array(
442
                                            '5.2' => false,
443
                                            '5.3' => true
444
                                        ),
445
                                        'enchant_broker_dict_exists' => array(
446
                                            '5.2' => false,
447
                                            '5.3' => true
448
                                        ),
449
                                        'enchant_broker_free_dict' => array(
450
                                            '5.2' => false,
451
                                            '5.3' => true
452
                                        ),
453
                                        'enchant_broker_free' => array(
454
                                            '5.2' => false,
455
                                            '5.3' => true
456
                                        ),
457
                                        'enchant_broker_get_error' => array(
458
                                            '5.2' => false,
459
                                            '5.3' => true
460
                                        ),
461
                                        'enchant_broker_init' => array(
462
                                            '5.2' => false,
463
                                            '5.3' => true
464
                                        ),
465
                                        'enchant_broker_list_dicts' => array(
466
                                            '5.2' => false,
467
                                            '5.3' => true
468
                                        ),
469
                                        'enchant_broker_request_dict' => array(
470
                                            '5.2' => false,
471
                                            '5.3' => true
472
                                        ),
473
                                        'enchant_broker_request_pwl_dict' => array(
474
                                            '5.2' => false,
475
                                            '5.3' => true
476
                                        ),
477
                                        'enchant_broker_set_ordering' => array(
478
                                            '5.2' => false,
479
                                            '5.3' => true
480
                                        ),
481
                                        'enchant_dict_add_to_personal' => array(
482
                                            '5.2' => false,
483
                                            '5.3' => true
484
                                        ),
485
                                        'enchant_dict_add_to_session' => array(
486
                                            '5.2' => false,
487
                                            '5.3' => true
488
                                        ),
489
                                        'enchant_dict_check' => array(
490
                                            '5.2' => false,
491
                                            '5.3' => true
492
                                        ),
493
                                        'enchant_dict_describe' => array(
494
                                            '5.2' => false,
495
                                            '5.3' => true
496
                                        ),
497
                                        'enchant_dict_get_error' => array(
498
                                            '5.2' => false,
499
                                            '5.3' => true
500
                                        ),
501
                                        'enchant_dict_is_in_session' => array(
502
                                            '5.2' => false,
503
                                            '5.3' => true
504
                                        ),
505
                                        'enchant_dict_quick_check' => array(
506
                                            '5.2' => false,
507
                                            '5.3' => true
508
                                        ),
509
                                        'enchant_dict_store_replacement' => array(
510
                                            '5.2' => false,
511
                                            '5.3' => true
512
                                        ),
513
                                        'enchant_dict_suggest' => array(
514
                                            '5.2' => false,
515
                                            '5.3' => true
516
                                        ),
517
                                        'finfo_buffer' => array(
518
                                            '5.2' => false,
519
                                            '5.3' => true
520
                                        ),
521
                                        'finfo_close' => array(
522
                                            '5.2' => false,
523
                                            '5.3' => true
524
                                        ),
525
                                        'finfo_file' => array(
526
                                            '5.2' => false,
527
                                            '5.3' => true
528
                                        ),
529
                                        'finfo_open' => array(
530
                                            '5.2' => false,
531
                                            '5.3' => true
532
                                        ),
533
                                        'finfo_set_flags' => array(
534
                                            '5.2' => false,
535
                                            '5.3' => true
536
                                        ),
537
                                        'intl_error_name' => array(
538
                                            '5.2' => false,
539
                                            '5.3' => true
540
                                        ),
541
                                        'intl_get_error_code' => array(
542
                                            '5.2' => false,
543
                                            '5.3' => true
544
                                        ),
545
                                        'intl_get_error_message' => array(
546
                                            '5.2' => false,
547
                                            '5.3' => true
548
                                        ),
549
                                        'intl_is_failure' => array(
550
                                            '5.2' => false,
551
                                            '5.3' => true
552
                                        ),
553
554
                                        'hex2bin' => array(
555
                                            '5.3' => false,
556
                                            '5.4' => true
557
                                        ),
558
                                        'http_response_code' => array(
559
                                            '5.3' => false,
560
                                            '5.4' => true
561
                                        ),
562
                                        'get_declared_traits' => array(
563
                                            '5.3' => false,
564
                                            '5.4' => true
565
                                        ),
566
                                        'getimagesizefromstring' => array(
567
                                            '5.3' => false,
568
                                            '5.4' => true
569
                                        ),
570
                                        'stream_set_chunk_size' => array(
571
                                            '5.3' => false,
572
                                            '5.4' => true
573
                                        ),
574
                                        'socket_import_stream' => array(
575
                                            '5.3' => false,
576
                                            '5.4' => true
577
                                        ),
578
                                        'trait_exists' => array(
579
                                            '5.3' => false,
580
                                            '5.4' => true
581
                                        ),
582
                                        'header_register_callback' => array(
583
                                            '5.3' => false,
584
                                            '5.4' => true
585
                                        ),
586
                                        'class_uses' => array(
587
                                            '5.3' => false,
588
                                            '5.4' => true
589
                                        ),
590
                                        'session_status' => array(
591
                                            '5.3' => false,
592
                                            '5.4' => true
593
                                        ),
594
                                        'session_register_shutdown' => array(
595
                                            '5.3' => false,
596
                                            '5.4' => true
597
                                        ),
598
                                        'mysqli_error_list' => array(
599
                                            '5.3' => false,
600
                                            '5.4' => true
601
                                        ),
602
                                        'mysqli_stmt_error_list' => array(
603
                                            '5.3' => false,
604
                                            '5.4' => true
605
                                        ),
606
                                        'libxml_set_external_entity_loader' => array(
607
                                            '5.3' => false,
608
                                            '5.4' => true
609
                                        ),
610
                                        'ldap_control_paged_result' => array(
611
                                            '5.3' => false,
612
                                            '5.4' => true
613
                                        ),
614
                                        'ldap_control_paged_result_response' => array(
615
                                            '5.3' => false,
616
                                            '5.4' => true
617
                                        ),
618
                                        'transliteral_create' => array(
619
                                            '5.3' => false,
620
                                            '5.4' => true
621
                                        ),
622
                                        'transliteral_create_from_rules' => array(
623
                                            '5.3' => false,
624
                                            '5.4' => true
625
                                        ),
626
                                        'transliteral_create_inverse' => array(
627
                                            '5.3' => false,
628
                                            '5.4' => true
629
                                        ),
630
                                        'transliteral_get_error_code' => array(
631
                                            '5.3' => false,
632
                                            '5.4' => true
633
                                        ),
634
                                        'transliteral_get_error_message' => array(
635
                                            '5.3' => false,
636
                                            '5.4' => true
637
                                        ),
638
                                        'transliteral_list_ids' => array(
639
                                            '5.3' => false,
640
                                            '5.4' => true
641
                                        ),
642
                                        'transliteral_transliterate' => array(
643
                                            '5.3' => false,
644
                                            '5.4' => true
645
                                        ),
646
                                        'zlib_decode' => array(
647
                                            '5.3' => false,
648
                                            '5.4' => true
649
                                        ),
650
                                        'zlib_encode' => array(
651
                                            '5.3' => false,
652
                                            '5.4' => true
653
                                        ),
654
655
                                        'array_column' => array(
656
                                            '5.4' => false,
657
                                            '5.5' => true
658
                                        ),
659
                                        'boolval' => array(
660
                                            '5.4' => false,
661
                                            '5.5' => true
662
                                        ),
663
                                        'json_last_error_msg' => array(
664
                                            '5.4' => false,
665
                                            '5.5' => true
666
                                        ),
667
                                        'password_get_info' => array(
668
                                            '5.4' => false,
669
                                            '5.5' => true
670
                                        ),
671
                                        'password_hash' => array(
672
                                            '5.4' => false,
673
                                            '5.5' => true
674
                                        ),
675
                                        'password_needs_rehash' => array(
676
                                            '5.4' => false,
677
                                            '5.5' => true
678
                                        ),
679
                                        'password_verify' => array(
680
                                            '5.4' => false,
681
                                            '5.5' => true
682
                                        ),
683
                                        'hash_pbkdf2' => array(
684
                                            '5.4' => false,
685
                                            '5.5' => true
686
                                        ),
687
                                        'openssl_pbkdf2' => array(
688
                                            '5.4' => false,
689
                                            '5.5' => true
690
                                        ),
691
                                        'curl_escape' => array(
692
                                            '5.4' => false,
693
                                            '5.5' => true
694
                                        ),
695
                                        'curl_file_create' => array(
696
                                            '5.4' => false,
697
                                            '5.5' => true
698
                                        ),
699
                                        'curl_multi_setopt' => array(
700
                                            '5.4' => false,
701
                                            '5.5' => true
702
                                        ),
703
                                        'curl_multi_strerror' => array(
704
                                            '5.4' => false,
705
                                            '5.5' => true
706
                                        ),
707
                                        'curl_pause' => array(
708
                                            '5.4' => false,
709
                                            '5.5' => true
710
                                        ),
711
                                        'curl_reset' => array(
712
                                            '5.4' => false,
713
                                            '5.5' => true
714
                                        ),
715
                                        'curl_share_close' => array(
716
                                            '5.4' => false,
717
                                            '5.5' => true
718
                                        ),
719
                                        'curl_share_init' => array(
720
                                            '5.4' => false,
721
                                            '5.5' => true
722
                                        ),
723
                                        'curl_share_setopt' => array(
724
                                            '5.4' => false,
725
                                            '5.5' => true
726
                                        ),
727
                                        'curl_strerror' => array(
728
                                            '5.4' => false,
729
                                            '5.5' => true
730
                                        ),
731
                                        'curl_unescape' => array(
732
                                            '5.4' => false,
733
                                            '5.5' => true
734
                                        ),
735
                                        'imageaffinematrixconcat' => array(
736
                                            '5.4' => false,
737
                                            '5.5' => true
738
                                        ),
739
                                        'imageaffinematrixget' => array(
740
                                            '5.4' => false,
741
                                            '5.5' => true
742
                                        ),
743
                                        'imagecrop' => array(
744
                                            '5.4' => false,
745
                                            '5.5' => true
746
                                        ),
747
                                        'imagecropauto' => array(
748
                                            '5.4' => false,
749
                                            '5.5' => true
750
                                        ),
751
                                        'imageflip' => array(
752
                                            '5.4' => false,
753
                                            '5.5' => true
754
                                        ),
755
                                        'imagepalettetotruecolor' => array(
756
                                            '5.4' => false,
757
                                            '5.5' => true
758
                                        ),
759
                                        'imagescale' => array(
760
                                            '5.4' => false,
761
                                            '5.5' => true
762
                                        ),
763
                                        'mysqli_begin_transaction' => array(
764
                                            '5.4' => false,
765
                                            '5.5' => true
766
                                        ),
767
                                        'mysqli_release_savepoint' => array(
768
                                            '5.4' => false,
769
                                            '5.5' => true
770
                                        ),
771
                                        'mysqli_savepoint' => array(
772
                                            '5.4' => false,
773
                                            '5.5' => true
774
                                        ),
775
                                        'pg_escape_literal' => array(
776
                                            '5.4' => false,
777
                                            '5.5' => true
778
                                        ),
779
                                        'pg_escape_identifier' => array(
780
                                            '5.4' => false,
781
                                            '5.5' => true
782
                                        ),
783
                                        'socket_sendmsg' => array(
784
                                            '5.4' => false,
785
                                            '5.5' => true
786
                                        ),
787
                                        'socket_recvmsg' => array(
788
                                            '5.4' => false,
789
                                            '5.5' => true
790
                                        ),
791
                                        'socket_cmsg_space' => array(
792
                                            '5.4' => false,
793
                                            '5.5' => true
794
                                        ),
795
                                        'cli_get_process_title' => array(
796
                                            '5.4' => false,
797
                                            '5.5' => true
798
                                        ),
799
                                        'cli_set_process_title' => array(
800
                                            '5.4' => false,
801
                                            '5.5' => true
802
                                        ),
803
                                        'datefmt_format_object' => array(
804
                                            '5.4' => false,
805
                                            '5.5' => true
806
                                        ),
807
                                        'datefmt_get_calendar_object' => array(
808
                                            '5.4' => false,
809
                                            '5.5' => true
810
                                        ),
811
                                        'datefmt_get_timezone' => array(
812
                                            '5.4' => false,
813
                                            '5.5' => true
814
                                        ),
815
                                        'datefmt_set_timezone' => array(
816
                                            '5.4' => false,
817
                                            '5.5' => true
818
                                        ),
819
                                        'datefmt_get_calendar_object' => array(
820
                                            '5.4' => false,
821
                                            '5.5' => true
822
                                        ),
823
                                        'intlcal_create_instance' => array(
824
                                            '5.4' => false,
825
                                            '5.5' => true
826
                                        ),
827
                                        'intlcal_get_keyword_values_for_locale' => array(
828
                                            '5.4' => false,
829
                                            '5.5' => true
830
                                        ),
831
                                        'intlcal_get_now' => array(
832
                                            '5.4' => false,
833
                                            '5.5' => true
834
                                        ),
835
                                        'intlcal_get_available_locales' => array(
836
                                            '5.4' => false,
837
                                            '5.5' => true
838
                                        ),
839
                                        'intlcal_get' => array(
840
                                            '5.4' => false,
841
                                            '5.5' => true
842
                                        ),
843
                                        'intlcal_get_time' => array(
844
                                            '5.4' => false,
845
                                            '5.5' => true
846
                                        ),
847
                                        'intlcal_set_time' => array(
848
                                            '5.4' => false,
849
                                            '5.5' => true
850
                                        ),
851
                                        'intlcal_add' => array(
852
                                            '5.4' => false,
853
                                            '5.5' => true
854
                                        ),
855
                                        'intlcal_set_time_zone' => array(
856
                                            '5.4' => false,
857
                                            '5.5' => true
858
                                        ),
859
                                        'intlcal_after' => array(
860
                                            '5.4' => false,
861
                                            '5.5' => true
862
                                        ),
863
                                        'intlcal_before' => array(
864
                                            '5.4' => false,
865
                                            '5.5' => true
866
                                        ),
867
                                        'intlcal_set' => array(
868
                                            '5.4' => false,
869
                                            '5.5' => true
870
                                        ),
871
                                        'intlcal_roll' => array(
872
                                            '5.4' => false,
873
                                            '5.5' => true
874
                                        ),
875
                                        'intlcal_clear' => array(
876
                                            '5.4' => false,
877
                                            '5.5' => true
878
                                        ),
879
                                        'intlcal_field_difference' => array(
880
                                            '5.4' => false,
881
                                            '5.5' => true
882
                                        ),
883
                                        'intlcal_get_actual_maximum' => array(
884
                                            '5.4' => false,
885
                                            '5.5' => true
886
                                        ),
887
                                        'intlcal_get_actual_minumum' => array(
888
                                            '5.4' => false,
889
                                            '5.5' => true
890
                                        ),
891
                                        'intlcal_get_day_of_week_type' => array(
892
                                            '5.4' => false,
893
                                            '5.5' => true
894
                                        ),
895
                                        'intlcal_get_first_day_of_week' => array(
896
                                            '5.4' => false,
897
                                            '5.5' => true
898
                                        ),
899
                                        'intlcal_get_greatest_minimum' => array(
900
                                            '5.4' => false,
901
                                            '5.5' => true
902
                                        ),
903
                                        'intlcal_get_least_maximum' => array(
904
                                            '5.4' => false,
905
                                            '5.5' => true
906
                                        ),
907
                                        'intlcal_get_locale' => array(
908
                                            '5.4' => false,
909
                                            '5.5' => true
910
                                        ),
911
                                        'intlcal_get_maximum' => array(
912
                                            '5.4' => false,
913
                                            '5.5' => true
914
                                        ),
915
                                        'intlcal_get_minimal_days_in_first_week' => array(
916
                                            '5.4' => false,
917
                                            '5.5' => true
918
                                        ),
919
                                        'intlcal_get_minimum' => array(
920
                                            '5.4' => false,
921
                                            '5.5' => true
922
                                        ),
923
                                        'intlcal_get_time_zone' => array(
924
                                            '5.4' => false,
925
                                            '5.5' => true
926
                                        ),
927
                                        'intlcal_get_type' => array(
928
                                            '5.4' => false,
929
                                            '5.5' => true
930
                                        ),
931
                                        'intlcal_get_weekend_transition' => array(
932
                                            '5.4' => false,
933
                                            '5.5' => true
934
                                        ),
935
                                        'intlcal_in_daylight_time' => array(
936
                                            '5.4' => false,
937
                                            '5.5' => true
938
                                        ),
939
                                        'intlcal_is_equivalent_to' => array(
940
                                            '5.4' => false,
941
                                            '5.5' => true
942
                                        ),
943
                                        'intlcal_is_lenient' => array(
944
                                            '5.4' => false,
945
                                            '5.5' => true
946
                                        ),
947
                                        'intlcal_equals' => array(
948
                                            '5.4' => false,
949
                                            '5.5' => true
950
                                        ),
951
                                        'intlcal_get_repeated_wall_time_option' => array(
952
                                            '5.4' => false,
953
                                            '5.5' => true
954
                                        ),
955
                                        'intlcal_get_skipped_wall_time_option' => array(
956
                                            '5.4' => false,
957
                                            '5.5' => true
958
                                        ),
959
                                        'intlcal_set_repeated_wall_time_option' => array(
960
                                            '5.4' => false,
961
                                            '5.5' => true
962
                                        ),
963
                                        'intlcal_set_skipped_wall_time_option' => array(
964
                                            '5.4' => false,
965
                                            '5.5' => true
966
                                        ),
967
                                        'intlcal_from_date_time' => array(
968
                                            '5.4' => false,
969
                                            '5.5' => true
970
                                        ),
971
                                        'intlcal_to_date_time' => array(
972
                                            '5.4' => false,
973
                                            '5.5' => true
974
                                        ),
975
                                        'intlcal_get_error_code' => array(
976
                                            '5.4' => false,
977
                                            '5.5' => true
978
                                        ),
979
                                        'intlcal_get_error_message' => array(
980
                                            '5.4' => false,
981
                                            '5.5' => true
982
                                        ),
983
                                        'intlgregcal_create_instance' => array(
984
                                            '5.4' => false,
985
                                            '5.5' => true
986
                                        ),
987
                                        'intlgregcal_set_gregorian_change' => array(
988
                                            '5.4' => false,
989
                                            '5.5' => true
990
                                        ),
991
                                        'intlgregcal_get_gregorian_change' => array(
992
                                            '5.4' => false,
993
                                            '5.5' => true
994
                                        ),
995
                                        'intlgregcal_is_leap_year' => array(
996
                                            '5.4' => false,
997
                                            '5.5' => true
998
                                        ),
999
                                        'intlz_create_time_zone' => array(
1000
                                            '5.4' => false,
1001
                                            '5.5' => true
1002
                                        ),
1003
                                        'intlz_create_default' => array(
1004
                                            '5.4' => false,
1005
                                            '5.5' => true
1006
                                        ),
1007
                                        'intlz_get_id' => array(
1008
                                            '5.4' => false,
1009
                                            '5.5' => true
1010
                                        ),
1011
                                        'intlz_get_gmt' => array(
1012
                                            '5.4' => false,
1013
                                            '5.5' => true
1014
                                        ),
1015
                                        'intlz_get_unknown' => array(
1016
                                            '5.4' => false,
1017
                                            '5.5' => true
1018
                                        ),
1019
                                        'intlz_create_enumeration' => array(
1020
                                            '5.4' => false,
1021
                                            '5.5' => true
1022
                                        ),
1023
                                        'intlz_count_equivalent_ids' => array(
1024
                                            '5.4' => false,
1025
                                            '5.5' => true
1026
                                        ),
1027
                                        'intlz_create_time_zone_id_enumeration' => array(
1028
                                            '5.4' => false,
1029
                                            '5.5' => true
1030
                                        ),
1031
                                        'intlz_get_canonical_id' => array(
1032
                                            '5.4' => false,
1033
                                            '5.5' => true
1034
                                        ),
1035
                                        'intlz_get_region' => array(
1036
                                            '5.4' => false,
1037
                                            '5.5' => true
1038
                                        ),
1039
                                        'intlz_get_tz_data_version' => array(
1040
                                            '5.4' => false,
1041
                                            '5.5' => true
1042
                                        ),
1043
                                        'intlz_get_equivalent_id' => array(
1044
                                            '5.4' => false,
1045
                                            '5.5' => true
1046
                                        ),
1047
                                        'intlz_use_daylight_time' => array(
1048
                                            '5.4' => false,
1049
                                            '5.5' => true
1050
                                        ),
1051
                                        'intlz_get_offset' => array(
1052
                                            '5.4' => false,
1053
                                            '5.5' => true
1054
                                        ),
1055
                                        'intlz_get_raw_offset' => array(
1056
                                            '5.4' => false,
1057
                                            '5.5' => true
1058
                                        ),
1059
                                        'intlz_has_same_rules' => array(
1060
                                            '5.4' => false,
1061
                                            '5.5' => true
1062
                                        ),
1063
                                        'intlz_get_display_name' => array(
1064
                                            '5.4' => false,
1065
                                            '5.5' => true
1066
                                        ),
1067
                                        'intlz_get_dst_savings' => array(
1068
                                            '5.4' => false,
1069
                                            '5.5' => true
1070
                                        ),
1071
                                        'intlz_from_date_time_zone' => array(
1072
                                            '5.4' => false,
1073
                                            '5.5' => true
1074
                                        ),
1075
                                        'intlz_to_date_time_zone' => array(
1076
                                            '5.4' => false,
1077
                                            '5.5' => true
1078
                                        ),
1079
                                        'intlz_get_error_code' => array(
1080
                                            '5.4' => false,
1081
                                            '5.5' => true
1082
                                        ),
1083
                                        'intlz_get_error_message' => array(
1084
                                            '5.4' => false,
1085
                                            '5.5' => true
1086
                                        ),
1087
1088
                                        'gmp_root' => array(
1089
                                            '5.5' => false,
1090
                                            '5.6' => true
1091
                                        ),
1092
                                        'gmp_rootrem' => array(
1093
                                            '5.5' => false,
1094
                                            '5.6' => true
1095
                                        ),
1096
                                        'hash_equals' => array(
1097
                                            '5.5' => false,
1098
                                            '5.6' => true
1099
                                        ),
1100
                                        'ldap_escape' => array(
1101
                                            '5.5' => false,
1102
                                            '5.6' => true
1103
                                        ),
1104
                                        'ldap_modify_batch' => array(
1105
                                            '5.4.25' => false,
1106
                                            '5.5.9' => false,
1107
                                            '5.4.26' => true,
1108
                                            '5.5.10' => true,
1109
                                            '5.6.0' => true,
1110
                                        ),
1111
                                        'mysqli_get_links_stats' => array(
1112
                                            '5.5' => false,
1113
                                            '5.6' => true
1114
                                        ),
1115
                                        'openssl_get_cert_locations' => array(
1116
                                            '5.5' => false,
1117
                                            '5.6' => true
1118
                                        ),
1119
                                        'openssl_x509_fingerprint' => array(
1120
                                            '5.5' => false,
1121
                                            '5.6' => true
1122
                                        ),
1123
                                        'openssl_spki_new' => array(
1124
                                            '5.5' => false,
1125
                                            '5.6' => true
1126
                                        ),
1127
                                        'openssl_spki_verify' => array(
1128
                                            '5.5' => false,
1129
                                            '5.6' => true
1130
                                        ),
1131
                                        'openssl_spki_export_challenge' => array(
1132
                                            '5.5' => false,
1133
                                            '5.6' => true
1134
                                        ),
1135
                                        'openssl_spki_export' => array(
1136
                                            '5.5' => false,
1137
                                            '5.6' => true
1138
                                        ),
1139
                                        'pg_connect_poll' => array(
1140
                                            '5.5' => false,
1141
                                            '5.6' => true
1142
                                        ),
1143
                                        'pg_consume_input' => array(
1144
                                            '5.5' => false,
1145
                                            '5.6' => true
1146
                                        ),
1147
                                        'pg_flush' => array(
1148
                                            '5.5' => false,
1149
                                            '5.6' => true
1150
                                        ),
1151
                                        'pg_socket' => array(
1152
                                            '5.5' => false,
1153
                                            '5.6' => true
1154
                                        ),
1155
                                        'session_abort' => array(
1156
                                            '5.5' => false,
1157
                                            '5.6' => true
1158
                                        ),
1159
                                        'session_reset' => array(
1160
                                            '5.5' => false,
1161
                                            '5.6' => true
1162
                                        ),
1163
1164
                                        'random_bytes' => array(
1165
                                            '5.6' => false,
1166
                                            '7.0' => true
1167
                                        ),
1168
                                        'random_int' => array(
1169
                                            '5.6' => false,
1170
                                            '7.0' => true
1171
                                        ),
1172
                                        'error_clear_last' => array(
1173
                                            '5.6' => false,
1174
                                            '7.0' => true
1175
                                        ),
1176
                                        'gmp_random_seed' => array(
1177
                                            '5.6' => false,
1178
                                            '7.0' => true
1179
                                        ),
1180
                                        'intdiv' => array(
1181
                                            '5.6' => false,
1182
                                            '7.0' => true
1183
                                        ),
1184
                                        'preg_replace_callback_array' => array(
1185
                                            '5.6' => false,
1186
                                            '7.0' => true
1187
                                        ),
1188
                                        'gc_mem_caches' => array(
1189
                                            '5.6' => false,
1190
                                            '7.0' => true
1191
                                        ),
1192
                                        'get_resources' => array(
1193
                                            '5.6' => false,
1194
                                            '7.0' => true
1195
                                        ),
1196
                                        'posix_setrlimit' => array(
1197
                                            '5.6' => false,
1198
                                            '7.0' => true
1199
                                        ),
1200
                                        'inflate_add' => array(
1201
                                            '5.6' => false,
1202
                                            '7.0' => true
1203
                                        ),
1204
                                        'deflate_add' => array(
1205
                                            '5.6' => false,
1206
                                            '7.0' => true
1207
                                        ),
1208
                                        'inflate_init' => array(
1209
                                            '5.6' => false,
1210
                                            '7.0' => true
1211
                                        ),
1212
                                        'deflate_init' => array(
1213
                                            '5.6' => false,
1214
                                            '7.0' => true
1215
                                        ),
1216
                                    );
1217
1218
1219
    /**
1220
     *
1221
     * @var array
1222
     */
1223
    private $forbiddenFunctionNames;
1224
1225
1226
    /**
1227
     * Returns an array of tokens this test wants to listen for.
1228
     *
1229
     * @return array
1230
     */
1231
    public function register()
1232
    {
1233
        // Everyone has had a chance to figure out what forbidden functions
1234
        // they want to check for, so now we can cache out the list.
1235
        $this->forbiddenFunctionNames = array_keys($this->forbiddenFunctions);
1236
        $this->forbiddenFunctionNames = array_map('strtolower', $this->forbiddenFunctionNames);
1237
        $this->forbiddenFunctions     = array_combine($this->forbiddenFunctionNames, $this->forbiddenFunctions);
1238
1239
        if ($this->patternMatch === true) {
1240
            foreach ($this->forbiddenFunctionNames as $i => $name) {
1241
                $this->forbiddenFunctionNames[$i] = '/'.$name.'/i';
1242
            }
1243
        }
1244
1245
        return array(T_STRING);
1246
1247
    }//end register()
1248
1249
    /**
1250
     * Processes this test, when one of its tokens is encountered.
1251
     *
1252
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
1253
     * @param int                  $stackPtr  The position of the current token in
1254
     *                                        the stack passed in $tokens.
1255
     *
1256
     * @return void
1257
     */
1258
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
1259
    {
1260
        $tokens = $phpcsFile->getTokens();
1261
1262
        $ignore = array(
1263
                T_DOUBLE_COLON,
1264
                T_OBJECT_OPERATOR,
1265
                T_FUNCTION,
1266
                T_CONST,
1267
        );
1268
1269
        $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
1270
        if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
1271
            // Not a call to a PHP function.
1272
            return;
1273
        }
1274
        else if($tokens[$prevToken]['code'] === T_NS_SEPARATOR && $tokens[$prevToken - 1]['code'] === T_STRING) {
1275
            // Namespaced function.
1276
            return;
1277
        }
1278
1279
        $function = strtolower($tokens[$stackPtr]['content']);
1280
        $pattern  = null;
1281
1282
        if ($this->patternMatch === true) {
1283
            $count   = 0;
1284
            $pattern = preg_replace(
1285
                    $this->forbiddenFunctionNames,
1286
                    $this->forbiddenFunctionNames,
1287
                    $function,
1288
                    1,
1289
                    $count
1290
            );
1291
1292
            if ($count === 0) {
1293
                return;
1294
            }
1295
1296
            // Remove the pattern delimiters and modifier.
1297
            $pattern = substr($pattern, 1, -2);
1298
        } else {
1299
            if (in_array($function, $this->forbiddenFunctionNames) === false) {
1300
                return;
1301
            }
1302
        }
1303
1304
        $this->addError($phpcsFile, $stackPtr, $tokens[$stackPtr]['content'], $pattern);
1305
1306
    }//end process()
1307
1308
1309
    /**
1310
     * Generates the error or warning for this sniff.
1311
     *
1312
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
1313
     * @param int                  $stackPtr  The position of the function
1314
     *                                        in the token array.
1315
     * @param string               $function  The name of the function.
1316
     * @param string               $pattern   The pattern used for the match.
1317
     *
1318
     * @return void
1319
     */
1320
    protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
1321
    {
1322
        if ($pattern === null) {
1323
            $pattern = strtolower($function);
1324
        }
1325
1326
        $error = '';
1327
1328
        $isError = false;
1329
        foreach ($this->forbiddenFunctions[$pattern] as $version => $present) {
1330
            if ($this->supportsBelow($version)) {
1331
                if ($present === false) {
1332
                    $isError = true;
1333
                    $error .= 'not present in PHP version ' . $version . ' or earlier';
1334
                }
1335
            }
1336
        }
1337
        if (strlen($error) > 0) {
1338
            $error = 'The function ' . $function . ' is ' . $error;
1339
1340
            if ($isError === true) {
1341
                $phpcsFile->addError($error, $stackPtr);
1342
            } else {
1343
                $phpcsFile->addWarning($error, $stackPtr);
1344
            }
1345
        }
1346
1347
    }//end addError()
1348
1349
}//end class
1350