PlatesRendererAdapter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Frostaly\Template\Adapters;
6
7
use Frostaly\Template\Contracts\RendererAdapterInterface;
8
use League\Plates\Engine;
9
10
class PlatesRendererAdapter implements RendererAdapterInterface
11
{
12
    protected Engine $engine;
13
14 3
    public function __construct(
15
        protected string $viewPath,
16
    ) {}
17
18
    /**
19
     * {@inheritdoc}
20
     */
21 1
    public function exists(string $name): bool
22
    {
23 1
        return $this->getEngine()->exists($name);
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 2
    public function render(string $name, array $params = []): string
30
    {
31 2
        return $this->getEngine()->render($name, $params);
32
    }
33
34
    /**
35
     * Get the Plates template Engine.
36
     */
37 3
    protected function getEngine(): Engine
38
    {
39 3
        return $this->engine ??= $this->createEngine();
40
    }
41
42
    /**
43
     * Create the Plates template Engine.
44
     */
45 3
    protected function createEngine(): Engine
46
    {
47 3
        $engine = new Engine($this->viewPath);
48 3
        return $engine->setFileExtension(null);
49
    }
50
}
51