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

DeprecatedFunctionsSniff::addError()   D

Complexity

Conditions 10
Paths 60

Size

Total Lines 42
Code Lines 26

Duplication

Lines 14
Ratio 33.33 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 14
loc 42
rs 4.8196
cc 10
eloc 26
nc 60
nop 4

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
     * A list of forbidden functions with their alternatives.
23
     *
24
     * The array lists : version number with false (deprecated) or true (forbidden) and an alternative function.
25
     * If no alternative exists, it is NULL, i.e, the function should just not be used.
26
     *
27
     * @var array(string => array(string => bool|string|null))
28
     */
29
    protected $forbiddenFunctions = array(
30
                                        'php_check_syntax' => array(
31
                                            '5.0.5' => true,
32
                                            'alternative' => null
33
                                        ),
34
                                        'call_user_method' => array(
35
                                            '5.3' => false,
36
                                            '5.4' => false,
37
                                            '5.5' => false,
38
                                            '5.6' => false,
39
                                            '7.0' => true,
40
                                            'alternative' => 'call_user_func'
41
                                        ),
42
                                        'call_user_method_array' => 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_array'
49
                                        ),
50
                                        'define_syslog_variables' => array(
51
                                            '5.3' => false,
52
                                            '5.4' => true,
53
                                            '5.5' => true,
54
                                            '5.6' => true,
55
                                            'alternative' => null
56
                                        ),
57
                                        'dl' => array(
58
                                            '5.3' => false,
59
                                            '5.4' => false,
60
                                            '5.5' => false,
61
                                            '5.6' => false,
62
                                            'alternative' => null
63
                                        ),
64
                                        'ereg' => array(
65
                                            '5.3' => false,
66
                                            '5.4' => false,
67
                                            '5.5' => false,
68
                                            '5.6' => false,
69
                                            '7.0' => true,
70
                                            'alternative' => 'preg_match'
71
                                        ),
72
                                        'ereg_replace' => array(
73
                                            '5.3' => false,
74
                                            '5.4' => false,
75
                                            '5.5' => false,
76
                                            '5.6' => false,
77
                                            '7.0' => true,
78
                                            'alternative' => 'preg_replace'
79
                                        ),
80
                                        'eregi' => array(
81
                                            '5.3' => false,
82
                                            '5.4' => false,
83
                                            '5.5' => false,
84
                                            '5.6' => false,
85
                                            '7.0' => true,
86
                                            'alternative' => 'preg_match'
87
                                        ),
88
                                        'eregi_replace' => array(
89
                                            '5.3' => false,
90
                                            '5.4' => false,
91
                                            '5.5' => false,
92
                                            '5.6' => false,
93
                                            '7.0' => true,
94
                                            'alternative' => 'preg_replace'
95
                                        ),
96
                                        'imagepsbbox' => array(
97
                                            '7.0' => true,
98
                                            'alternative' => null
99
                                        ),
100
                                        'imagepsencodefont' => array(
101
                                            '7.0' => true,
102
                                            'alternative' => null
103
                                        ),
104
                                        'imagepsextendfont' => array(
105
                                            '7.0' => true,
106
                                            'alternative' => null
107
                                        ),
108
                                        'imagepsfreefont' => array(
109
                                            '7.0' => true,
110
                                            'alternative' => null
111
                                        ),
112
                                        'imagepsloadfont' => array(
113
                                            '7.0' => true,
114
                                            'alternative' => null
115
                                        ),
116
                                        'imagepsslantfont' => array(
117
                                            '7.0' => true,
118
                                            'alternative' => null
119
                                        ),
120
                                        'imagepstext' => array(
121
                                            '7.0' => true,
122
                                            'alternative' => null
123
                                        ),
124
                                        'import_request_variables' => array(
125
                                            '5.3' => false,
126
                                            '5.4' => true,
127
                                            'alternative' => null
128
                                        ),
129
                                        'ldap_sort' => array(
130
                                            '7.0' => false,
131
                                            'alternative' => null
132
                                        ),
133
                                        'mcrypt_generic_end' => array(
134
                                            '5.4' => false,
135
                                            '5.5' => false,
136
                                            '5.6' => false,
137
                                            '7.0' => true,
138
                                            'alternative' => 'mcrypt_generic_deinit'
139
                                        ),
140
                                        'mysql_db_query' => array(
141
                                            '5.3' => false,
142
                                            '5.4' => false,
143
                                            '5.5' => false,
144
                                            '5.6' => false,
145
                                            '7.0' => true,
146
                                            'alternative' => 'mysqli_select_db and mysqli_query'
147
                                        ),
148
                                        'mysql_escape_string' => array(
149
                                            '5.3' => false,
150
                                            '5.4' => false,
151
                                            '5.5' => false,
152
                                            '5.6' => false,
153
                                            '7.0' => true,
154
                                            'alternative' => 'mysqli_real_escape_string'
155
                                        ),
156
                                        'mysql_list_dbs' => array(
157
                                            '5.4' => false,
158
                                            '5.5' => false,
159
                                            '5.6' => false,
160
                                            '7.0' => true,
161
                                            'alternative' => null
162
                                        ),
163
                                        'mysqli_bind_param' => array(
164
                                            '5.3' => false,
165
                                            '5.4' => true,
166
                                            '5.5' => true,
167
                                            '5.6' => true,
168
                                            'alternative' => 'mysqli_stmt_bind_param'
169
                                        ),
170
                                        'mysqli_bind_result' => array(
171
                                            '5.3' => false,
172
                                            '5.4' => true,
173
                                            '5.5' => true,
174
                                            '5.6' => true,
175
                                            'alternative' => 'mysqli_stmt_bind_result'
176
                                        ),
177
                                        'mysqli_client_encoding' => array(
178
                                            '5.3' => false,
179
                                            '5.4' => true,
180
                                            '5.5' => true,
181
                                            '5.6' => true,
182
                                            'alternative' => 'mysqli_character_set_name'
183
                                        ),
184
                                        'mysqli_fetch' => array(
185
                                            '5.3' => false,
186
                                            '5.4' => true,
187
                                            '5.5' => true,
188
                                            '5.6' => true,
189
                                            'alternative' => 'mysqli_stmt_fetch'
190
                                        ),
191
                                        'mysqli_param_count' => array(
192
                                            '5.3' => false,
193
                                            '5.4' => true,
194
                                            '5.5' => true,
195
                                            '5.6' => true,
196
                                            'alternative' => 'mysqli_stmt_param_count'
197
                                        ),
198
                                        'mysqli_get_metadata' => array(
199
                                            '5.3' => false,
200
                                            '5.4' => true,
201
                                            '5.5' => true,
202
                                            '5.6' => true,
203
                                            'alternative' => 'mysqli_stmt_result_metadata'
204
                                        ),
205
                                        'mysqli_send_long_data' => array(
206
                                            '5.3' => false,
207
                                            '5.4' => true,
208
                                            '5.5' => true,
209
                                            '5.6' => true,
210
                                            'alternative' => 'mysqli_stmt_send_long_data'
211
                                        ),
212
                                        'magic_quotes_runtime' => array(
213
                                            '5.3' => false,
214
                                            '5.4' => false,
215
                                            '5.5' => false,
216
                                            '5.6' => false,
217
                                            '7.0' => true,
218
                                            'alternative' => null
219
                                        ),
220
                                        'session_register' => array(
221
                                            '5.3' => false,
222
                                            '5.4' => true,
223
                                            '5.5' => true,
224
                                            '5.6' => true,
225
                                            'alternative' => '$_SESSION'
226
                                        ),
227
                                        'session_unregister' => array(
228
                                            '5.3' => false,
229
                                            '5.4' => true,
230
                                            '5.5' => true,
231
                                            '5.6' => true,
232
                                            'alternative' => '$_SESSION'
233
                                        ),
234
                                        'session_is_registered' => array(
235
                                            '5.3' => false,
236
                                            '5.4' => true,
237
                                            '5.5' => true,
238
                                            '5.6' => true,
239
                                            'alternative' => '$_SESSION'
240
                                        ),
241
                                        'set_magic_quotes_runtime' => array(
242
                                            '5.3' => false,
243
                                            '5.4' => false,
244
                                            '5.5' => false,
245
                                            '5.6' => false,
246
                                            '7.0' => true,
247
                                            'alternative' => null
248
                                        ),
