Completed
Pull Request — final (#419)
by Georges
04:26 queued 02:13
created

SyntaxChecker.test.php ➔ read_dir()   C

Complexity

Conditions 9
Paths 7

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 16
nc 7
nop 2
dl 0
loc 24
rs 5.3563
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author Khoa Bui (khoaofgod)  <[email protected]> http://www.phpfastcache.com
5
 * @author Georges.L (Geolim4)  <[email protected]>
6
 */
7
8
function read_dir($dir, $ext = null)
9
{
10
    $list = [];
11
    $dir .= '/';
12
    if (($res = opendir($dir)) === false) {
13
        exit(1);
14
    }
15
    while (($name = readdir($res)) !== false) {
16
        if ($name == '.' || $name == '..') {
17
            continue;
18
        }
19
        $name = $dir . $name;
20
        if (is_dir($name)) {
21
            $list = array_merge($list, read_dir($name, $ext));
22
        } elseif (is_file($name)) {
23
            if (!is_null($ext) && substr(strrchr($name, '.'), 1) != $ext) {
24
                continue;
25
            }
26
            $list[] = $name;
27
        }
28
    }
29
30
    return $list;
31
}
32
33
$list = read_dir(__DIR__ . '/../', 'php');
34
$list += read_dir(__DIR__ . '/../', 'tpl');
35
36
$exit = 0;
37
foreach ($list as $file) {
38
    $output = '';
39
    /**
40
     * @todo Make the exclusions much cleaner
41
     */
42
    if (strpos($file, '/vendor/composer') === false && strpos($file, '/bin/stubs') === false) {
43
        exec('php -l "' . $file . '"', $output, $status);
44
    } else {
45
        echo '[SKIP] ' . $file;
46
        echo "\n";
47
        continue;
48
    }
49
50
    if ($status !== 0) {
51
        $exit = $status;
52
        echo '[FAIL]';
53
    } else {
54
        echo '[PASS]';
55
    }
56
    echo ' ' . implode("\n", $output);
57
    echo "\n";
58
}
59
exit($exit);