Completed
Pull Request — master (#110)
by Wim
03:06
created

DeprecatedFunctionsSniff::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 47
Code Lines 29

Duplication

Lines 21
Ratio 44.68 %

Importance

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