PugFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 34
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0

2 Methods

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