Passed
Push — develop ( ec1e42...80559e )
by Brent
03:22
created

MarkdownVariable::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Stitcher\Variable;
4
5
use Parsedown;
6
use Stitcher\Exception\InvalidConfiguration;
7
use Stitcher\File;
8
9
class MarkdownVariable extends AbstractVariable
10
{
11
    private $parser;
12
13 4
    public function __construct(string $unparsed, Parsedown $parser)
14
    {
15 4
        parent::__construct($unparsed);
16
17 4
        $this->parser = $parser;
18 4
    }
19
20 4
    public static function make(string $value, Parsedown $parser): MarkdownVariable
21
    {
22 4
        return new self($value, $parser);
23
    }
24
25 3
    public function parse(): AbstractVariable
26
    {
27 3
        $contents = File::read($this->unparsed);
28
29 3
        if (! $contents) {
30
            throw InvalidConfiguration::fileNotFound($this->unparsed);
31
        }
32
33 3
        $this->parsed = $this->parser->parse($contents);
34
35 3
        return $this;
36
    }
37
}
38