Completed
Branch final (ad8b8d)
by Georges
03:08 queued 28s
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 1
Bugs 0 Features 1
Metric Value
cc 9
eloc 16
c 1
b 0
f 1
nc 7
nop 2
dl 0
loc 24
rs 5.3563
1
<?php
2
3
/**
4
 * @author Khoa Bui (khoaofgod)  <[email protected]> http://www.phpfastcache.com
5
 * @author Georges.L (Geolim4)  <[email protected]>
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 && strpos($file, '/bin/stubs') === false) {
42
        exec('php -lf "' . $file . '"', $output, $status);
43
    } else {
44
        echo '[SKIP] ' . $file;
45
        echo "\n";
46
        continue;
47
    }
48
49
    if ($status != 0) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $status of type integer|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
50
        $exit = $status;
51
        echo '[FAIL]';
52
    } else {
53
        echo '[PASS]';
54
    }
55
    echo ' ' . implode("\n", $output);
56
    echo "\n";
57
}
58
exit($exit);