249
                                        'set_socket_blocking' => array(
250
                                            '5.3' => false,
251
                                            '5.4' => false,
252
                                            '5.5' => false,
253
                                            '5.6' => false,
254
                                            '7.0' => true,
255
                                            'alternative' => 'stream_set_blocking'
256
                                        ),
257
                                        'split' => array(
258
                                            '5.3' => false,
259
                                            '5.4' => false,
260
                                            '5.5' => false,
261
                                            '5.6' => false,
262
                                            '7.0' => true,
263
                                            'alternative' => 'preg_split'
264
                                        ),
265
                                        'spliti' => 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
                                        'sql_regcase' => array(
274
                                            '5.3' => false,
275
                                            '5.4' => false,
276
                                            '5.5' => false,
277
                                            '5.6' => false,
278
                                            '7.0' => true,
279
                                            'alternative' => null
280
                                        ),
281
                                        'php_logo_guid' => array(
282
                                            '5.5' => true,
283
                                            '5.6' => true,
284
                                            'alternative' => null
285
                                        ),
286
                                        'php_egg_logo_guid' => array(
287
                                            '5.5' => true,
288
                                            '5.6' => true,
289
                                            'alternative' => null
290
                                        ),
291
                                        'php_real_logo_guid' => array(
292
                                            '5.5' => true,
293
                                            '5.6' => true,
294
                                            'alternative' => null
295
                                        ),
296
                                        'zend_logo_guid' => array(
297
                                            '5.5' => true,
298
                                            '5.6' => true,
299
                                            'alternative' => null
300
                                        ),
301
                                        'datefmt_set_timezone_id' => array(
302
                                            '5.5' => false,
303
                                            '5.6' => false,
304
                                            '7.0' => true,
305
                                            'alternative' => 'datefmt_set_timezone'
306
                                        ),
307
                                        'mcrypt_ecb' => array(
308
                                            '5.5' => false,
309
                                            '5.6' => false,
310
                                            '7.0' => true,
311
                                            'alternative' => null
312
                                        ),
313
                                        'mcrypt_cbc' => array(
314
                                            '5.5' => false,
315
                                            '5.6' => false,
316
                                            '7.0' => true,
317
                                            'alternative' => null
318
                                        ),
319
                                        'mcrypt_cfb' => array(
320
                                            '5.5' => false,
321
                                            '5.6' => false,
322
                                            '7.0' => true,
323
                                            'alternative' => null
324
                                        ),
325
                                        'mcrypt_ofb' => array(
326
                                            '5.5' => false,
327
                                            '5.6' => false,
328
                                            '7.0' => true,
329
                                            'alternative' => null
330
                                        ),
331
                                        'ocibindbyname' => array(
332
                                            '5.4' => false,
333
                                            '5.5' => false,
334
                                            '5.6' => false,
335
                                            'alternative' => 'oci_bind_by_name'
336
                                        ),
337
                                        'ocicancel' => array(
338
                                            '5.4' => false,
339
                                            '5.5' => false,
340
                                            '5.6' => false,
341
                                            'alternative' => 'oci_cancel'
342
                                        ),
343
                                        'ocicloselob' => array(
344
                                            '5.4' => false,
345
                                            '5.5' => false,
346
                                            '5.6' => false,
347
                                            'alternative' => 'OCI-Lob::close'
348
                                        ),
349
                                        'ocicollappend' => array(
350
                                            '5.4' => false,
351
                                            '5.5' => false,
352
                                            '5.6' => false,
353
                                            'alternative' => 'OCI-Collection::append'
354
                                        ),
355
                                        'ocicollassign' => array(
356
                                            '5.4' => false,
357
                                            '5.5' => false,
358
                                            '5.6' => false,
359
                                            'alternative' => 'OCI-Collection::assign'
360
                                        ),
361
                                        'ocicollassignelem' => array(
362
                                            '5.4' => false,
363
                                            '5.5' => false,
364
                                            '5.6' => false,
365
                                            'alternative' => 'OCI-Collection::assignElem'
366
                                        ),
367
                                        'ocicollgetelem' => array(
368
                                            '5.4' => false,
369
                                            '5.5' => false,
370
                                            '5.6' => false,
371
                                            'alternative' => 'OCI-Collection::getElem'
372
                                        ),
