Passed
Pull Request — master (#3)
by Stanislau
04:15 queued 01:16
created

EnvironmentFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
/*
4
 *  This file is part of the Micro framework package.
5
 *
6
 *  (c) Stanislau Komar <[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
namespace Micro\Plugin\Twig\Business\Environment;
13
14
use Micro\Plugin\Twig\Business\Loader\LoaderProcessorInterface;
15
use Micro\Plugin\Twig\TwigPluginConfigurationInterface;
16
use Twig\Environment;
17
use Twig\Loader\FilesystemLoader;
18
use Twig\Loader\LoaderInterface;
19
20
readonly class EnvironmentFactory implements EnvironmentFactoryInterface
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_READONLY on line 20 at column 0
Loading history...
21
{
22 2
    public function __construct(
23
        private TwigPluginConfigurationInterface $pluginConfiguration,
24
        private LoaderProcessorInterface $environmentLoaderProcessor
25
    ) {
26 2
    }
27
28 1
    public function create(): Environment
29
    {
30 1
        $twig = $this->createEnvironment();
31
32 1
        $this->environmentLoaderProcessor->load($twig);
33
34 1
        return $twig;
35
    }
36
37 1
    protected function createEnvironment(): Environment
38
    {
39 1
        return new Environment(
40 1
            $this->createLoader(),
41 1
            $this->createEnvironmentConfigurationArray()
42 1
        );
43
    }
44
45 1
    protected function createLoader(): LoaderInterface
46
    {
47 1
        return new FilesystemLoader();
48
    }
49
50
    /**
51
     * @return array<string, mixed>
52
     */
53 1
    protected function createEnvironmentConfigurationArray(): array
54
    {
55 1
        return $this->pluginConfiguration->getConfigurationArray();
56
    }
57
}
58