GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#101)
by Patrick
05:09
created

ChapiConfigLoader   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 95.83%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 2
dl 0
loc 72
ccs 23
cts 24
cp 0.9583
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B loadProfileParameters() 0 23 6
A validate() 0 6 3
A setParameters() 0 6 2
1
<?php
2
/**
3
 * @package: chapi
4
 *
5
 * @author:  msiebeneicher
6
 * @since:   2017-03-20
7
 *
8
 */
9
10
namespace Chapi\Component\DependencyInjection\Loader;
11
12
use Chapi\Component\Config\ChapiConfigInterface;
13
use \InvalidArgumentException;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
16
class ChapiConfigLoader implements ChapiConfigLoaderInterface
17
{
18
    /**
19
     * @var ContainerBuilder
20
     */
21
    private $container;
22
23
    /**
24
     * @var ChapiConfigInterface
25
     */
26
    private $config;
27
28
    /**
29
     * ChapiConfigLoader constructor.
30
     * @param ContainerBuilder $container
31
     * @param ChapiConfigInterface $config
32
     */
33 3
    public function __construct(ContainerBuilder $container, ChapiConfigInterface $config)
34
    {
35 3
        $this->container = $container;
36 3
        $this->config = $config;
37 3
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 3
    public function loadProfileParameters()
43
    {
44 3
        $content = $this->config->getProfileConfig();
45
46 3
        $this->container->addObjectResource($this->config);
47
48
        // empty config
49 3
        if (empty($content)) {
50 1
            return;
51
        }
52
53 2
        foreach ($content['parameters'] as &$parameter) {
54 1
            if ($parameter === null || $parameter === 'null') {
55 1
                $parameter = '';
56
            }
57
        }
58
59
        // parameters
60 1
        if (isset($content['parameters'])) {
61 1
            $this->validate($content);
62 1
            $this->setParameters($content['parameters']);
63
        }
64 1
    }
65
66
    /**
67
     * @param array $content
68
     * @throws InvalidArgumentException
69
     * @return void
70
     */
71 1
    private function validate(array &$content)
72
    {
73 1
        if (isset($content['parameters']) && !is_array($content['parameters'])) {
74
            throw new InvalidArgumentException('The "parameters" key should contain an array. Please check your configuration files.');
75
        }
76 1
    }
77
78
    /**
79
     * @param array $parameters
80
     */
81 1
    private function setParameters(array &$parameters)
82
    {
83 1
        foreach ($parameters as $key => $value) {
84 1
            $this->container->setParameter($key, $value);
85
        }
86 1
    }
87
}
88