373
                                        'ocicollmax' => array(
374
                                            '5.4' => false,
375
                                            '5.5' => false,
376
                                            '5.6' => false,
377
                                            'alternative' => 'OCI-Collection::max'
378
                                        ),
379
                                        'ocicollsize' => array(
380
                                            '5.4' => false,
381
                                            '5.5' => false,
382
                                            '5.6' => false,
383
                                            'alternative' => 'OCI-Collection::size'
384
                                        ),
385
                                        'ocicolltrim' => array(
386
                                            '5.4' => false,
387
                                            '5.5' => false,
388
                                            '5.6' => false,
389
                                            'alternative' => 'OCI-Collection::trim'
390
                                        ),
391
                                        'ocicolumnisnull' => array(
392
                                            '5.4' => false,
393
                                            '5.5' => false,
394
                                            '5.6' => false,
395
                                            'alternative' => 'oci_field_is_null'
396
                                        ),
397
                                        'ocicolumnname' => array(
398
                                            '5.4' => false,
399
                                            '5.5' => false,
400
                                            '5.6' => false,
401
                                            'alternative' => 'oci_field_name'
402
                                        ),
403
                                        'ocicolumnprecision' => array(
404
                                            '5.4' => false,
405
                                            '5.5' => false,
406
                                            '5.6' => false,
407
                                            'alternative' => 'oci_field_precision'
408
                                        ),
409
                                        'ocicolumnscale' => array(
410
                                            '5.4' => false,
411
                                            '5.5' => false,
412
                                            '5.6' => false,
413
                                            'alternative' => 'oci_field_scale'
414
                                        ),
415
                                        'ocicolumnsize' => array(
416
                                            '5.4' => false,
417
                                            '5.5' => false,
418
                                            '5.6' => false,
419
                                            'alternative' => 'oci_field_size'
420
                                        ),
421
                                        'ocicolumntype' => array(
422
                                            '5.4' => false,
423
                                            '5.5' => false,
424
                                            '5.6' => false,
425
                                            'alternative' => 'oci_field_type'
426
                                        ),
427
                                        'ocicolumntyperaw' => array(
428
                                            '5.4' => false,
429
                                            '5.5' => false,
430
                                            '5.6' => false,
431
                                            'alternative' => 'oci_field_type_raw'
432
                                        ),
433
                                        'ocicommit' => array(
434
                                            '5.4' => false,
435
                                            '5.5' => false,
436
                                            '5.6' => false,
437
                                            'alternative' => 'oci_commit'
438
                                        ),
439
                                        'ocidefinebyname' => array(
440
                                            '5.4' => false,
441
                                            '5.5' => false,
442
                                            '5.6' => false,
443
                                            'alternative' => 'oci_define_by_name'
444
                                        ),
445
                                        'ocierror' => array(
446
                                            '5.4' => false,
447
                                            '5.5' => false,
448
                                            '5.6' => false,
449
                                            'alternative' => 'oci_error'
450
                                        ),
451
                                        'ociexecute' => array(
452
                                            '5.4' => false,
453
                                            '5.5' => false,
454
                                            '5.6' => false,
455
                                            'alternative' => 'oci_execute'
456
                                        ),
457
                                        'ocifetch' => array(
458
                                            '5.4' => false,
459
                                            '5.5' => false,
460
                                            '5.6' => false,
461
                                            'alternative' => 'oci_fetch'
462
                                        ),
463
                                        'ocifetchinto' => array(
464
                                            '5.4' => false,
465
                                            '5.5' => false,
466
                                            '5.6' => false,
467
                                            'alternative' => null
468
                                        ),
469
                                        'ocifetchstatement' => array(
470
                                            '5.4' => false,
471
                                            '5.5' => false,
472
                                            '5.6' => false,
473
                                            'alternative' => 'oci_fetch_all'
474
                                        ),
475
                                        'ocifreecollection' => array(
476
                                            '5.4' => false,
477
                                            '5.5' => false,
478
                                            '5.6' => false,
479
                                            'alternative' => 'OCI-Collection::free'
480
                                        ),
481
                                        'ocifreecursor' => array(
482
                                            '5.4' => false,
483
                                            '5.5' => false,
484
                                            '5.6' => false,
485
                                            'alternative' => 'oci_free_statement'
486
                                        ),
