Completed
Push — master ( 83e357...f961ff )
by Nikola
03:07
created

AuraDiFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 85%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 42
ccs 17
cts 20
cp 0.85
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createContainer() 0 4 1
A configure() 0 9 1
A setFactories() 0 12 3
A setInvokables() 0 6 2
1
<?php
2
/**
3
 * This file is part of the Phoundation package.
4
 *
5
 * Copyright (c) Nikola Posa
6
 *
7
 * For full copyright and license information, please refer to the LICENSE file,
8
 * located at the package root folder.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Phoundation\Di\Container\Factory;
14
15
use Aura\Di\Container;
16
use Aura\Di\ContainerBuilder;
17
18
/**
19
 * @author Nikola Posa <[email protected]>
20
 */
21
final class AuraDiFactory extends AbstractFactory
22
{
23
    /**
24
     * @var Container
25
     */
26
    protected $container;
27
28 4
    protected function createContainer()
29
    {
30 4
        return (new ContainerBuilder())->newInstance();
31
    }
32
33 4
    protected function configure($container)
34
    {
35 4
        $this->container = $container;
36
        
37 4
        $this->setFactories();
38 4
        $this->setInvokables();
39
40 4
        $this->container->set($this->getConfigServiceName(), $this->getConfig());
41 4
    }
42
43 4
    private function setFactories()
44
    {
45 4
        foreach ($this->getDiConfig('factories') as $name => $factory) {
46 1
            if (is_string($factory)) {
47
                $this->container->set($name, $this->container->lazyNew($factory));
48
                $this->container->set($name, $this->container->lazyGetCall($factory, '__invoke', $this->container));
49
                continue;
50
            }
51
52 1
            $this->container->set($name, $factory);
53
        }
54 4
    }
55
56 4
    private function setInvokables()
57
    {
58 4
        foreach ($this->getDiConfig('invokables') as $name => $className) {
59 1
            $this->container->set($name, $this->container->lazyNew($className));
60
        }
61 4
    }
62
}
63