1
|
|
|
<?php |
2
|
|
|
namespace CodeReview; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Simple configuration container handling basic options parsing nad providing convenient methods. |
6
|
|
|
* |
7
|
|
|
* @property string|null $subPath |
8
|
|
|
* @property string $maxVersion |
9
|
|
|
* @property bool $includeDisabledPlugins |
10
|
|
|
* @property bool $findDeprecatedFunctions |
11
|
|
|
* @property bool $findPrivateFunctions |
12
|
|
|
* @property bool $fixProblems |
13
|
|
|
*/ |
14
|
|
|
class Config { |
15
|
|
|
|
16
|
|
|
const T_PLUGINS_ALL = 0; |
17
|
|
|
const T_PLUGINS_ACTIVE = 1; |
18
|
|
|
const T_PLUGINS_INACTIVE = 2; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $options = array(); |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var null|function |
27
|
|
|
*/ |
28
|
|
|
protected $versionGetter = null; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param array $options |
32
|
|
|
*/ |
33
|
8 |
|
public function __construct(array $options = array(), $versionGetter = null) { |
34
|
8 |
|
$this->options = (array)$options; |
35
|
8 |
|
if (is_callable($versionGetter)) { |
36
|
5 |
|
$this->versionGetter = $versionGetter; |
|
|
|
|
37
|
5 |
|
} else { |
38
|
|
|
//TODO possibly further decouple Elgg core dependency |
39
|
3 |
|
$this->versionGetter = 'elgg_get_version'; |
|
|
|
|
40
|
|
|
} |
41
|
8 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param $key |
45
|
|
|
* @return mixed |
46
|
|
|
*/ |
47
|
5 |
|
public function __get($key) { |
48
|
5 |
|
return isset($this->options[$key]) ? $this->options[$key] : null; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param $key |
53
|
|
|
* @param null $default |
54
|
|
|
* @return null |
55
|
|
|
*/ |
56
|
7 |
|
public function getOption($key, $default = null) { |
57
|
7 |
|
return isset($this->options[$key]) ? $this->options[$key] : $default; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param $key |
62
|
|
|
* @param $value |
63
|
|
|
*/ |
64
|
4 |
|
public function __set($key, $value) { |
65
|
4 |
|
$this->options[$key] = $value; |
66
|
4 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param $type |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
1 |
|
public function getPluginIds($type) { |
73
|
1 |
|
$pluginsDirs = false; |
74
|
|
|
|
75
|
1 |
|
$config = \code_review::getConfig(); |
76
|
|
|
|
77
|
|
|
switch ($type) { |
78
|
1 |
|
case self::T_PLUGINS_INACTIVE: |
79
|
1 |
|
$pluginsDirs = $this->getPluginIds(self::T_PLUGINS_ALL); |
80
|
1 |
|
$actives = call_user_func($config['plugins_getter'], 'active'); |
81
|
1 |
|
foreach ($actives as $plugin) { |
82
|
1 |
|
if ($plugin instanceof \ElggPlugin) { |
|
|
|
|
83
|
|
|
$pluginsDirs = array_diff($pluginsDirs, array($plugin->getID())); |
84
|
|
|
} else { |
85
|
1 |
|
$pluginsDirs = array_diff($pluginsDirs, array($plugin)); |
86
|
|
|
} |
87
|
1 |
|
} |
88
|
1 |
|
break; |
89
|
1 |
|
case self::T_PLUGINS_ACTIVE: |
90
|
|
|
$pluginsDirs = call_user_func($config['plugins_getter'], 'active'); |
91
|
|
|
foreach ($pluginsDirs as $key => $plugin) { |
92
|
|
|
if ($plugin instanceof \ElggPlugin) { |
93
|
|
|
$pluginsDirs[$key] = $plugin->getID(); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
break; |
97
|
1 |
|
case self::T_PLUGINS_ALL: |
98
|
1 |
|
$pluginsDirs = \code_review::getPluginDirsInDir($config['pluginspath']); |
99
|
1 |
|
break; |
100
|
|
|
|
101
|
|
|
} |
102
|
1 |
|
return $pluginsDirs; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/* |
106
|
|
|
* Shorthand methods |
107
|
|
|
*/ |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param $key |
111
|
|
|
* @param array $array |
112
|
|
|
* @param null $default |
113
|
|
|
* @param bool $strict |
114
|
|
|
* @return null |
115
|
|
|
* |
116
|
|
|
* Function is a part of Elgg framework with following license: |
117
|
|
|
|
118
|
|
|
Copyright (c) 2013. See COPYRIGHT.txt |
119
|
|
|
http://elgg.org/ |
120
|
|
|
|
121
|
|
|
Permission is hereby granted, free of charge, to any person obtaining |
122
|
|
|
a copy of this software and associated documentation files (the |
123
|
|
|
"Software"), to deal in the Software without restriction, including |
124
|
|
|
without limitation the rights to use, copy, modify, merge, publish, |
125
|
|
|
distribute, sublicense, and/or sell copies of the Software, and to |
126
|
|
|
permit persons to whom the Software is furnished to do so, subject to |
127
|
|
|
the following conditions: |
128
|
|
|
|
129
|
|
|
The above copyright notice and this permission notice shall be |
130
|
|
|
included in all copies or substantial portions of the Software. |
131
|
|
|
|
132
|
|
|
Except as contained in this notice, the name(s) of the above copyright |
133
|
|
|
holders shall not be used in advertising or otherwise to promote the |
134
|
|
|
sale, use or other dealings in this Software without prior written |
135
|
|
|
authorization. |
136
|
|
|
|
137
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
138
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
139
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
140
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
141
|
|
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
142
|
|
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
143
|
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
144
|
|
|
*/ |
145
|
4 |
|
private function elggExtract($key, array $array, $default = null, $strict = true) { |
146
|
4 |
|
if (!is_array($array)) { |
147
|
|
|
return $default; |
148
|
|
|
} |
149
|
|
|
|
150
|
4 |
|
if ($strict) { |
151
|
4 |
|
return (isset($array[$key])) ? $array[$key] : $default; |
152
|
|
|
} else { |
153
|
|
|
return (isset($array[$key]) && !empty($array[$key])) ? $array[$key] : $default; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param array $vars |
159
|
|
|
*/ |
160
|
4 |
|
public function parseInput(array $vars) { |
161
|
|
|
|
162
|
|
|
//sanitize provided path |
163
|
4 |
|
$subPath = $this->elggExtract('subpath', $vars, '/'); |
|
|
|
|
164
|
4 |
|
$subPath = trim($subPath, '/\\'); |
165
|
4 |
|
$subPath = str_replace('\\', '/', $subPath); |
166
|
4 |
|
$subPath = str_replace('..', '', $subPath); |
167
|
4 |
|
$subPath = $subPath . '/'; |
168
|
|
|
|
169
|
4 |
|
$this->subPath = $subPath; |
170
|
4 |
|
$this->maxVersion = $this->elggExtract('version', $vars, ''); |
|
|
|
|
171
|
4 |
|
$this->includeDisabledPlugins = $this->elggExtract('include_disabled_plugins', $vars, false); |
|
|
|
|
172
|
4 |
|
$this->findDeprecatedFunctions = $this->elggExtract('find_deprecated_functions', $vars, true); |
|
|
|
|
173
|
4 |
|
$this->findPrivateFunctions = $this->elggExtract('find_private_functions', $vars, true); |
|
|
|
|
174
|
4 |
|
$this->fixProblems = $this->elggExtract('fix_problems', $vars, false); |
|
|
|
|
175
|
4 |
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return bool |
179
|
|
|
*/ |
180
|
5 |
|
public function isFixProblemsEnabled() { |
181
|
5 |
|
return (bool)$this->getOption('fixProblems', false); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return string |
186
|
|
|
*/ |
187
|
5 |
|
public function getMaxVersion() { |
188
|
5 |
|
if (!$this->maxVersion) { |
|
|
|
|
189
|
3 |
|
return call_user_func($this->versionGetter, true); |
190
|
|
|
} |
191
|
3 |
|
return $this->maxVersion; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
5 |
|
public function getSubPath() { |
198
|
5 |
|
return (string)$this->subPath; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @return bool |
203
|
|
|
*/ |
204
|
7 |
|
public function isIncludeDisabledPluginsEnabled() { |
205
|
7 |
|
return (bool)$this->getOption('includeDisabledPlugins', false); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @return bool |
210
|
|
|
*/ |
211
|
7 |
|
public function isSkipInactivePluginsEnabled() { |
212
|
7 |
|
return !$this->isIncludeDisabledPluginsEnabled(); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return bool |
217
|
|
|
*/ |
218
|
5 |
|
public function isDeprecatedFunctionsTestEnabled() { |
219
|
5 |
|
return (bool)$this->getOption('findDeprecatedFunctions', true); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @return bool |
224
|
|
|
*/ |
225
|
5 |
|
public function isPrivateFunctionsTestEnabled() { |
226
|
5 |
|
return (bool)$this->getOption('findPrivateFunctions', true); |
227
|
|
|
} |
228
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..