487
                                        'ocifreedesc' => array(
488
                                            '5.4' => false,
489
                                            '5.5' => false,
490
                                            '5.6' => false,
491
                                            'alternative' => 'OCI-Lob::free'
492
                                        ),
493
                                        'ocifreestatement' => array(
494
                                            '5.4' => false,
495
                                            '5.5' => false,
496
                                            '5.6' => false,
497
                                            'alternative' => 'oci_free_statement'
498
                                        ),
499
                                        'ociinternaldebug' => array(
500
                                            '5.4' => false,
501
                                            '5.5' => false,
502
                                            '5.6' => false,
503
                                            'alternative' => 'oci_internal_debug'
504
                                        ),
505
                                        'ociloadlob' => array(
506
                                            '5.4' => false,
507
                                            '5.5' => false,
508
                                            '5.6' => false,
509
                                            'alternative' => 'OCI-Lob::load'
510
                                        ),
511
                                        'ocilogoff' => array(
512
                                            '5.4' => false,
513
                                            '5.5' => false,
514
                                            '5.6' => false,
515
                                            'alternative' => 'oci_close'
516
                                        ),
517
                                        'ocilogon' => array(
518
                                            '5.4' => false,
519
                                            '5.5' => false,
520
                                            '5.6' => false,
521
                                            'alternative' => 'oci_connect'
522
                                        ),
523
                                        'ocinewcollection' => array(
524
                                            '5.4' => false,
525
                                            '5.5' => false,
526
                                            '5.6' => false,
527
                                            'alternative' => 'oci_new_collection'
528
                                        ),
529
                                        'ocinewcursor' => array(
530
                                            '5.4' => false,
531
                                            '5.5' => false,
532
                                            '5.6' => false,
533
                                            'alternative' => 'oci_new_cursor'
534
                                        ),
535
                                        'ocinewdescriptor' => array(
536
                                            '5.4' => false,
537
                                            '5.5' => false,
538
                                            '5.6' => false,
539
                                            'alternative' => 'oci_new_descriptor'
540
                                        ),
541
                                        'ocinlogon' => array(
542
                                            '5.4' => false,
543
                                            '5.5' => false,
544
                                            '5.6' => false,
545
                                            'alternative' => 'oci_new_connect'
546
                                        ),
547
                                        'ocinumcols' => array(
548
                                            '5.4' => false,
549
                                            '5.5' => false,
550
                                            '5.6' => false,
551
                                            'alternative' => 'oci_num_fields'
552
                                        ),
553
                                        'ociparse' => array(
554
                                            '5.4' => false,
555
                                            '5.5' => false,
556
                                            '5.6' => false,
557
                                            'alternative' => 'oci_parse'
558
                                        ),
559
                                        'ociplogon' => array(
560
                                            '5.4' => false,
561
                                            '5.5' => false,
562
                                            '5.6' => false,
563
                                            'alternative' => 'oci_pconnect'
564
                                        ),
565
                                        'ociresult' => array(
566
                                            '5.4' => false,
567
                                            '5.5' => false,
568
                                            '5.6' => false,
569
                                            'alternative' => 'oci_result'
570
                                        ),
571
                                        'ocirollback' => array(
572
                                            '5.4' => false,
573
                                            '5.5' => false,
574
                                            '5.6' => false,
575
                                            'alternative' => 'oci_rollback'
576
                                        ),
577
                                        'ocirowcount' => array(
578
                                            '5.4' => false,
579
                                            '5.5' => false,
580
                                            '5.6' => false,
581
                                            'alternative' => 'oci_num_rows'
582
                                        ),
583
                                        'ocisavelob' => array(
584
                                            '5.4' => false,
585
                                            '5.5' => false,
586
                                            '5.6' => false,
587
                                            'alternative' => 'OCI-Lob::save'
588
                                        ),
589
                                        'ocisavelobfile' => array(
590
                                            '5.4' => false,
591
                                            '5.5' => false,
592
                                            '5.6' => false,
593
                                            'alternative' => 'OCI-Lob::import'
594
                                        ),
595
                                        'ociserverversion' => array(
596
                                            '5.4' => false,
597
                                            '5.5' => false,
598
                                            '5.6' => false,
599
                                            'alternative' => 'oci_server_version'
600
                                        ),
