Completed
Pull Request — master (#170)
by Juliette
32:45 queued 29:29
created

DeprecatedFunctionsSniff   B

Complexity

Total Complexity 18

Size/Duplication

Total Lines 754
Duplicated Lines 6.9 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 7
Bugs 1 Features 2
Metric Value
wmc 18
c 7
b 1
f 2
lcom 1
cbo 2
dl 52
loc 754
rs 7.2258

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 15 15 3
B process() 21 47 5
D addError() 16 42 10

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_DeprecatedFunctionsSniff.
4
 *
5
 * PHP version 7.0
6
 *
7
 * @category  PHP
8
 * @package   PHPCompatibility
9
 * @author    Wim Godden <[email protected]>
10
 */
11
12
/**
13
 * PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff.
14
 *
15
 * @category  PHP
16
 * @package   PHPCompatibility
17
 * @author    Wim Godden <[email protected]>
18
 */
19
class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff 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...
20
{
21
22
    /**
23
     * If true, forbidden functions will be considered regular expressions.
24
     *
25
     * @var bool
26
     */
27
    protected $patternMatch = false;
28
29
    /**
30
     * A list of forbidden functions with their alternatives.
31
     *
32
     * The array lists : version number with false (deprecated) or true (forbidden) and an alternative function.
33
     * If no alternative exists, it is NULL, i.e, the function should just not be used.
34
     *
35
     * @var array(string => array(string => bool|string|null))
36
     */
37
    protected $forbiddenFunctions = array(
38
                                        'php_check_syntax' => array(
39
                                            '5.0.5' => true,
40
                                            'alternative' => null
41
                                        ),
42
                                        'call_user_method' => array(
43
                                            '5.3' => false,
44
                                            '5.4' => false,
45
                                            '5.5' => false,
46
                                            '5.6' => false,
47
                                            '7.0' => true,
48
                                            'alternative' => 'call_user_func'
49
                                        ),
50
                                        'call_user_method_array' => array(
51
                                            '5.3' => false,
52
                                            '5.4' => false,
53
                                            '5.5' => false,
54
                                            '5.6' => false,
55
                                            '7.0' => true,
56
                                            'alternative' => 'call_user_func_array'
57
                                        ),
58
                                        'define_syslog_variables' => array(
59
                                            '5.3' => false,
60
                                            '5.4' => true,
61
                                            '5.5' => true,
62
                                            '5.6' => true,
63
                                            'alternative' => null
64
                                        ),
65
                                        'dl' => array(
66
                                            '5.3' => false,
67
                                            '5.4' => false,
68
                                            '5.5' => false,
69
                                            '5.6' => false,
70
                                            'alternative' => null
71
                                        ),
72
                                        'ereg' => array(
73
                                            '5.3' => false,
74
                                            '5.4' => false,
75
                                            '5.5' => false,
76
                                            '5.6' => false,
77
                                            '7.0' => true,
78
                                            'alternative' => 'preg_match'
79
                                        ),
80
                                        'ereg_replace' => array(
81
                                            '5.3' => false,
82
                                            '5.4' => false,
83
                                            '5.5' => false,
84
                                            '5.6' => false,
85
                                            '7.0' => true,
86
                                            'alternative' => 'preg_replace'
87
                                        ),
88
                                        'eregi' => array(
89
                                            '5.3' => false,
90
                                            '5.4' => false,
91
                                            '5.5' => false,
92
                                            '5.6' => false,
93
                                            '7.0' => true,
94
                                            'alternative' => 'preg_match'
95
                                        ),
96
                                        'eregi_replace' => array(
97
                                            '5.3' => false,
98
                                            '5.4' => false,
99
                                            '5.5' => false,
100
                                            '5.6' => false,
101
                                            '7.0' => true,
102
                                            'alternative' => 'preg_replace'
103
                                        ),
104
                                        'imagepsbbox' => array(
105
                                            '7.0' => true,
106
                                            'alternative' => null
107
                                        ),
108
                                        'imagepsencodefont' => array(
109
                                            '7.0' => true,
110
                                            'alternative' => null
111
                                        ),
112
                                        'imagepsextendfont' => array(
113
                                            '7.0' => true,
114
                                            'alternative' => null
115
                                        ),
116
                                        'imagepsfreefont' => array(
117
                                            '7.0' => true,
118
                                            'alternative' => null
119
                                        ),
120
                                        'imagepsloadfont' => array(
121
                                            '7.0' => true,
122
                                            'alternative' => null
123
                                        ),
124
                                        'imagepsslantfont' => array(
125
                                            '7.0' => true,
126
                                            'alternative' => null
127
                                        ),
128
                                        'imagepstext' => array(
129
                                            '7.0' => true,
130
                                            'alternative' => null
131
                                        ),
132
                                        'import_request_variables' => array(
133
                                            '5.3' => false,
134
                                            '5.4' => true,
135
                                            'alternative' => null
136
                                        ),
137
                                        'ldap_sort' => array(
138
                                            '7.0' => false,
139
                                            'alternative' => null
140
                                        ),
141
                                        'mcrypt_generic_end' => array(
142
                                            '5.4' => false,
143
                                            '5.5' => false,
144
                                            '5.6' => false,
145
                                            '7.0' => true,
146
                                            'alternative' => 'mcrypt_generic_deinit'
147
                                        ),
148
                                        'mysql_db_query' => array(
149
                                            '5.3' => false,
150
                                            '5.4' => false,
151
                                            '5.5' => false,
152
                                            '5.6' => false,
153
                                            '7.0' => true,
154
                                            'alternative' => 'mysqli_select_db and mysqli_query'
155
                                        ),
156
                                        'mysql_escape_string' => array(
157
                                            '5.3' => false,
158
                                            '5.4' => false,
159
                                            '5.5' => false,
160
                                            '5.6' => false,
161
                                            '7.0' => true,
162
                                            'alternative' => 'mysqli_real_escape_string'
163
                                        ),
164
                                        'mysql_list_dbs' => array(
165
                                            '5.4' => false,
166
                                            '5.5' => false,
167
                                            '5.6' => false,
168
                                            '7.0' => true,
169
                                            'alternative' => null
170
                                        ),
171
                                        'mysqli_bind_param' => array(
172
                                            '5.3' => false,
173
                                            '5.4' => true,
174
                                            '5.5' => true,
175
                                            '5.6' => true,
176
                                            'alternative' => 'mysqli_stmt_bind_param'
177
                                        ),
178
                                        'mysqli_bind_result' => array(
179
                                            '5.3' => false,
180
                                            '5.4' => true,
181
                                            '5.5' => true,
182
                                            '5.6' => true,
183
                                            'alternative' => 'mysqli_stmt_bind_result'
184
                                        ),
185
                                        'mysqli_client_encoding' => array(
186
                                            '5.3' => false,
187
                                            '5.4' => true,
188
                                            '5.5' => true,
189
                                            '5.6' => true,
190
                                            'alternative' => 'mysqli_character_set_name'
191
                                        ),
192
                                        'mysqli_fetch' => array(
193
                                            '5.3' => false,
194
                                            '5.4' => true,
195
                                            '5.5' => true,
196
                                            '5.6' => true,
197
                                            'alternative' => 'mysqli_stmt_fetch'
198
                                        ),
199
                                        'mysqli_param_count' => array(
200
                                            '5.3' => false,
201
                                            '5.4' => true,
202
                                            '5.5' => true,
203
                                            '5.6' => true,
204
                                            'alternative' => 'mysqli_stmt_param_count'
205
                                        ),
206
                                        'mysqli_get_metadata' => array(
207
                                            '5.3' => false,
208
                                            '5.4' => true,
209
                                            '5.5' => true,
210
                                            '5.6' => true,
211
                                            'alternative' => 'mysqli_stmt_result_metadata'
212
                                        ),
213
                                        'mysqli_send_long_data' => array(
214
                                            '5.3' => false,
215
                                            '5.4' => true,
216
                                            '5.5' => true,
217
                                            '5.6' => true,
218
                                            'alternative' => 'mysqli_stmt_send_long_data'
219
                                        ),
220
                                        'magic_quotes_runtime' => array(
221
                                            '5.3' => false,
222
                                            '5.4' => false,
223
                                            '5.5' => false,
224
                                            '5.6' => false,
225
                                            '7.0' => true,
226
                                            'alternative' => null
227
                                        ),
228
                                        'session_register' => array(
229
                                            '5.3' => false,
230
                                            '5.4' => true,
231
                                            '5.5' => true,
232
                                            '5.6' => true,
233
                                            'alternative' => '$_SESSION'
234
                                        ),
235
                                        'session_unregister' => array(
236
                                            '5.3' => false,
237
                                            '5.4' => true,
238
                                            '5.5' => true,
239
                                            '5.6' => true,
240
                                            'alternative' => '$_SESSION'
241
                                        ),
242
                                        'session_is_registered' => array(
243
                                            '5.3' => false,
244
                                            '5.4' => true,
245
                                            '5.5' => true,
246
                                            '5.6' => true,
247
                                            'alternative' => '$_SESSION'
248
                                        ),
249
                                        'set_magic_quotes_runtime' => array(
250
                                            '5.3' => false,
251
                                            '5.4' => false,
252
                                            '5.5' => false,
253
                                            '5.6' => false,
254
                                            '7.0' => true,
255
                                            'alternative' => null
256
                                        ),
257
                                        'set_socket_blocking' => array(
258
                                            '5.3' => false,
259
                                            '5.4' => false,
260
                                            '5.5' => false,
261
                                            '5.6' => false,
262
                                            '7.0' => true,
263
                                            'alternative' => 'stream_set_blocking'
264
                                        ),
265
                                        'split' => array(
266
                                            '5.3' => false,
267
                                            '5.4' => false,
268
                                            '5.5' => false,
269
                                            '5.6' => false,
270
                                            '7.0' => true,
271
                                            'alternative' => 'preg_split'
272
                                        ),
273
                                        'spliti' => array(
274
                                            '5.3' => false,
275
                                            '5.4' => false,
276
                                            '5.5' => false,
277
                                            '5.6' => false,
278
                                            '7.0' => true,
279
                                            'alternative' => 'preg_split'
280
                                        ),
281
                                        'sql_regcase' => array(
282
                                            '5.3' => false,
283
                                            '5.4' => false,
284
                                            '5.5' => false,
285
                                            '5.6' => false,
286
                                            '7.0' => true,
287
                                            'alternative' => null
288
                                        ),
289
                                        'php_logo_guid' => array(
290
                                            '5.5' => true,
291
                                            '5.6' => true,
292
                                            'alternative' => null
293
                                        ),
294
                                        'php_egg_logo_guid' => array(
295
                                            '5.5' => true,
296
                                            '5.6' => true,
297
                                            'alternative' => null
298
                                        ),
299
                                        'php_real_logo_guid' => array(
300
                                            '5.5' => true,
301
                                            '5.6' => true,
302
                                            'alternative' => null
303
                                        ),
304
                                        'zend_logo_guid' => array(
305
                                            '5.5' => true,
306
                                            '5.6' => true,
307
                                            'alternative' => null
308
                                        ),
309
                                        'datefmt_set_timezone_id' => array(
310
                                            '5.5' => false,
311
                                            '5.6' => false,
312
                                            '7.0' => true,
313
                                            'alternative' => 'datefmt_set_timezone'
314
                                        ),
315
                                        'mcrypt_ecb' => array(
316
                                            '5.5' => false,
317
                                            '5.6' => false,
318
                                            '7.0' => true,
319
                                            'alternative' => null
320
                                        ),
321
                                        'mcrypt_cbc' => array(
322
                                            '5.5' => false,
323
                                            '5.6' => false,
324
                                            '7.0' => true,
325
                                            'alternative' => null
326
                                        ),
327
                                        'mcrypt_cfb' => array(
328
                                            '5.5' => false,
329
                                            '5.6' => false,
330
                                            '7.0' => true,
331
                                            'alternative' => null
332
                                        ),
333
                                        'mcrypt_ofb' => array(
334
                                            '5.5' => false,
335
                                            '5.6' => false,
336
                                            '7.0' => true,
337
                                            'alternative' => null
338
                                        ),
339
                                        'ocibindbyname' => array(
340
                                            '5.4' => false,
341
                                            '5.5' => false,
342
                                            '5.6' => false,
343
                                            'alternative' => 'oci_bind_by_name'
344
                                        ),
345
                                        'ocicancel' => array(
346
                                            '5.4' => false,
347
                                            '5.5' => false,
348
                                            '5.6' => false,
349
                                            'alternative' => 'oci_cancel'
350
                                        ),
351
                                        'ocicloselob' => array(
352
                                            '5.4' => false,
353
                                            '5.5' => false,
354
                                            '5.6' => false,
355
                                            'alternative' => 'OCI-Lob::close'
356
                                        ),
357
                                        'ocicollappend' => array(
358
                                            '5.4' => false,
359
                                            '5.5' => false,
360
                                            '5.6' => false,
361
                                            'alternative' => 'OCI-Collection::append'
362
                                        ),
363
                                        'ocicollassign' => array(
364
                                            '5.4' => false,
365
                                            '5.5' => false,
366
                                            '5.6' => false,
367
                                            'alternative' => 'OCI-Collection::assign'
368
                                        ),
369
                                        'ocicollassignelem' => array(
370
                                            '5.4' => false,
371
                                            '5.5' => false,
372
                                            '5.6' => false,
373
                                            'alternative' => 'OCI-Collection::assignElem'
374
                                        ),
375
                                        'ocicollgetelem' => array(
376
                                            '5.4' => false,
377
                                            '5.5' => false,
378
                                            '5.6' => false,
379
                                            'alternative' => 'OCI-Collection::getElem'
380
                                        ),
381
                                        'ocicollmax' => array(
382
                                            '5.4' => false,
383
                                            '5.5' => false,
384
                                            '5.6' => false,
385
                                            'alternative' => 'OCI-Collection::max'
386
                                        ),
387
                                        'ocicollsize' => array(
388
                                            '5.4' => false,
389
                                            '5.5' => false,
390
                                            '5.6' => false,
391
                                            'alternative' => 'OCI-Collection::size'
392
                                        ),
393
                                        'ocicolltrim' => array(
394
                                            '5.4' => false,
395
                                            '5.5' => false,
396
                                            '5.6' => false,
397
                                            'alternative' => 'OCI-Collection::trim'
398
                                        ),
399
                                        'ocicolumnisnull' => array(
400
                                            '5.4' => false,
401
                                            '5.5' => false,
402
                                            '5.6' => false,
403
                                            'alternative' => 'oci_field_is_null'
404
                                        ),
405
                                        'ocicolumnname' => array(
406
                                            '5.4' => false,
407
                                            '5.5' => false,
408
                                            '5.6' => false,
409
                                            'alternative' => 'oci_field_name'
410
                                        ),
411
                                        'ocicolumnprecision' => array(
412
                                            '5.4' => false,
413
                                            '5.5' => false,
414
                                            '5.6' => false,
415
                                            'alternative' => 'oci_field_precision'
416
                                        ),
417
                                        'ocicolumnscale' => array(
418
                                            '5.4' => false,
419
                                            '5.5' => false,
420
                                            '5.6' => false,
421
                                            'alternative' => 'oci_field_scale'
422
                                        ),
423
                                        'ocicolumnsize' => array(
424
                                            '5.4' => false,
425
                                            '5.5' => false,
426
                                            '5.6' => false,
427
                                            'alternative' => 'oci_field_size'
428
                                        ),
429
                                        'ocicolumntype' => array(
430
                                            '5.4' => false,
431
                                            '5.5' => false,
432
                                            '5.6' => false,
433
                                            'alternative' => 'oci_field_type'
434
                                        ),
435
                                        'ocicolumntyperaw' => array(
436
                                            '5.4' => false,
437
                                            '5.5' => false,
438
                                            '5.6' => false,
439
                                            'alternative' => 'oci_field_type_raw'
440
                                        ),
441
                                        'ocicommit' => array(
442
                                            '5.4' => false,
443
                                            '5.5' => false,
444
                                            '5.6' => false,
445
                                            'alternative' => 'oci_commit'
446
                                        ),
447
                                        'ocidefinebyname' => array(
448
                                            '5.4' => false,
449
                                            '5.5' => false,
450
                                            '5.6' => false,
451
                                            'alternative' => 'oci_define_by_name'
452
                                        ),
453
                                        'ocierror' => array(
454
                                            '5.4' => false,
455
                                            '5.5' => false,
456
                                            '5.6' => false,
457
                                            'alternative' => 'oci_error'
458
                                        ),
459
                                        'ociexecute' => array(
460
                                            '5.4' => false,
461
                                            '5.5' => false,
462
                                            '5.6' => false,
463
                                            'alternative' => 'oci_execute'
464
                                        ),
465
                                        'ocifetch' => array(
466
                                            '5.4' => false,
467
                                            '5.5' => false,
468
                                            '5.6' => false,
469
                                            'alternative' => 'oci_fetch'
470
                                        ),
471
                                        'ocifetchinto' => array(
472
                                            '5.4' => false,
473
                                            '5.5' => false,
474
                                            '5.6' => false,
475
                                            'alternative' => null
476
                                        ),
477
                                        'ocifetchstatement' => array(
478
                                            '5.4' => false,
479
                                            '5.5' => false,
480
                                            '5.6' => false,
481
                                            'alternative' => 'oci_fetch_all'
482
                                        ),
483
                                        'ocifreecollection' => array(
484
                                            '5.4' => false,
485
                                            '5.5' => false,
486
                                            '5.6' => false,
487
                                            'alternative' => 'OCI-Collection::free'
488
                                        ),
489
                                        'ocifreecursor' => array(
490
                                            '5.4' => false,
491
                                            '5.5' => false,
492
                                            '5.6' => false,
493
                                            'alternative' => 'oci_free_statement'
494
                                        ),
495
                                        'ocifreedesc' => array(
496
                                            '5.4' => false,
497
                                            '5.5' => false,
498
                                            '5.6' => false,
499
                                            'alternative' => 'OCI-Lob::free'
500
                                        ),
501
                                        'ocifreestatement' => array(
502
                                            '5.4' => false,
503
                                            '5.5' => false,
504
                                            '5.6' => false,
505
                                            'alternative' => 'oci_free_statement'
506
                                        ),
507
                                        'ociinternaldebug' => array(
508
                                            '5.4' => false,
509
                                            '5.5' => false,
510
                                            '5.6' => false,
511
                                            'alternative' => 'oci_internal_debug'
512
                                        ),
513
                                        'ociloadlob' => array(
514
                                            '5.4' => false,
515
                                            '5.5' => false,
516
                                            '5.6' => false,
517
                                            'alternative' => 'OCI-Lob::load'
518
                                        ),
519
                                        'ocilogoff' => array(
520
                                            '5.4' => false,
521
                                            '5.5' => false,
522
                                            '5.6' => false,
523
                                            'alternative' => 'oci_close'
524
                                        ),
525
                                        'ocilogon' => array(
526
                                            '5.4' => false,
527
                                            '5.5' => false,
528
                                            '5.6' => false,
529
                                            'alternative' => 'oci_connect'
530
                                        ),
531
                                        'ocinewcollection' => array(
532
                                            '5.4' => false,
533
                                            '5.5' => false,
534
                                            '5.6' => false,
535
                                            'alternative' => 'oci_new_collection'
536
                                        ),
537
                                        'ocinewcursor' => array(
538
                                            '5.4' => false,
539
                                            '5.5' => false,
540
                                            '5.6' => false,
541
                                            'alternative' => 'oci_new_cursor'
542
                                        ),
543
                                        'ocinewdescriptor' => array(
544
                                            '5.4' => false,
545
                                            '5.5' => false,
546
                                            '5.6' => false,
547
                                            'alternative' => 'oci_new_descriptor'
548
                                        ),
549
                                        'ocinlogon' => array(
550
                                            '5.4' => false,
551
                                            '5.5' => false,
552
                                            '5.6' => false,
553
                                            'alternative' => 'oci_new_connect'
554
                                        ),
555
                                        'ocinumcols' => array(
556
                                            '5.4' => false,
557
                                            '5.5' => false,
558
                                            '5.6' => false,
559
                                            'alternative' => 'oci_num_fields'
560
                                        ),
561
                                        'ociparse' => array(
562
                                            '5.4' => false,
563
                                            '5.5' => false,
564
                                            '5.6' => false,
565
                                            'alternative' => 'oci_parse'
566
                                        ),
567
                                        'ociplogon' => array(
568
                                            '5.4' => false,
569
                                            '5.5' => false,
570
                                            '5.6' => false,
571
                                            'alternative' => 'oci_pconnect'
572
                                        ),
573
                                        'ociresult' => array(
574
                                            '5.4' => false,
575
                                            '5.5' => false,
576
                                            '5.6' => false,
577
                                            'alternative' => 'oci_result'
578
                                        ),
579
                                        'ocirollback' => array(
580
                                            '5.4' => false,
581
                                            '5.5' => false,
582
                                            '5.6' => false,
583
                                            'alternative' => 'oci_rollback'
584
                                        ),
585
                                        'ocirowcount' => array(
586
                                            '5.4' => false,
587
                                            '5.5' => false,
588
                                            '5.6' => false,
589
                                            'alternative' => 'oci_num_rows'
590
                                        ),
591
                                        'ocisavelob' => array(
592
                                            '5.4' => false,
593
                                            '5.5' => false,
594
                                            '5.6' => false,
595
                                            'alternative' => 'OCI-Lob::save'
596
                                        ),
597
                                        'ocisavelobfile' => array(
598
                                            '5.4' => false,
599
                                            '5.5' => false,
600
                                            '5.6' => false,
601
                                            'alternative' => 'OCI-Lob::import'
602
                                        ),
603
                                        'ociserverversion' => array(
604
                                            '5.4' => false,
605
                                            '5.5' => false,
606
                                            '5.6' => false,
607
                                            'alternative' => 'oci_server_version'
608
                                        ),
609
                                        'ocisetprefetch' => array(
610
                                            '5.4' => false,
611
                                            '5.5' => false,
612
                                            '5.6' => false,
613
                                            'alternative' => 'oci_set_prefetch'
614
                                        ),
615
                                        'ocistatementtype' => array(
616
                                            '5.4' => false,
617
                                            '5.5' => false,
618
                                            '5.6' => false,
619
                                            'alternative' => 'oci_statement_type'
620
                                        ),
621
                                        'ociwritelobtofile' => array(
622
                                            '5.4' => false,
623
                                            '5.5' => false,
624
                                            '5.6' => false,
625
                                            'alternative' => 'OCI-Lob::export'
626
                                        ),
627
                                        'ociwritetemporarylob' => array(
628
                                            '5.4' => false,
629
                                            '5.5' => false,
630
                                            '5.6' => false,
631
                                            'alternative' => 'OCI-Lob::writeTemporary'
632
                                        ),
633
                                        'mysqli_get_cache_stats' => array(
634
                                            '5.4' => true,
635
                                            'alternative' => null
636
                                        ),
637
                                    );
638
639
    /**
640
     * Returns an array of tokens this test wants to listen for.
641
     *
642
     * @return array
643
     */
644 View Code Duplication
    public function register()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
645
    {
646
        // Everyone has had a chance to figure out what forbidden functions
647
        // they want to check for, so now we can cache out the list.
648
        $this->forbiddenFunctionNames = array_keys($this->forbiddenFunctions);
0 ignored issues
show
Bug introduced by
The property forbiddenFunctionNames does not seem to exist. Did you mean forbiddenFunctions?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
649
650
        if ($this->patternMatch === true) {
651
            foreach ($this->forbiddenFunctionNames as $i => $name) {
0 ignored issues
show
Bug introduced by
The property forbiddenFunctionNames does not seem to exist. Did you mean forbiddenFunctions?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
652
                $this->forbiddenFunctionNames[$i] = '/'.$name.'/i';
0 ignored issues
show
Bug introduced by
The property forbiddenFunctionNames does not seem to exist. Did you mean forbiddenFunctions?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
653
            }
654
        }
655
656
        return array(T_STRING);
657
658
    }//end register()
659
660
661
    /**
662
     * Processes this test, when one of its tokens is encountered.
663
     *
664
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
665
     * @param int                  $stackPtr  The position of the current token in
666
     *                                        the stack passed in $tokens.
667
     *
668
     * @return void
669
     */
670
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
671
    {
672
        $tokens = $phpcsFile->getTokens();
673
674
        $ignore = array(
675
                T_DOUBLE_COLON,
676
                T_OBJECT_OPERATOR,
677
                T_FUNCTION,
678
                T_CONST,
679
                T_USE,
680
                T_NS_SEPARATOR,
681
        );
682
683
        $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
684
        if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
685
            // Not a call to a PHP function.
686
            return;
687
        }
688
689
        $function = strtolower($tokens[$stackPtr]['content']);
690
        $pattern  = null;
691
692 View Code Duplication
        if ($this->patternMatch === true) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
693
            $count   = 0;
694
            $pattern = preg_replace(
695
                    $this->forbiddenFunctionNames,
0 ignored issues
show
Bug introduced by
The property forbiddenFunctionNames does not seem to exist. Did you mean forbiddenFunctions?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
696
                    $this->forbiddenFunctionNames,
0 ignored issues
show
Bug introduced by
The property forbiddenFunctionNames does not seem to exist. Did you mean forbiddenFunctions?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
697
                    $function,
698
                    1,
699
                    $count
700
            );
701
702
            if ($count === 0) {
703
                return;
704
            }
705
706
            // Remove the pattern delimiters and modifier.
707
            $pattern = substr($pattern, 1, -2);
708
        } else {
709
            if (in_array($function, $this->forbiddenFunctionNames) === false) {
0 ignored issues
show
Bug introduced by
The property forbiddenFunctionNames does not seem to exist. Did you mean forbiddenFunctions?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
710
                return;
711
            }
712
        }
713
714
        $this->addError($phpcsFile, $stackPtr, $function, $pattern);
715
716
    }//end process()
