Completed
Pull Request — master (#28)
by Tom
02:54
created

ApplicationConfigServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 52
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A register() 0 11 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
8
final class ApplicationConfigServiceProvider extends AbstractServiceProvider
9
{
10
    /**
11
     * @var ApplicationConfig
12
     */
13
    private $config;
14
15
    /**
16
     * @var string
17
     */
18
    private $prefix;
19
20
    /**
21
     * @param ApplicationConfig $config
22
     * @param string            $prefix
23
     */
24
    public function __construct(ApplicationConfig $config, $prefix)
25
    {
26
        $this->prefix   = $prefix;
27
        $this->config   = $config;
28
        $this->provides = array_map(
29
            function ($key) {
30
                return $this->keyPrefix() . $key;
31
            },
32
            $config->getKeys()
33
        );
34
    }
35
36
    public function register()
37
    {
38
        $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...
39
        $prefix    = $this->keyPrefix();
40
41
        foreach ($this->config as $key => $value) {
42
            $this->getContainer()->share($prefix . $key, function () use ($value) {
43
                return $value;
44
            });
45
        }
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    private function keyPrefix()
52
    {
53
        if (empty($this->prefix)) {
54
            return '';
55
        }
56
57
        return $this->prefix . $this->config->getSeparator();
58
    }
59
}
60