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
02:41
created

ChapiConfigLoader   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 2
dl 0
loc 74
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
C loadProfileParameters() 0 25 7
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
        // parameters
54 2
        if (isset($content['parameters'])) {
55 2
            if (is_array($content['parameters'])) {
56 1
                foreach ($content['parameters'] as &$parameter) {
57 1
                    if ($parameter === null || $parameter === 'null') {
58 1
                        $parameter = '';
59
                    }
60
                }
61
            }
62
63 2
            $this->validate($content);
64 1
            $this->setParameters($content['parameters']);
65
        }
66 1
    }
67
68
    /**
69
     * @param array $content
70
     * @throws InvalidArgumentException
71
     * @return void
72
     */
73 2
    private function validate(array &$content)
74
    {
75 2
        if (isset($content['parameters']) && !is_array($content['parameters'])) {
76 1
            throw new InvalidArgumentException('The "parameters" key should contain an array. Please check your configuration files.');
77
        }
78 1
    }
79
80
    /**
81
     * @param array $parameters
82
     */
83 1
    private function setParameters(array &$parameters)
84
    {
85 1
        foreach ($parameters as $key => $value) {
86 1
            $this->container->setParameter($key, $value);
87
        }
88 1
    }
89
}
90