717
718
    /**
719
     * Generates the error or warning for this sniff.
720
     *
721
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
722
     * @param int                  $stackPtr  The position of the forbidden function
723
     *                                        in the token array.
724
     * @param string               $function  The name of the forbidden function.
725
     * @param string               $pattern   The pattern used for the match.
726
     *
727
     * @return void
728
     */
729
    protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
730
    {
731
        if ($pattern === null) {
732
            $pattern = $function;
733
        }
734
735
        $error = '';
736
737
        $isError = false;
738
        $previousVersionStatus = null;
739 View Code Duplication
        foreach ($this->forbiddenFunctions[$pattern] as $version => $forbidden) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
740
            if ($this->supportsAbove($version)) {
741
                if ($version != 'alternative') {
742
                    if ($previousVersionStatus !== $forbidden) {
743
                        $previousVersionStatus = $forbidden;
744
                        if ($forbidden === true) {
745
                            $isError = true;
746
                            $error .= 'forbidden';
747
                        } else {
748
                            $error .= 'discouraged';
749
                        }
750
                        $error .=  ' from PHP version ' . $version . ' and ';
751
                    }
752
                }
753
            }
754
        }
755
        if (strlen($error) > 0) {
756
            $error = 'The use of function ' . $function . ' is ' . $error;
757
            $error = substr($error, 0, strlen($error) - 5);
758
759
            if ($this->forbiddenFunctions[$pattern]['alternative'] !== null) {
760
                $error .= '; use ' . $this->forbiddenFunctions[$pattern]['alternative'] . ' instead';
761
            }
762
763
            if ($isError === true) {
764
                $phpcsFile->addError($error, $stackPtr);
765
            } else {
766
                $phpcsFile->addWarning($error, $stackPtr);
767
            }
768
        }
769
770
    }//end addError()
771
772
}//end class
773