Passed
Pull Request — master (#2285)
by Arnaud
10:02 queued 03:47
created

TwigFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of Cecil.
5
 *
6
 * (c) Arnaud Ligny <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cecil\Renderer\Twig;
15
16
use Cecil\Builder;
17
use Cecil\Config;
18
use Cecil\Renderer\Twig;
19
use Psr\Log\LoggerInterface;
20
21
/**
22
 * Factory to create and configure the Twig Renderer.
23
 *
24
 * This factory allows creating the renderer with all its dependencies
25
 * in a lazy manner (only when needed).
26
 */
27
class TwigFactory
28
{
29
    private Config $config;
30
    private LoggerInterface $logger;
31
    private Builder $builder;
32
33 1
    public function __construct(
34
        Config $config,
35
        LoggerInterface $logger,
36
        Builder $builder
37
    ) {
38 1
        $this->config = $config;
39 1
        $this->logger = $logger;
40 1
        $this->builder = $builder;
41
    }
42
43
    /**
44
     * Creates a Twig renderer instance.
45
     *
46
     * @param string|array|null $templatesPath Template path(s) (uses default config if null)
47
     * @return Twig Configured renderer instance
48
     */
49 1
    public function create(string|array|null $templatesPath = null): Twig
50
    {
51 1
        if ($templatesPath === null) {
52
            $templatesPath = $this->config->getLayoutsPath();
53
        }
54
55 1
        return new Twig($this->builder, $templatesPath);
56
    }
57
}
58