Completed
Push — master ( 03d9da...2dac9a )
by Tom
13s
created

InflectorServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A register() 0 3 1
A boot() 0 6 2
A configureInterface() 0 10 2
A addInflectorMethod() 0 6 1
1
<?php
2
3
namespace TomPHP\ContainerConfigurator\League;
4
5
use League\Container\ServiceProvider\AbstractServiceProvider;
6
use League\Container\ServiceProvider\BootableServiceProviderInterface;
7
use TomPHP\ContainerConfigurator\InflectorConfig;
8
use TomPHP\ContainerConfigurator\InflectorDefinition;
9
10
final class InflectorServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface
11
{
12
    /**
13
     * @var InflectorConfig
14
     */
15
    private $config;
16
17
    /**
18
     * @api
19
     *
20
     * @param InflectorConfig $config
21
     */
22
    public function __construct(InflectorConfig $config)
23
    {
24
        $this->config = $config;
25
    }
26
27
    public function register()
28
    {
29
    }
30
31
    public function boot()
32
    {
33
        foreach ($this->config as $definition) {
34
            $this->configureInterface($definition);
35
        }
36
    }
37
38
    /**
39
     * @param InflectorDefinition $definition
40
     */
41
    private function configureInterface(InflectorDefinition $definition)
42
    {
43
        foreach ($definition->getMethods() as $method => $args) {
44
            $this->addInflectorMethod(
45
                $definition->getInterface(),
46
                $method,
47
                $args
48
            );
49
        }
50
    }
51
52
    /**
53
     * @param string $interface
54
     * @param string $method
55
     * @param array  $args
56
     */
57
    private function addInflectorMethod($interface, $method, array $args)
58
    {
59
        $this->getContainer()
60
            ->inflector($interface)
61
            ->invokeMethod($method, $args);
62
    }
63
}
64