Completed
Pull Request — master (#10)
by Tomáš
07:18
created

MultiCodingStandardExtension::loadConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
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 1
    public function loadConfiguration()
26
    {
27 1
        $this->setConfigToContainerBuilder($this->defaults);
28 1
        $this->loadServicesFromConfigPath(__DIR__ . '/../config/services.neon');
29 1
    }
30
31
    /**
32
     * @param string[] $defaults
33
     */
34 1
    private function setConfigToContainerBuilder(array $defaults)
35
    {
36 1
        $config = $this->validateConfig($defaults);
37 1
        $config['configPath'] = Helpers::expand($config['configPath'], $this->getContainerBuilder()->parameters);
38 1
        $this->getContainerBuilder()->parameters += $config;
39 1
    }
40
41 1
    private function loadServicesFromConfigPath(string $configPath)
42
    {
43 1
        $containerBuilder = $this->getContainerBuilder();
44 1
        $config = $this->loadFromFile($configPath);
45 1
        $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 1
    }
47
}
48