Test Failed
Push — master ( 22b809...326de4 )
by Brent
05:15 queued 39s
created

DirectoryVariable::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Stitcher\Variable;
4
5
use Stitcher\File;
6
7
class DirectoryVariable extends AbstractVariable
8
{
9
    /** @var \Stitcher\Variable\VariableParser */
10
    private $parser;
11
12
    public function __construct(string $path, VariableParser $parser)
13
    {
14
        parent::__construct($path);
15
16
        $this->parser = $parser;
17
    }
18
19
    public function parse(): AbstractVariable
20
    {
21
        $path = File::path($this->unparsed);
22
23
        $files = @scandir($path) ?: [];
24
25
        unset($files[0], $files[1]);
26
27
        $this->parsed = [];
28
29
        foreach ($files as $file) {
30
            $id = pathinfo($file, PATHINFO_FILENAME);
31
32
            $filePath = $path . $file;
33
34
            $this->parsed[$id] = [
35
                'id' => $id,
36
                'content' => $this->parser->parse($filePath),
37
            ];
38
        }
39
40
        return $this;
41
    }
42
}
43