Passed
Push — php-di ( 14dc40...53e65d )
by Arnaud
21:01 queued 17:21
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
declare(strict_types=1);
4
5
namespace Cecil\Renderer\Twig;
6
7
use Cecil\Builder;
8
use Cecil\Config;
9
use Cecil\Renderer\Twig;
10
use Psr\Log\LoggerInterface;
11
12
/**
13
 * Factory to create and configure the Twig Renderer.
14
 *
15
 * This factory allows creating the renderer with all its dependencies
16
 * in a lazy manner (only when needed).
17
 */
18
class TwigFactory
19
{
20
    private Config $config;
21
    private LoggerInterface $logger;
22
    private Builder $builder;
23
24 1
    public function __construct(
25
        Config $config,
26
        LoggerInterface $logger,
27
        Builder $builder
28
    ) {
29 1
        $this->config = $config;
30 1
        $this->logger = $logger;
31 1
        $this->builder = $builder;
32
    }
33
34
    /**
35
     * Creates a Twig renderer instance.
36
     *
37
     * @param string|array|null $templatesPath Template path(s) (uses default config if null)
38
     * @return Twig Configured renderer instance
39
     */
40 1
    public function create(string|array|null $templatesPath = null): Twig
41
    {
42 1
        if ($templatesPath === null) {
43
            $templatesPath = $this->config->getLayoutsPath();
44
        }
45
46 1
        return new Twig($this->builder, $templatesPath);
47
    }
48
}
49