Completed
Pull Request — master (#190)
by
unknown
04:51
created

DeprecatedIniOptions::pass()   C

Complexity

Conditions 7
Paths 5

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
cc 7
eloc 14
nc 5
nop 2
dl 0
loc 22
ccs 0
cts 20
cp 0
crap 56
rs 6.9811
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Analyzer\Pass\Expression\FunctionCall;
7
8
use PhpParser\Node\Expr\FuncCall;
9
use PHPSA\Context;
10
11
class DeprecatedIniOptions extends AbstractFunctionCallAnalyzer
12
{
13
    static protected $functions = array(
14
        'ini_set' => 'ini_set',
15
        'ini_get' => 'ini_get',
16
        'ini_alter' => 'ini_alter',
17
        'ini_restore' => 'ini_restore'
18
    );
19
20
    static protected $deprecatedOptions = array(
21
        'asp_tags' => 'is a deprecated option since PHP 7.0.0',
22
        'always_populate_raw_post_data' => 'is a deprecated option since PHP 7.0.0',
23
        //
24
        'iconv.input_encoding' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead',
25
        'iconv.output_encoding' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead',
26
        'iconv.internal_encoding' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead',
27
        'mbstring.http_input' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead',
28
        'mbstring.http_output' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead',
29
        'mbstring.internal_encoding' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead',
30
        //
31
        'xsl.security_prefs' => 'is a deprecated option since PHP 5.4.0 (removed in PHP 7.0.0). Use XsltProcessor->setSecurityPrefs() instead',
32
        //
33
        'allow_call_time_pass_reference' => 'is a deprecated option since PHP 5.4.0',
34
        'highlight.bg' => 'is a deprecated option since PHP 5.4.0',
35
        'zend.ze1_compatibility_mode' => 'is a deprecated option since PHP 5.4.0',
36
        'session.bug_compat_42' => 'is a deprecated option since PHP 5.4.0',
37
        'session.bug_compat_warn' => 'is a deprecated option since PHP 5.4.0',
38
        'y2k_compliance' => 'is a deprecated option since PHP 5.4.0',
39
        //
40
        'define_syslog_variables' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
41
        'magic_quotes_gpc' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
42
        'magic_quotes_runtime' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
43
        'magic_quotes_sybase' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
44
        'register_globals' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
45
        'register_long_arrays' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
46
        'safe_mode' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
47
        'safe_mode_gid' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
48
        'safe_mode_include_dir' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
49
        'safe_mode_exec_dir' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
50
        'safe_mode_allowed_env_vars' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
51
        'safe_mode_protected_env_vars' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)'
52
    );
53
54
    public function pass(FuncCall $funcCall, Context $context)
55
    {
56
        $functionName = $this->resolveFunctionName($funcCall, $context);
57
        if ($functionName && isset(self::$functions[$functionName])) {
58
            if ($funcCall->args) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $funcCall->args of type PhpParser\Node\Arg[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
59
                $compiledOptionName = $context->getExpressionCompiler()->compile($funcCall->args[0]);
60
                if ($compiledOptionName->isString() && $compiledOptionName->isCorrectValue()) {
61
                    if (isset(self::$deprecatedOptions[$compiledOptionName->getValue()])) {
62
                        $context->notice(
63
                            'deprecated.option',
64
                            sprintf(
65
                                'Ini option %s %s.',
66
                                $compiledOptionName->getValue(),
67
                                self::$deprecatedOptions[$compiledOptionName->getValue()]
68
                            ),
69
                            $funcCall
70
                        );
71
                    }
72
                }
73
            }
74
        }
75
    }
76
}
77