Liquid   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 41
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A renderSource() 0 8 2
A fileName() 0 4 1
A __construct() 0 10 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Template;
5
6
use League\Flysystem\Adapter\Local;
7
use League\Flysystem\Filesystem;
8
use Liquid\Exception\ParseException;
9
use Liquid\Exception\RenderException;
10
use Liquid\Template as LiquidTemplate;
11
12
class Liquid extends Template
13
{
14
    /**
15
     * @var LiquidTemplate
16
     */
17
    private $liquid;
18
19
    /**
20
     * @param Filesystem $filesystem
21
     */
22 4
    public function __construct(Filesystem $filesystem = null)
23
    {
24 4
        parent::__construct($filesystem);
25 4
        if (!is_null($filesystem) && $filesystem->getAdapter() instanceof Local) {
26
            $path = $filesystem->getAdapter()->getPathPrefix();
27
        } else {
28 4
            $path = null;
29
        }
30 4
        $this->liquid = new LiquidTemplate($path);
31 4
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 3
    public function renderSource(string $source, array $variables): string
37
    {
38
        try {
39 3
            return $this->liquid->parse($source)->render($variables);
40 1
        } catch (ParseException|RenderException $e) {
41 1
            throw new RenderFailedException($source, $e);
42
        }
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    protected function fileName(string $templateName): string
49
    {
50 2
        return $templateName . '.liquid';
51
    }
52
}
53