Completed
Push — master ( 9b25f2...d42705 )
by Tomáš
09:42 queued 07:08
created

LatteDecorator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 38
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A decorateFile() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\PHP7_Sculpin\Renderable\Latte;
11
12
use Latte\Engine;
13
use Symplify\PHP7_Sculpin\Contract\Renderable\DecoratorInterface;
14
use Symplify\PHP7_Sculpin\Configuration\Configuration;
15
use Symplify\PHP7_Sculpin\Renderable\File\File;
16
17
final class LatteDecorator implements DecoratorInterface
18
{
19
    /**
20
     * @var Configuration
21
     */
22
    private $configuration;
23
24
    /**
25
     * @var Engine
26
     */
27
    private $latteEngine;
28
29 2
    public function __construct(
30
        Configuration $configuration,
31
        Engine $latteEngine
32
    ) {
33 2
        $this->configuration = $configuration;
34 2
        $this->latteEngine = $latteEngine;
35 2
    }
36
37 2
    public function decorateFile(File $file)
38
    {
39 2
        $options = $this->configuration->getOptions();
40
41
        $parameters = [
42 2
            'site' => $options,
43 2
            'page' => $file->getConfiguration(),
44
            'posts' => $options['posts'] ?? [],
45
        ];
46
47
        /** @var DynamicStringLoader $dynamicStringLoader */
48 2
        $dynamicStringLoader = $this->latteEngine->getLoader();
49 2
        $dynamicStringLoader->addTemplate($file->getBaseName(), $file->getContent());
50
51 2
        $htmlContent = $this->latteEngine->renderToString($file->getBaseName(), $parameters);
52 2
        $file->changeContent($htmlContent);
53 2
    }
54
}
55