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

MarkdownVariable::__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 Pageon\Lib\Markdown\MarkdownParser;
6
use Stitcher\Exception\InvalidConfiguration;
7
use Stitcher\File;
8
9
class MarkdownVariable extends AbstractVariable
10
{
11
    private $parser;
12
13
    public function __construct(string $unparsed, MarkdownParser $parser)
14
    {
15
        parent::__construct($unparsed);
16
17
        $this->parser = $parser;
18
    }
19
20
    public static function make(
21
        string $value,
22
        MarkdownParser $parser
23
    ): MarkdownVariable {
24
        return new self($value, $parser);
25
    }
26
27
    public function parse(): AbstractVariable
28
    {
29
        $contents = File::read($this->unparsed);
30
31
        if (! $contents) {
32
            throw InvalidConfiguration::fileNotFound($this->unparsed);
33
        }
34
35
        $this->parsed = $this->parser->parse($contents);
36
37
        return $this;
38
    }
39
}
40