Completed
Push — master ( afadea...e6376f )
by Tomáš
03:06 queued 03:01
created

setConfigToContainerBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 2
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of Symplify
5
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6
 */
7
8
namespace Symplify\MultiCodingStandard\DI;
9
10
use Nette\DI\CompilerExtension;
11
use Nette\DI\Helpers;
12
13
final class MultiCodingStandardExtension extends CompilerExtension
14
{
15
    /**
16
     * @var string[]
17
     */
18
    private $defaults = [
19
        'configPath' => '%appDir%/../../multi-cs.json'
20
    ];
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function loadConfiguration()
26
    {
27
        $this->setConfigToContainerBuilder($this->defaults);
28
        $this->loadServicesFromConfigPath(__DIR__ . '/../config/services.neon');
29
    }
30
31
    /**
32
     * @param string[] $defaults
33
     */
34
    private function setConfigToContainerBuilder(array $defaults)
35
    {
36
        $config = $this->validateConfig($defaults);
37
        $config['configPath'] = Helpers::expand($config['configPath'], $this->getContainerBuilder()->parameters);
38
        $this->getContainerBuilder()->parameters += $config;
39
    }
40
41
    private function loadServicesFromConfigPath(string $configPath)
42
    {
43
        $containerBuilder = $this->getContainerBuilder();
44
        $config = $this->loadFromFile($configPath);
45
        $this->compiler->parseServices($containerBuilder, $config);
0 ignored issues
show
Deprecated Code introduced by
The method Nette\DI\Compiler::parseServices() has been deprecated.

This method has been deprecated.

Loading history...
Bug introduced by
It seems like $config defined by $this->loadFromFile($configPath) on line 44 can also be of type string; however, Nette\DI\Compiler::parseServices() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
46
    }
47
}
48