Completed
Push — master ( 23bc19...2eec4d )
by Tomáš
11:42
created

Php7CodeSnifferExtension::loadConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
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\PHP7_CodeSniffer\DI;
9
10
use Nette\DI\CompilerExtension;
11
use Symfony\Component\Console\Command\Command;
12
use Symplify\PHP7_CodeSniffer\Configuration\ConfigurationResolver;
13
use Symplify\PHP7_CodeSniffer\Console\Php7CodeSnifferApplication;
14
use Symplify\PHP7_CodeSniffer\Contract\Configuration\OptionResolver\OptionResolverInterface;
15
16
final class Php7CodeSnifferExtension extends CompilerExtension
17
{
18
    use ExtensionHelperTrait;
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 1
    public function loadConfiguration()
24
    {
25 1
        $this->loadServicesFromConfig();
26 1
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    public function beforeCompile()
32
    {
33 1
        $this->loadConsoleCommandsToConsoleApplication();
34 1
        $this->loadOptionResolversToConfigurationResolver();
35 1
    }
36
37 1
    private function loadServicesFromConfig()
38
    {
39 1
        $config = $this->loadFromFile(__DIR__ . '/../config/services.neon');
40 1
        $this->compiler->parseServices($this->getContainerBuilder(), $config);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->loadFromFile(__DI.../config/services.neon') on line 39 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...
Deprecated Code introduced by
The method Nette\DI\Compiler::parseServices() has been deprecated.

This method has been deprecated.

Loading history...
41 1
    }
42
43 1
    private function loadConsoleCommandsToConsoleApplication()
44
    {
45 1
        $this->addServicesToCollector(Php7CodeSnifferApplication::class, Command::class, 'add');
46 1
    }
47
48 1
    private function loadOptionResolversToConfigurationResolver()
49
    {
50 1
        $this->addServicesToCollector(
51 1
            ConfigurationResolver::class,
52 1
            OptionResolverInterface::class,
53 1
            'addOptionResolver'
54
        );
55 1
    }
56
}
57