|
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
|
|
|
use PHPSA\Analyzer\Pass\Metadata; |
|
11
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
12
|
|
|
|
|
13
|
|
|
class DeprecatedIniOptions extends AbstractFunctionCallAnalyzer |
|
14
|
|
|
{ |
|
15
|
|
|
const DESCRIPTION = 'Checks for use of deprecated php.ini options and gives alternatives if available.'; |
|
16
|
|
|
|
|
17
|
|
|
protected $functions = [ |
|
18
|
|
|
'ini_set' => 'ini_set', |
|
19
|
|
|
'ini_get' => 'ini_get', |
|
20
|
|
|
'ini_alter' => 'ini_alter', |
|
21
|
|
|
'ini_restore' => 'ini_restore' |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Contains the ini options that are checked |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $deprecatedOptions = []; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param array $config The config values for the analyzer |
|
31
|
|
|
*/ |
|
32
|
1 |
|
public function __construct(array $config) |
|
33
|
|
|
{ |
|
34
|
1 |
|
if ($config["check_5_3"] == true) { |
|
35
|
|
|
$check53 = [ |
|
36
|
1 |
|
'define_syslog_variables' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)', |
|
37
|
1 |
|
'magic_quotes_gpc' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)', |
|
38
|
1 |
|
'magic_quotes_runtime' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)', |
|
39
|
1 |
|
'magic_quotes_sybase' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)', |
|
40
|
1 |
|
'register_globals' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)', |
|
41
|
1 |
|
'register_long_arrays' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)', |
|
42
|
1 |
|
'safe_mode' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)', |
|
43
|
1 |
|
'safe_mode_gid' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)', |
|
44
|
1 |
|
'safe_mode_include_dir' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)', |
|
45
|
1 |
|
'safe_mode_exec_dir' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)', |
|
46
|
1 |
|
'safe_mode_allowed_env_vars' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)', |
|
47
|
|
|
'safe_mode_protected_env_vars' => 'is a deprecated option since PHP 5.3.0 (removed in PHP 5.4.0)' |
|
48
|
1 |
|
]; |
|
49
|
1 |
|
$this->deprecatedOptions = array_merge($this->deprecatedOptions, $check53); |
|
50
|
1 |
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
if ($config["check_5_4"] == true) { |
|
53
|
|
|
$check54 = [ |
|
54
|
1 |
|
'allow_call_time_pass_reference' => 'is a deprecated option since PHP 5.4.0', |
|
55
|
1 |
|
'highlight.bg' => 'is a deprecated option since PHP 5.4.0', |
|
56
|
1 |
|
'zend.ze1_compatibility_mode' => 'is a deprecated option since PHP 5.4.0', |
|
57
|
1 |
|
'session.bug_compat_42' => 'is a deprecated option since PHP 5.4.0', |
|
58
|
1 |
|
'session.bug_compat_warn' => 'is a deprecated option since PHP 5.4.0', |
|
59
|
1 |
|
'y2k_compliance' => 'is a deprecated option since PHP 5.4.0', |
|
60
|
1 |
|
'xsl.security_prefs' => 'is a deprecated option since PHP 5.4.0 (removed in PHP 7.0.0). Use XsltProcessor->setSecurityPrefs() instead', |
|
61
|
1 |
|
]; |
|
62
|
1 |
|
$this->deprecatedOptions = array_merge($this->deprecatedOptions, $check54); |
|
63
|
1 |
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
if ($config["check_5_6"] == true) { |
|
66
|
|
|
$check56 = [ |
|
67
|
1 |
|
'iconv.input_encoding' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead', |
|
68
|
1 |
|
'iconv.output_encoding' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead', |
|
69
|
1 |
|
'iconv.internal_encoding' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead', |
|
70
|
1 |
|
'mbstring.http_input' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead', |
|
71
|
1 |
|
'mbstring.http_output' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead', |
|
72
|
1 |
|
'mbstring.internal_encoding' => 'is a deprecated option since PHP 5.6.0. Use \'default_charset\' instead', |
|
73
|
1 |
|
]; |
|
74
|
1 |
|
$this->deprecatedOptions = array_merge($this->deprecatedOptions, $check56); |
|
75
|
1 |
|
} |
|
76
|
|
|
|
|
77
|
1 |
|
if ($config["check_7_0"] == true) { |
|
78
|
|
|
$check70 = [ |
|
79
|
1 |
|
'asp_tags' => 'is a deprecated option since PHP 7.0.0', |
|
80
|
1 |
|
'always_populate_raw_post_data' => 'is a deprecated option since PHP 7.0.0', |
|
81
|
1 |
|
]; |
|
82
|
1 |
|
$this->deprecatedOptions = array_merge($this->deprecatedOptions, $check70); |
|
83
|
1 |
|
} |
|
84
|
1 |
|
} |
|
85
|
|
|
|
|
86
|
4 |
|
public function pass(FuncCall $funcCall, Context $context) |
|
87
|
|
|
{ |
|
88
|
4 |
|
$functionName = $this->resolveFunctionName($funcCall, $context); |
|
89
|
4 |
|
if ($functionName && isset($this->functions[$functionName])) { |
|
90
|
1 |
|
if ($funcCall->args) { |
|
|
|
|
|
|
91
|
1 |
|
$compiledOptionName = $context->getExpressionCompiler()->compile($funcCall->args[0]); |
|
92
|
1 |
|
if ($compiledOptionName->isString() && $compiledOptionName->isCorrectValue()) { |
|
93
|
1 |
|
if (isset($this->deprecatedOptions[$compiledOptionName->getValue()])) { |
|
94
|
1 |
|
$context->notice( |
|
95
|
1 |
|
'deprecated.option', |
|
96
|
1 |
|
sprintf( |
|
97
|
1 |
|
'Ini option %s %s.', |
|
98
|
1 |
|
$compiledOptionName->getValue(), |
|
99
|
1 |
|
$this->deprecatedOptions[$compiledOptionName->getValue()] |
|
100
|
1 |
|
), |
|
101
|
|
|
$funcCall |
|
102
|
1 |
|
); |
|
103
|
1 |
|
} |
|
104
|
1 |
|
} |
|
105
|
1 |
|
} |
|
106
|
1 |
|
} |
|
107
|
4 |
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return Metadata |
|
111
|
|
|
*/ |
|
112
|
43 |
|
public static function getMetadata() |
|
113
|
|
|
{ |
|
114
|
43 |
|
$treebuilder = new TreeBuilder(); |
|
115
|
43 |
|
$config = $treebuilder->root("deprecated_ini_options") |
|
|
|
|
|
|
116
|
43 |
|
->info(self::DESCRIPTION) |
|
117
|
43 |
|
->canBeDisabled() |
|
118
|
43 |
|
->children() |
|
119
|
43 |
|
->booleanNode("check_5_3")->defaultTrue()->end() |
|
120
|
43 |
|
->booleanNode("check_5_4")->defaultTrue()->end() |
|
121
|
43 |
|
->booleanNode("check_5_6")->defaultTrue()->end() |
|
122
|
43 |
|
->booleanNode("check_7_0")->defaultTrue()->end() |
|
123
|
43 |
|
->end(); |
|
124
|
|
|
|
|
125
|
43 |
|
return new Metadata("deprecated_ini_options", $config, self::DESCRIPTION); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
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.