Completed
Push — master ( b52690...50932b )
by Wim
02:29
created

process()   C

Complexity

Conditions 11
Paths 18

Size

Total Lines 50
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 50
rs 5.4893
cc 11
eloc 28
nc 18
nop 2

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_NewIniDirectivesSniff.
4
 *
5
 * PHP version 5.5
6
 *
7
 * @category  PHP
8
 * @package   PHPCompatibility
9
 * @author    Wim Godden <[email protected]>
10
 * @copyright 2013 Cu.be Solutions bvba
11
 */
12
13
/**
14
 * PHPCompatibility_Sniffs_PHP_NewIniDirectivesSniff.
15
 *
16
 * Discourages the use of new INI directives through ini_set() or ini_get().
17
 *
18
 * @category  PHP
19
 * @package   PHPCompatibility
20
 * @author    Wim Godden <[email protected]>
21
 * @copyright 2013 Cu.be Solutions bvba
22
 */
23
class PHPCompatibility_Sniffs_PHP_NewIniDirectivesSniff 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...
24
{
25
    /**
26
     * A list of new INI directives
27
     *
28
     * @var array(string)
29
     */
30
    protected $newIniDirectives = array(
31
        'auto_globals_jit' => array(
32
            '4.4' => false,
33
            '5.0' => true,
34
        ),
35
        'com.code_page' => array(
36
            '4.4' => false,
37
            '5.0' => true,
38
        ),
39
        'date.default_latitude' => array(
40
            '4.4' => false,
41
            '5.0' => true,
42
        ),
43
        'date.default_longitude' => array(
44
            '4.4' => false,
45
            '5.0' => true,
46
        ),
47
        'date.sunrise_zenith' => array(
48
            '4.4' => false,
49
            '5.0' => true,
50
        ),
51
        'date.sunset_zenith' => array(
52
            '4.4' => false,
53
            '5.0' => true,
54
        ),
55
        'ibase.default_charset' => array(
56
            '4.4' => false,
57
            '5.0' => true,
58
        ),
59
        'ibase.default_db' => array(
60
            '4.4' => false,
61
            '5.0' => true,
62
        ),
63
        'mail.force_extra_parameters' => array(
64
            '4.4' => false,
65
            '5.0' => true,
66
        ),
67
        'mime_magic.debug' => array(
68
            '4.4' => false,
69
            '5.0' => true,
70
        ),
71
        'mysqli.max_links' => array(
72
            '4.4' => false,
73
            '5.0' => true,
74
        ),
75
        'mysqli.default_port' => array(
76
            '4.4' => false,
77
            '5.0' => true,
78
        ),
79
        'mysqli.default_socket' => array(
80
            '4.4' => false,
81
            '5.0' => true,
82
        ),
83
        'mysqli.default_host' => array(
84
            '4.4' => false,
85
            '5.0' => true,
86
        ),
87
        'mysqli.default_user' => array(
88
            '4.4' => false,
89
            '5.0' => true,
90
        ),
91
        'mysqli.default_pw' => array(
92
            '4.4' => false,
93
            '5.0' => true,
94
        ),
95
        'report_zend_debug' => array(
96
            '4.4' => false,
97
            '5.0' => true,
98
        ),
99
        'session.hash_bits_per_character' => array(
100
            '4.4' => false,
101
            '5.0' => true,
102
        ),
103
        'session.hash_function' => array(
104
            '4.4' => false,
105
            '5.0' => true,
106
        ),
107
        'soap.wsdl_cache_dir' => array(
108
            '4.4' => false,
109
            '5.0' => true,
110
        ),
111
        'soap.wsdl_cache_enabled' => array(
112
            '4.4' => false,
113
            '5.0' => true,
114
        ),
115
        'soap.wsdl_cache_ttl' => array(
116
            '4.4' => false,
117
            '5.0' => true,
118
        ),
119
        'sqlite.assoc_case' => array(
120
            '4.4' => false,
121
            '5.0' => true,
122
        ),
123
        'tidy.clean_output' => array(
124
            '4.4' => false,
125
            '5.0' => true,
126
        ),
127
        'tidy.default_config' => array(
128
            '4.4' => false,
129
            '5.0' => true,
130
        ),
131
        'zend.ze1_compatibility_mode' => array(
132
            '4.4' => false,
133
            '5.0' => true,
134
        ),
135
136
        'date.timezone' => array(
137
            '5.0' => false,
138
            '5.1' => true,
139
        ),
140
        'detect_unicode' => array(
141
            '5.0' => false,
142
            '5.1' => true,
143
        ),
144
        'fbsql.batchsize' => array(
145
            '5.0'         => false,
146
            '5.1'         => true,
147
            'alternative' => 'fbsql.batchSize',
148
        ),
149
        'realpath_cache_size' => array(
150
            '5.0' => false,
151
            '5.1' => true,
152
        ),
153
        'realpath_cache_ttl' => array(
154
            '5.0' => false,
155
            '5.1' => true,
156
        ),
157
158
        'mbstring.strict_detection' => array(
159
            '5.0'   => false,
160
            '5.1'   => false,
161
            '5.1.2' => true,
162
        ),
163
        'mssql.charset' => array(
164
            '5.0'   => false,
165
            '5.1'   => false,
166
            '5.1.2' => true,
167
        ),
168
169
        'gd.jpeg_ignore_warning' => array(
170
            '5.0'   => false,
171
            '5.1'   => false,
172
            '5.1.3' => true,
173
        ),
174
175
        'fbsql.show_timestamp_decimals' => array(
176
            '5.0'   => false,
177
            '5.1'   => false,
178
            '5.1.5' => true,
179
        ),
180
        'soap.wsdl_cache' => array(
181
            '5.0'   => false,
182
            '5.1'   => false,
183
            '5.1.5' => true,
184
        ),
185
        'soap.wsdl_cache_limit' => array(
186
            '5.0'   => false,
187
            '5.1'   => false,
188
            '5.1.5' => true,
189
        ),
190
191
        'allow_url_include' => array(
192
            '5.1' => false,
193
            '5.2' => true
194
        ),
195
        'filter.default' => array(
196
            '5.1' => false,
197
            '5.2' => true,
198
        ),
199
        'filter.default_flags' => array(
200
            '5.1' => false,
201
            '5.2' => true,
202
        ),
203
        'pcre.backtrack_limit' => array(
204
            '5.1' => false,
205
            '5.2' => true
206
        ),
207
        'pcre.recursion_limit' => array(
208
            '5.1' => false,
209
            '5.2' => true
210
        ),
211
        'session.cookie_httponly' => array(
212
            '5.1' => false,
213
            '5.2' => true
214
        ),
215
216
        'cgi.check_shebang_line' => array(
217
            '5.1' => false,
218
            '5.2' => false,
219
            '5.2.1' => true
220
        ),
221
222
        'max_input_nesting_level' => array(
223
            '5.1' => false,
224
            '5.2' => false,
225
            '5.2.3' => true
226
        ),
227
228
        'mysqli.allow_local_infile' => array(
229
            '5.1'   => false,
230
            '5.2'   => false,
231
            '5.2.4' => true,
232
        ),
233
234
        'max_file_uploads' => array(
235
            '5.1'    => false,
236
            '5.2'    => false,
237
            '5.2.12' => true,
238
        ),
239
240
        'cgi.discard_path' => array(
241
            '5.2' => false,
242
            '5.3' => true,
243
        ),
244
        'exit_on_timeout' => array(
245
            '5.2' => false,
246
            '5.3' => true,
247
        ),
248
        'intl.default_locale' => array(
249
            '5.2' => false,
250
            '5.3' => true,
251
        ),
252
        'intl.error_level' => array(
253
            '5.2' => false,
254
            '5.3' => true,
255
        ),
256
        'mail.add_x_header' => array(
257
            '5.2' => false,
258
            '5.3' => true,
259
        ),
260
        'mail.log' => array(
261
            '5.2' => false,
262
            '5.3' => true,
263
        ),
264
        'mbstring.http_output_conv_mimetype' => array(
265
            '5.2' => false,
266
            '5.3' => true,
267
        ),
268
        'mysqli.allow_persistent' => array(
269
            '5.2' => false,
270
            '5.3' => true,
271
        ),
272
        'mysqli.cache_size' => array(
273
            '5.2' => false,
274
            '5.3' => true,
275
        ),
276
        'mysqli.max_persistent' => array(
277
            '5.2' => false,
278
            '5.3' => true,
279
        ),
280
        'mysqlnd.collect_memory_statistics' => array(
281
            '5.2' => false,
282
            '5.3' => true,
283
        ),
284
        'mysqlnd.collect_statistics' => array(
285
            '5.2' => false,
286
            '5.3' => true,
287
        ),
288
        'mysqlnd.debug' => array(
289
            '5.2' => false,
290
            '5.3' => true,
291
        ),
292
        'mysqlnd.net_read_buffer_size' => array(
293
            '5.2' => false,
294
            '5.3' => true,
295
        ),
296
        'odbc.default_cursortype' => array(
297
            '5.2' => false,
298
            '5.3' => true,
299
        ),
300
        'request_order' => array(
301
            '5.2' => false,
302
            '5.3' => true,
303
        ),
304
        'user_ini.cache_ttl' => array(
305
            '5.2' => false,
306
            '5.3' => true,
307
        ),
308
        'user_ini.filename' => array(
309
            '5.2' => false,
310
            '5.3' => true,
311
        ),
312
        'zend.enable_gc' => array(
313
            '5.2' => false,
314
            '5.3' => true,
315
        ),
316
317
        'curl.cainfo' => array(
318
            '5.2' => false,
319
            '5.3' => false,
320
            '5.3.7' => true,
321
        ),
322
323
        'max_input_vars' => array(
324
            '5.2'   => false,
325
            '5.3'   => false,
326
            '5.3.9' => true,
327
        ),
328
329
        'sqlite3.extension_dir' => array(
330
            '5.2'    => false,
331
            '5.3'    => false,
332
            '5.3.11' => true,
333
        ),
334
335
        'cli.pager' => array(
336
            '5.3' => false,
337
            '5.4' => true,
338
        ),
339
        'cli.prompt' => array(
340
            '5.3' => false,
341
            '5.4' => true,
342
        ),
343
        'cli_server.color' => array(
344
            '5.3' => false,
345
            '5.4' => true,
346
        ),
347
        'enable_post_data_reading' => array(
348
            '5.3' => false,
349
            '5.4' => true,
350
        ),
351
        'mysqlnd.mempool_default_size' => array(
352
            '5.3' => false,
353
            '5.4' => true,
354
        ),
355
        'mysqlnd.net_cmd_buffer_size' => array(
356
            '5.3' => false,
357
            '5.4' => true,
358
        ),
359
        'mysqlnd.net_read_timeout' => array(
360
            '5.3' => false,
361
            '5.4' => true,
362
        ),
363
        'phar.cache_list' => array(
364
            '5.3' => false,
365
            '5.4' => true,
366
        ),
367
        'session.upload_progress.enabled' => array(
368
            '5.3' => false,
369
            '5.4' => true,
370
        ),
371
        'session.upload_progress.cleanup' => array(
372
            '5.3' => false,
373
            '5.4' => true,
374
        ),
375
        'session.upload_progress.name' => array(
376
            '5.3' => false,
377
            '5.4' => true,
378
        ),
379
        'session.upload_progress.freq' => array(
380
            '5.3' => false,
381
            '5.4' => true,
382
        ),
383
        'session.upload_progress.min_freq' => array(
384
            '5.3' => false,
385
            '5.4' => true,
386
        ),
387
        'session.upload_progress.prefix' => array(
388
            '5.3' => false,
389
            '5.4' => true,
390
        ),
391
        'windows_show_crt_warning' => array(
392
            '5.3' => false,
393
            '5.4' => true,
394
        ),
395
        'zend.detect_unicode' => array(
396
            '5.3'         => false,
397
            '5.4'         => true,
398
            'alternative' => 'detect_unicode',
399
        ),
400
        'zend.multibyte' => array(
401
            '5.3' => false,
402
            '5.4' => true,
403
        ),
404
        'zend.script_encoding' => array(
405
            '5.3' => false,
406
            '5.4' => true,
407
        ),
408
        'zend.signal_check' => array(
409
            '5.3' => false,
410
            '5.4' => true,
411
        ),
412
        'mysqlnd.log_mask' => array(
413
            '5.3' => false,
414
            '5.4' => true,
415
        ),
416
417
        'intl.use_exceptions' => array(
418
            '5.4' => false,
419
            '5.5' => true,
420
        ),
421
        'mysqlnd.sha256_server_public_key' => array(
422
            '5.4' => false,
423
            '5.5' => true,
424
        ),
425
        'mysqlnd.trace_alloc' => array(
426
            '5.4' => false,
427
            '5.5' => true,
428
        ),
429
        'sys_temp_dir' => array(
430
            '5.4' => false,
431
            '5.5' => true,
432
        ),
433
        'xsl.security_prefs' => array(
434
            '5.4' => false,
435
            '5.5' => true,
436
        ),
437
438
        'session.use_strict_mode' => array(
439
            '5.4'   => false,
440
            '5.5'   => false,
441
            '5.5.2' => true,
442
        ),
443
444
        'mysqli.rollback_on_cached_plink' => array(
445
            '5.5' => false,
446
            '5.6' => true,
447
        ),
448
449
        'assert.exception' => array(
450
            '5.6' => false,
451
            '7.0' => true,
452
        ),
453
        'pcre.jit' => array(
454
            '5.6' => false,
455
            '7.0' => true,
456
        ),
457
        'session.lazy_write' => array(
458
            '5.6' => false,
459
            '7.0' => true,
460
        ),
461
        'zend.assertions' => array(
462
            '5.6' => false,
463
            '7.0' => true,
464
        ),
465
    );
466
467
    /**
468
     * Returns an array of tokens this test wants to listen for.
469
     *
470
     * @return array
471
     */
472
    public function register()
473
    {
474
        return array(T_STRING);
475
476
    }//end register()
477
478
    /**
479
     * Processes this test, when one of its tokens is encountered.
480
     *
481
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
482
     * @param int                  $stackPtr  The position of the current token in the
483
     *                                        stack passed in $tokens.
484
     *
485
     * @return void
486
     */
487
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
488
    {
489
        $tokens = $phpcsFile->getTokens();
490
491
        $ignore = array(
492
                   T_DOUBLE_COLON,
493
                   T_OBJECT_OPERATOR,
494
                   T_FUNCTION,
495
                   T_CONST,
496
                  );
497
498
        $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
499
        if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
500
            // Not a call to a PHP function.
501
            return;
502
        }
503
504
        $function = strtolower($tokens[$stackPtr]['content']);
505
        if ($function != 'ini_get' && $function != 'ini_set') {
506
            return;
507
        }
508
509
        $iniToken      = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr, null);
510
        $filteredToken = trim($tokens[$iniToken]['content'], '\'"');
511
        if (isset($this->newIniDirectives[$filteredToken]) === false) {
512
            return;
513
        }
514
515
        $error = '';
516
517
        foreach ($this->newIniDirectives[$filteredToken] as $version => $present) {
518
            if ($version !== 'alternative') {
519
                if ($this->supportsBelow($version)) {
520
                    if ($present === true) {
521
                        $error .= " not available before version " . $version;
522
                    }
523
                }
524
            }
525
        }
526
527
        if (strlen($error) > 0) {
528
            $error = "INI directive '" . $filteredToken . "' is" . $error;
529
            if (isset($this->newIniDirectives[$filteredToken]['alternative'])) {
530
                $error .= ". This directive was previously called '" . $this->newIniDirectives[$filteredToken]['alternative'] . "'.";
531
            }
532
533
            $phpcsFile->addWarning($error, $stackPtr);
534
        }
535
536
    }//end process()
537
538
539
}//end class
540