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.

ChapiConfigLoader::loadProfileParameters()   C
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 13
cts 13
cp 1
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 12
nc 4
nop 0
crap 7
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