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

MultiCodingStandardExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 7
Bugs 1 Features 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 35
ccs 0
cts 17
cp 0
rs 10
c 7
b 1
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loadConfiguration() 0 5 1
A setConfigToContainerBuilder() 0 6 1
A loadServicesFromConfigPath() 0 6 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
    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