Passed
Push — master ( 044628...35c875 )
by Koldo
02:20
created

PugFactory::addOns()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 4.25

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 3
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 5
ccs 3
cts 4
cp 0.75
crap 4.25
rs 10
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