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