Completed
Push — master ( 853d12...6ab7bd )
by Дмитрий
11s
created

DeprecatedIniOptions::pass()   C

Complexity

Conditions 7
Paths 5

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 7

Importance

Changes 3
Bugs 0 Features 3
Metric Value
cc 7
eloc 14
c 3
b 0
f 3
nc 5
nop 2
dl 0
loc 22
ccs 20
cts 20
cp 1
crap 7
rs 6.9811
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\Compiler\Expression;
10
use PHPSA\Context;
11
12
class DeprecatedIniOptions extends AbstractFunctionCallAnalyzer
13
{
14
    static protected $functions = array(
15
        'ini_set' => 'ini_set',
16
        'ini_get' => 'ini_get',
17
        'ini_alter' => 'ini_alter',
18
        'ini_restore' => 'ini_restore'
19
    );
20
21
    static protected $deprecatedOptions = array(
22
        'asp_tags' => 'is a deprecated option since PHP 7.0.0',
23
        'always_populate_raw_post_data' => 'is a deprecated option since PHP 7.0.0',
24
        //
25
        'iconv.input_encoding' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead',
26
        'iconv.output_encoding' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead',
27
        'iconv.internal_encoding' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead',
28
        'mbstring.http_input' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead',
29
        'mbstring.http_output' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead',
30
        'mbstring.internal_encoding' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead',
31
        //
32
        'xsl.security_prefs' => 'is a deprecated option since PHP 5.4.0 (removed in PHP 7.0.0). Use XsltProcessor->setSecurityPrefs() instead',
33
        //
34
        'allow_call_time_pass_reference' => 'is a deprecated option since PHP 5.4.0',
35
        'highlight.bg' => 'is a deprecated option since PHP 5.4.0',
36
        'zend.ze1_compatibility_mode' => 'is a deprecated option since PHP 5.4.0',
37
        'session.bug_compat_42' => 'is a deprecated option since PHP 5.4.0',
38
        'session.bug_compat_warn' => 'is a deprecated option since PHP 5.4.0',
39
        'y2k_compliance' => 'is a deprecated option since PHP 5.4.0',
40
        //
41
        'define_syslog_variables' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
42
        'magic_quotes_gpc' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
43
        'magic_quotes_runtime' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
44
        'magic_quotes_sybase' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
45
        'register_globals' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
46
        'register_long_arrays' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
47
        'safe_mode' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
48
        'safe_mode_gid' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
49
        'safe_mode_include_dir' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
50
        'safe_mode_exec_dir' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
51
        'safe_mode_allowed_env_vars' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)',
52
        'safe_mode_protected_env_vars' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)'
53
    );
54
55 9
    public function pass(FuncCall $funcCall, Context $context)
56
    {
57 9
        $functionName = $this->resolveFunctionName($funcCall, $context);
58 9
        if ($functionName && isset(self::$functions[$functionName])) {
59 1
            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...
60 1
                $compiledOptionName = $context->getExpressionCompiler()->compile($funcCall->args[0]);
61 1
                if ($compiledOptionName->isString() && $compiledOptionName->isCorrectValue()) {
62 1
                    if (isset(self::$deprecatedOptions[$compiledOptionName->getValue()])) {
63 1
                        $context->notice(
64 1
                            'deprecated.option',
65 1
                            sprintf(
66 1
                                'Ini option %s %s.',
67 1
                                $compiledOptionName->getValue(),
68 1
                                self::$deprecatedOptions[$compiledOptionName->getValue()]
69 1
                            ),
70
                            $funcCall
71 1
                        );
72 1
                    }
73 1
                }
74 1
            }
75 1
        }
76 9
    }
77
}
78