Directory::parse()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 11
cts 11
cp 1
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 11
nc 4
nop 1
crap 7
1
<?php
2
3
namespace ntentan\config;
4
5
class Directory
6
{
7
8
    private $path;
9
    private $contexts = [];
10
11 3
    public function __construct($path) {
12 3
        $this->path = $path;
13 3
    }
14
15 3
    public function parse($path = '') {
16 3
        $config = [];
17 3
        $dir = "$this->path/$path";
18 3
        $files = scandir($dir);
19 3
        foreach ($files as $file) {
20 3
            if (fnmatch("*.conf.php", $file)) {
21 3
                $prefix = substr($file, 0, -9);
22 3
                $config[$prefix] = File::read("$dir/$file");
23 3
            } else if (is_dir("{$this->path}/$file") && $file != '.' && $file != '..' && $path === '') {
24 3
                $this->contexts[] = $file;
25
            }
26
        }
27
28 3
        return $config;
29
    }
30
31 3
    public function getContexts() {
32 3
        return $this->contexts;
33
    }
34
35
}
36