Php7CodeSnifferExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 10
Bugs 2 Features 0
Metric Value
wmc 6
lcom 2
cbo 3
dl 0
loc 51
ccs 27
cts 27
cp 1
rs 10
c 10
b 2
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A loadConfiguration() 0 4 1
A beforeCompile() 0 6 1
A loadServicesFromConfig() 0 5 1
A loadConsoleCommandsToConsoleApplication() 0 4 1
A loadSniffFactoriesToSniffSetFactory() 0 8 1
A loadOptionResolversToConfigurationResolver() 0 8 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\ConsoleApplication;
14
use Symplify\PHP7_CodeSniffer\Contract\Configuration\OptionResolver\OptionResolverInterface;
15
use Symplify\PHP7_CodeSniffer\Contract\Sniff\Factory\SniffFactoryInterface;
16
use Symplify\PHP7_CodeSniffer\Sniff\SniffSetFactory;
17
18
final class Php7CodeSnifferExtension extends CompilerExtension
19
{
20
    use ExtensionHelperTrait;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 1
    public function loadConfiguration()
26
    {
27 1
        $this->loadServicesFromConfig();
28 1
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function beforeCompile()
34
    {
35 1
        $this->loadSniffFactoriesToSniffSetFactory();
36 1
        $this->loadConsoleCommandsToConsoleApplication();
37 1
        $this->loadOptionResolversToConfigurationResolver();
38 1
    }
39
40 1
    private function loadServicesFromConfig()
41
    {
42 1
        $config = $this->loadFromFile(__DIR__ . '/../config/services.neon');
43 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 42 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...
44 1
    }
45
46 1
    private function loadConsoleCommandsToConsoleApplication()
47
    {
48 1
        $this->addServicesToCollector(ConsoleApplication::class, Command::class, 'add');
49 1
    }
50
51 1
    private function loadSniffFactoriesToSniffSetFactory()
52
    {
53 1
        $this->addServicesToCollector(
54 1
            SniffSetFactory::class,
55 1
            SniffFactoryInterface::class,
56 1
            'addSniffFactory'
57
        );
58 1
    }
59
60 1
    private function loadOptionResolversToConfigurationResolver()
61
    {
62 1
        $this->addServicesToCollector(
63 1
            ConfigurationResolver::class,
64 1
            OptionResolverInterface::class,
65 1
            'addOptionResolver'
66
        );
67 1
    }
68
}
69