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

MarkdownVariable::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 12
ccs 0
cts 6
cp 0
crap 6
rs 9.8666
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