ContainerFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 31
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A set() 0 4 1
A addProvider() 0 4 1
A createContainer() 0 7 1
1
<?php
2
namespace NaiveContainer;
3
4
use Closure;
5
6
class ContainerFactory extends ContainerDecorator implements Factory
7
{
8
9
    /**
10
     * @var mixed [id => value] May be simple types or closures
11
     */
12
    protected $factory_stack = [];
13
14
    public function register(string $id, Closure $closure): void
15
    {
16
        $this->factory_stack[$id] = $closure;
17
    }
18
19
    public function set(string $id, $value): void
20
    {
21
        $this->factory_stack[$id] = $value;
22
    }
23
24
    public function addProvider(FactoryProvider $provider): void
25
    {
26
        $provider->register($this);
27
    }
28
29
    public function createContainer(): Container
30
    {
31
        $container = new Container();
32
        $container->container_stack = $this->factory_stack;
0 ignored issues
show
Bug introduced by
The property container_stack cannot be accessed from this context as it is declared protected in class NaiveContainer\ContainerDecorator.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
33
34
        return $container;
35
    }
36
}
37