Passed
Push — master ( 2a8eac...e4d347 )
by Hannes
01:51
created

Plugin::loadPlugin()   C

Complexity

Conditions 10
Paths 257

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 17
nc 257
nop 1
dl 0
loc 26
rs 6.1208
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * This file is part of byrokrat\giroapp.
4
 *
5
 * byrokrat\giroapp is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License as published
7
 * by the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * byrokrat\giroapp is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with byrokrat\giroapp. If not, see <http://www.gnu.org/licenses/>.
17
 *
18
 * Copyright 2016-19 Hannes Forsgård
19
 */
20
21
declare(strict_types = 1);
22
23
namespace byrokrat\giroapp\Plugin;
24
25
use byrokrat\giroapp\Console\CommandInterface;
26
use byrokrat\giroapp\Filter\FilterInterface;
27
use byrokrat\giroapp\Formatter\FormatterInterface;
28
use byrokrat\giroapp\Sorter\SorterInterface;
29
use byrokrat\giroapp\State\StateInterface;
30
use byrokrat\giroapp\Xml\XmlFormInterface;
31
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
32
33
class Plugin implements PluginInterface
34
{
35
    /**
36
     * @var object[]
37
     */
38
    private $objects;
39
40
    public function __construct(...$objects)
41
    {
42
        $this->objects = $objects;
43
    }
44
45
    final public function loadPlugin(EnvironmentInterface $environment): void
46
    {
47
        foreach ($this->objects as $item) {
48
            if ($item instanceof ApiVersionConstraint) {
49
                $environment->assertApiVersion($item);
50
            }
51
            if ($item instanceof CommandInterface) {
52
                $environment->registerCommand($item);
53
            }
54
            if ($item instanceof EventSubscriberInterface) {
55
                $environment->registerSubscriber($item);
56
            }
57
            if ($item instanceof FilterInterface) {
58
                $environment->registerDonorFilter($item);
59
            }
60
            if ($item instanceof FormatterInterface) {
61
                $environment->registerDonorFormatter($item);
62
            }
63
            if ($item instanceof SorterInterface) {
64
                $environment->registerDonorSorter($item);
65
            }
66
            if ($item instanceof StateInterface) {
67
                $environment->registerDonorState($item);
68
            }
69
            if ($item instanceof XmlFormInterface) {
70
                $environment->registerXmlForm($item);
71
            }
72
        }
73
    }
74
}
75