601
                                        'ocisetprefetch' => array(
602
                                            '5.4' => false,
603
                                            '5.5' => false,
604
                                            '5.6' => false,
605
                                            'alternative' => 'oci_set_prefetch'
606
                                        ),
607
                                        'ocistatementtype' => array(
608
                                            '5.4' => false,
609
                                            '5.5' => false,
610
                                            '5.6' => false,
611
                                            'alternative' => 'oci_statement_type'
612
                                        ),
613
                                        'ociwritelobtofile' => array(
614
                                            '5.4' => false,
615
                                            '5.5' => false,
616
                                            '5.6' => false,
617
                                            'alternative' => 'OCI-Lob::export'
618
                                        ),
619
                                        'ociwritetemporarylob' => array(
620
                                            '5.4' => false,
621
                                            '5.5' => false,
622
                                            '5.6' => false,
623
                                            'alternative' => 'OCI-Lob::writeTemporary'
624
                                        ),
625
                                        'mysqli_get_cache_stats' => array(
626
                                            '5.4' => true,
627
                                            'alternative' => null
628
                                        ),
629
                                    );
630
631
    /**
632
     * Returns an array of tokens this test wants to listen for.
633
     *
634
     * @return array
635
     */
636
    public function register()
637
    {
638
        // Everyone has had a chance to figure out what forbidden functions
639
        // they want to check for, so now we can cache out the list.
640
        $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...
641
642
        return array(T_STRING);
643
644
    }//end register()
645
646
647
    /**
648
     * Processes this test, when one of its tokens is encountered.
649
     *
650
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
651
     * @param int                  $stackPtr  The position of the current token in
652
     *                                        the stack passed in $tokens.
653
     *
654
     * @return void
655
     */
656
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
657
    {
658
        $tokens = $phpcsFile->getTokens();
659
660
        $ignore = array(
661
                T_DOUBLE_COLON,
662
                T_OBJECT_OPERATOR,
663
                T_FUNCTION,
664
                T_CONST,
665
                T_USE,
666
                T_NS_SEPARATOR,
667
        );
668
669
        $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
670
        if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
671
            // Not a call to a PHP function.
672
            return;
673
        }
674
675
        $function = strtolower($tokens[$stackPtr]['content']);
676
        $pattern  = null;
677
678
        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...
679
            return;
680
        }
681
682
        $this->addError($phpcsFile, $stackPtr, $function, $pattern);
683
684
    }//end process()
685
686
    /**
687
     * Generates the error or warning for this sniff.
688
     *
689
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
690
     * @param int                  $stackPtr  The position of the forbidden function
691
     *                                        in the token array.
692
     * @param string               $function  The name of the forbidden function.
693
     * @param string               $pattern   The pattern used for the match.
694
     *
695
     * @return void
696
     */
697
    protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
698
    {
699
        if ($pattern === null) {
700
            $pattern = $function;
701
        }
702
703
        $error = '';
704
705
        $isError = false;
706
        $previousVersionStatus = null;
707
        foreach ($this->forbiddenFunctions[$pattern] as $version => $forbidden) {
708
            if ($this->supportsAbove($version)) {
709
                if ($version != 'alternative') {
710
                    if ($previousVersionStatus !== $forbidden) {
711
                        $previousVersionStatus = $forbidden;
712
                        if ($forbidden === true) {
713
                            $isError = true;
714
                            $error .= 'forbidden';
715
                        } else {
716
                            $error .= 'discouraged';
717
                        }
718
                        $error .=  ' from PHP version ' . $version . ' and ';
719
                    }
720
                }
721
            }
722
        }
723 View Code Duplication
        if (strlen($error) > 0) {
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...
724
            $error = 'The use of function ' . $function . ' is ' . $error;
725
            $error = substr($error, 0, strlen($error) - 5);
726
727
            if ($this->forbiddenFunctions[$pattern]['alternative'] !== null) {
728
                $error .= '; use ' . $this->forbiddenFunctions[$pattern]['alternative'] . ' instead';
729
            }
730
731
            if ($isError === true) {
732
                $phpcsFile->addError($error, $stackPtr);
733
            } else {
734
                $phpcsFile->addWarning($error, $stackPtr);
735
            }
736
        }
737
738
    }//end addError()
739
740
}//end class
741