This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | View Code Duplication | if ( ! function_exists('glob_recursive')) |
|
3 | { |
||
4 | // Does not support flag GLOB_BRACE |
||
5 | function glob_recursive($pattern, $flags = 0) |
||
6 | { |
||
7 | $files = glob($pattern, $flags); |
||
8 | |||
9 | foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) |
||
10 | { |
||
11 | $files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags)); |
||
12 | } |
||
13 | |||
14 | return $files; |
||
15 | } |
||
16 | } |
||
17 | |||
18 | /** |
||
19 | * This is project's console commands configuration for Robo task runner. |
||
20 | * |
||
21 | * @see http://robo.li/ |
||
22 | */ |
||
23 | class RoboFile extends \Robo\Tasks { |
||
24 | |||
25 | /** |
||
26 | * Directories used by analysis tools |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $taskDirs = [ |
||
31 | 'build/logs', |
||
32 | 'build/pdepend', |
||
33 | 'build/phpdox', |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * Directories to remove with the clean task |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $cleanDirs = [ |
||
42 | 'coverage', |
||
43 | 'docs', |
||
44 | 'phpdoc', |
||
45 | 'build/logs', |
||
46 | 'build/phpdox', |
||
47 | 'build/pdepend' |
||
48 | ]; |
||
49 | |||
50 | |||
51 | /** |
||
52 | * Do static analysis tasks |
||
53 | */ |
||
54 | public function analyze() |
||
55 | { |
||
56 | $this->prepare(); |
||
57 | $this->lint(); |
||
58 | $this->phploc(TRUE); |
||
59 | $this->phpcs(TRUE); |
||
60 | $this->dependencyReport(); |
||
61 | $this->phpcpdReport(); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Run all tests, generate coverage, generate docs, generate code statistics |
||
66 | */ |
||
67 | public function build() |
||
68 | { |
||
69 | $this->analyze(); |
||
70 | $this->coverage(); |
||
71 | $this->docs(); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Cleanup temporary files |
||
76 | */ |
||
77 | public function clean() |
||
78 | { |
||
79 | $cleanFiles = [ |
||
80 | 'build/humbug.json', |
||
81 | 'build/humbug-log.txt', |
||
82 | ]; |
||
83 | array_map(function ($file) { |
||
84 | @unlink($file); |
||
0 ignored issues
–
show
|
|||
85 | }, $cleanFiles); |
||
86 | |||
87 | // So the task doesn't complain, |
||
88 | // make any 'missing' dirs to cleanup |
||
89 | array_map(function ($dir) { |
||
90 | if ( ! is_dir($dir)) |
||
91 | { |
||
92 | `mkdir -p {$dir}`; |
||
93 | } |
||
94 | }, $this->cleanDirs); |
||
95 | |||
96 | $this->_cleanDir($this->cleanDirs); |
||
97 | $this->_deleteDir($this->cleanDirs); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Run unit tests and generate coverage reports |
||
102 | */ |
||
103 | public function coverage() |
||
104 | { |
||
105 | $this->taskPhpUnit() |
||
106 | ->configFile('build/phpunit.xml') |
||
107 | ->printed(true) |
||
108 | ->run(); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Generate documentation with phpdox |
||
113 | */ |
||
114 | public function docs() |
||
115 | { |
||
116 | $cmd_parts = [ |
||
117 | 'cd build', |
||
118 | '../vendor/bin/phpdox', |
||
119 | 'cd ..' |
||
120 | ]; |
||
121 | $this->_run($cmd_parts, ' && '); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Verify that source files are valid |
||
126 | */ |
||
127 | public function lint() |
||
128 | { |
||
129 | $files = $this->getAllSourceFiles(); |
||
130 | |||
131 | $chunks = array_chunk($files, 6); |
||
132 | |||
133 | foreach($chunks as $chunk) |
||
134 | { |
||
135 | $this->parallelLint($chunk); |
||
136 | } |
||
137 | } |
||
138 | |||
139 | |||
140 | /** |
||
141 | * Run mutation tests with humbug |
||
142 | * |
||
143 | * @param bool $stats - if true, generates stats rather than running mutation tests |
||
144 | */ |
||
145 | public function mutate($stats = FALSE) |
||
146 | { |
||
147 | $test_parts = [ |
||
148 | 'vendor/bin/humbug' |
||
149 | ]; |
||
150 | |||
151 | $stat_parts = [ |
||
152 | 'vendor/bin/humbug', |
||
153 | '--skip-killed=yes', |
||
154 | '-v', |
||
155 | './build/humbug.json' |
||
156 | ]; |
||
157 | |||
158 | $cmd_parts = ($stats) ? $stat_parts : $test_parts; |
||
159 | $this->_run($cmd_parts); |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * Run the phpcs tool |
||
164 | * |
||
165 | * @param bool $report - if true, generates reports instead of direct output |
||
166 | */ |
||
167 | public function phpcs($report = FALSE) |
||
168 | { |
||
169 | $report_cmd_parts = [ |
||
170 | 'vendor/bin/phpcs', |
||
171 | '--standard=./build/phpcs.xml', |
||
172 | '--report-checkstyle=./build/logs/phpcs.xml', |
||
173 | ]; |
||
174 | |||
175 | $normal_cmd_parts = [ |
||
176 | 'vendor/bin/phpcs', |
||
177 | '--standard=./build/phpcs.xml', |
||
178 | ]; |
||
179 | |||
180 | $cmd_parts = ($report) ? $report_cmd_parts : $normal_cmd_parts; |
||
181 | |||
182 | $this->_run($cmd_parts); |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * Run the phploc tool |
||
187 | * |
||
188 | * @param bool $report - if true, generates reports instead of direct output |
||
189 | */ |
||
190 | public function phploc($report = FALSE) |
||
191 | { |
||
192 | // Command for generating reports |
||
193 | $report_cmd_parts = [ |
||
194 | 'vendor/bin/phploc', |
||
195 | '--count-tests', |
||
196 | '--log-csv=build/logs/phploc.csv', |
||
197 | '--log-xml=build/logs/phploc.xml', |
||
198 | 'src', |
||
199 | 'tests' |
||
200 | ]; |
||
201 | |||
202 | // Command for generating direct output |
||
203 | $normal_cmd_parts = [ |
||
204 | 'vendor/bin/phploc', |
||
205 | '--count-tests', |
||
206 | 'src', |
||
207 | 'tests' |
||
208 | ]; |
||
209 | |||
210 | $cmd_parts = ($report) ? $report_cmd_parts : $normal_cmd_parts; |
||
211 | |||
212 | $this->_run($cmd_parts); |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * Create temporary directories |
||
217 | */ |
||
218 | public function prepare() |
||
219 | { |
||
220 | array_map([$this, '_mkdir'], $this->taskDirs); |
||
221 | } |
||
222 | |||
223 | /** |
||
224 | * Lint php files and run unit tests |
||
225 | */ |
||
226 | public function test() |
||
227 | { |
||
228 | $this->lint(); |
||
229 | $this->taskPHPUnit() |
||
230 | ->configFile('phpunit.xml') |
||
231 | ->printed(true) |
||
232 | ->run(); |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * Watches for file updates, and automatically runs appropriate actions |
||
237 | */ |
||
238 | public function watch() |
||
239 | { |
||
240 | $this->taskWatch() |
||
241 | ->monitor('composer.json', function() { |
||
242 | $this->taskComposerUpdate()->run(); |
||
243 | }) |
||
244 | ->monitor('src', function () { |
||
245 | $this->taskExec('test')->run(); |
||
246 | }) |
||
247 | ->monitor('tests', function () { |
||
248 | $this->taskExec('test')->run(); |
||
249 | }) |
||
250 | ->run(); |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * Create pdepend reports |
||
255 | */ |
||
256 | protected function dependencyReport() |
||
257 | { |
||
258 | $cmd_parts = [ |
||
259 | 'vendor/bin/pdepend', |
||
260 | '--jdepend-xml=build/logs/jdepend.xml', |
||
261 | '--jdepend-chart=build/pdepend/dependencies.svg', |
||
262 | '--overview-pyramid=build/pdepend/overview-pyramid.svg', |
||
263 | 'src' |
||
264 | ]; |
||
265 | $this->_run($cmd_parts); |
||
266 | } |
||
267 | |||
268 | /** |
||
269 | * Get the total list of source files, including tests |
||
270 | * |
||
271 | * @return array |
||
272 | */ |
||
273 | protected function getAllSourceFiles() |
||
274 | { |
||
275 | $files = array_merge( |
||
276 | glob_recursive('build/*.php'), |
||
277 | glob_recursive('src/*.php'), |
||
278 | glob_recursive('tests/*.php'), |
||
279 | glob('*.php') |
||
280 | ); |
||
281 | |||
282 | sort($files); |
||
283 | |||
284 | return $files; |
||
285 | } |
||
286 | |||
287 | /** |
||
288 | * Run php's linter in one parallel task for the passed chunk |
||
289 | * |
||
290 | * @param array $chunk |
||
291 | */ |
||
292 | protected function parallelLint(array $chunk) |
||
293 | { |
||
294 | $task = $this->taskParallelExec() |
||
295 | ->timeout(5) |
||
296 | ->printed(FALSE); |
||
297 | |||
298 | foreach($chunk as $file) |
||
299 | { |
||
300 | $task = $task->process("php -l {$file}"); |
||
301 | } |
||
302 | |||
303 | $task->run(); |
||
304 | } |
||
305 | |||
306 | /** |
||
307 | * Generate copy paste detector report |
||
308 | */ |
||
309 | protected function phpcpdReport() |
||
310 | { |
||
311 | $cmd_parts = [ |
||
312 | 'vendor/bin/phpcpd', |
||
313 | '--log-pmd build/logs/pmd-cpd.xml', |
||
314 | 'src' |
||
315 | ]; |
||
316 | $this->_run($cmd_parts); |
||
317 | } |
||
318 | |||
319 | /** |
||
320 | * Shortcut for joining an array of command arguments |
||
321 | * and then running it |
||
322 | * |
||
323 | * @param array $cmd_parts - command arguments |
||
324 | * @param string $join_on - what to join the command arguments with |
||
325 | */ |
||
326 | protected function _run(array $cmd_parts, $join_on = ' ') |
||
327 | { |
||
328 | $this->taskExec(implode($join_on, $cmd_parts))->run(); |
||
329 | } |
||
330 | } |
If you suppress an error, we recommend checking for the error condition explicitly: