Passed
Pull Request — master (#2285)
by Arnaud
15:22 queued 09:39
created

TwigFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
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
31
    /**
32
     * Logger instance for future use.
33
     * Reserved for consistency with other factory patterns in the codebase.
34
     */
35
    private LoggerInterface $logger;
36
37
    private Builder $builder;
38
39 1
    public function __construct(
40
        Config $config,
41
        LoggerInterface $logger,
42
        Builder $builder
43
    ) {
44 1
        $this->config = $config;
45 1
        $this->logger = $logger;
46 1
        $this->builder = $builder;
47
    }
48
49
    /**
50
     * Creates a Twig renderer instance.
51
     *
52
     * @param string|array|null $templatesPath Template path(s) (uses default config if null)
53
     * @return Twig Configured renderer instance
54
     */
55 1
    public function create(string|array|null $templatesPath = null): Twig
56
    {
57 1
        if ($templatesPath === null) {
58
            $templatesPath = $this->config->getLayoutsPath();
59
        }
60
61 1
        return new Twig($this->builder, $templatesPath);
62
    }
63
}
64