Completed
Push — master ( 3b5f38...c5ceed )
by Tomáš
04:59
created

Php7CodeSnifferExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 2
cbo 3
dl 0
loc 37
ccs 0
cts 22
cp 0
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A loadConfiguration() 0 4 1
A beforeCompile() 0 5 1
A loadServicesFromConfig() 0 5 1
A loadConsoleCommandsToConsoleApplication() 0 4 1
A loadEventSubscribersToEventDispatcher() 0 4 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\Application;
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\EventDispatcher\EventDispatcher;
14
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15
16
final class Php7CodeSnifferExtension extends CompilerExtension
17
{
18
    use ExtensionHelperTrait;
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function loadConfiguration()
24
    {
25
        $this->loadServicesFromConfig();
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function beforeCompile()
32
    {
33
        $this->loadConsoleCommandsToConsoleApplication();
34
        $this->loadEventSubscribersToEventDispatcher();
35
    }
36
37
    private function loadServicesFromConfig()
38
    {
39
        $config = $this->loadFromFile(__DIR__ . '/../config/services.neon');
40
        $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
    }
42
43
    private function loadConsoleCommandsToConsoleApplication()
44
    {
45
        $this->addServicesToCollector(Application::class, Command::class, 'add');
46
    }
47
48
    private function loadEventSubscribersToEventDispatcher()
49
    {
50
        $this->addServicesToCollector(EventDispatcher::class, EventSubscriberInterface::class, 'addSubscriber');
51
    }
52
}
53