Passed
Push — master ( b500c8...f1f1b3 )
by Hirofumi
05:29
created

Liquid::fileName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Template;
5
6
use League\Flysystem\Filesystem;
7
use Liquid\Exception\ParseException;
8
use Liquid\Exception\RenderException;
9
use Liquid\Template as LiquidTemplate;
10
11
class Liquid extends Template
12
{
13
    /**
14
     * @var LiquidTemplate
15
     */
16
    private $liquid;
17
18
    /**
19
     * @param Filesystem $filesystem
20
     */
21 4
    public function __construct(Filesystem $filesystem)
22
    {
23 4
        parent::__construct($filesystem);
24 4
        $this->liquid = new LiquidTemplate;
25 4
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 3
    public function renderSource(string $source, array $variables): string
31
    {
32
        try {
33 3
            return $this->liquid->parse($source)->render($variables);
34 1
        } catch (ParseException|RenderException $e) {
35 1
            throw new RenderFailedException($source, $e);
36
        }
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 2
    protected function fileName(string $templateName): string
43
    {
44 2
        return $templateName . '.liquid';
45
    }
46
}
47