Test Failed
Push — develop ( 0d79d2...755cd9 )
by Brent
12:23
created

DirectoryVariable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A parse() 0 23 2
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