PugFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 30
ccs 13
cts 14
cp 0.9286
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 1
A addOns() 0 5 4
1
<?php
2
3
namespace Antidot\Render\Phug\Container;
4
5
use Antidot\Render\Phug\Container\Config\PugConfig;
6
use Psr\Container\ContainerInterface;
7
use Pug\Pug;
8
9
final class PugFactory
10
{
11
    public const AVAILABLE_ADD_ONS = [
12
        'filter' => 'filters',
13
        'addKeyword' => 'keywords',
14
        'share' => 'helpers',
15
    ];
16
17 1
    public function __invoke(ContainerInterface $container): Pug
18
    {
19 1
        $pugConfig = PugConfig::createFromAntidotConfig($container->get('config'));
20
21 1
        $pug = new Pug([
22 1
            'pugjs' => $pugConfig->get('pugjs'),
23 1
            'localsJsonFile' => $pugConfig->get('localsJsonFile'),
24 1
            'pretty' => $pugConfig->get('pretty'),
25 1
            'cache' => $pugConfig->get('cache'),
26 1
            'expressionLanguage' => $pugConfig->get('expressionLanguage'),
27
        ]);
28
29 1
        $this->addOns($pug, $container, $pugConfig);
30
31 1
        return $pug;
32
    }
33
34 1
    private function addOns(Pug $pug, ContainerInterface $container, PugConfig $config): void
35
    {
36 1
        foreach (self::AVAILABLE_ADD_ONS as $method => $type) {
37 1
            foreach ($config->get($type) as $name => $callable) {
38
                $pug->{$method}($name, is_callable($callable) ? $callable : $container->get($callable));
39
            }
40
        }
41 1
    }
42
}
43