Completed
Push — V6 ( b362d7...e9a4a9 )
by Georges
02:18
created

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