Passed
Push — analysis-A7yJ5k ( c97a2e )
by Arnaud
10:56 queued 05:11
created

TwigFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
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
    public function __construct(
25
        Config $config,
26
        LoggerInterface $logger,
27
        Builder $builder
28
    ) {
29
        $this->config = $config;
30
        $this->logger = $logger;
31
        $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
    public function create(string|array|null $templatesPath = null): Twig
41
    {
42
        if ($templatesPath === null) {
43
            $templatesPath = $this->config->getLayoutsPath();
44
        }
45
46
        return new Twig($this->builder, $templatesPath);
47
    }
48
}
49