Completed
Pull Request — master (#28)
by Tom
27:09
created

ApplicationConfigServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 53
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A register() 0 12 2
A keyPrefix() 0 8 2
1
<?php
2
3
namespace TomPHP\ConfigServiceProvider\League;
4
5
use League\Container\ServiceProvider\AbstractServiceProvider;
6
use TomPHP\ConfigServiceProvider\ApplicationConfig;
7
use TomPHP\ConfigServiceProvider\ApplicationConfigIterator;
8
9
final class ApplicationConfigServiceProvider extends AbstractServiceProvider
10
{
11
    /**
12
     * @var ApplicationConfig
13
     */
14
    private $config;
15
16
    /**
17
     * @var string
18
     */
19
    private $prefix;
20
21
    /**
22
     * @param ApplicationConfig $config
23
     * @param string            $prefix
24
     */
25
    public function __construct(ApplicationConfig $config, $prefix)
26
    {
27
        $this->prefix   = $prefix;
28
        $this->config   = $config;
29
        $this->provides = array_map(
30
            function ($key) {
31
                return $this->keyPrefix() . $key;
32
            },
33
            $config->getKeys()
34
        );
35
    }
36
37
    public function register()
38
    {
39
        $container = $this->getContainer();
0 ignored issues
show
Unused Code introduced by
$container is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
40
        $iterator  = new ApplicationConfigIterator($this->config);
41
        $prefix    = $this->keyPrefix();
42
43
        foreach ($iterator as $key => $value) {
44
            $this->getContainer()->share($prefix . $key, function () use ($value) {
45
                return $value;
46
            });
47
        }
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    private function keyPrefix()
54
    {
55
        if (empty($this->prefix)) {
56
            return '';
57
        }
58
59
        return $this->prefix . $this->config->getSeparator();
60
    }
61
}
62