Passed
Branch v2 (aaaa8e)
by Brent
03:38
created

MarkdownVariable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A make() 0 4 1
A parse() 0 12 2
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
    public function __construct(string $unparsed, Parsedown $parser)
14
    {
15
        parent::__construct($unparsed);
16
17
        $this->parser = $parser;
18
    }
19
20
    public static function make(string $value, Parsedown $parser): MarkdownVariable
21
    {
22
        return new self($value, $parser);
23
    }
24
25
    public function parse(): AbstractVariable
26
    {
27
        $contents = File::read($this->unparsed);
28
29
        if (! $contents) {
30
            throw InvalidConfiguration::fileNotFound($this->unparsed);
31
        }
32
33
        $this->parsed = $this->parser->parse($contents);
34
35
        return $this;
36
    }
37
}
38