ParameterInjection   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 50
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A register() 0 4 1
A args() 0 7 1
A injectIntoCommandData() 0 7 2
A getInstanceToInject() 0 8 2
A get() 0 11 3
1
<?php
2
namespace Consolidation\AnnotatedCommand;
3
4
/**
5
 * Prepare parameter list for execurion. Handle injection of any
6
 * special values (e.g. $input and $output) into the parameter list.
7
 */
8
class ParameterInjection implements ParameterInjector
9
{
10
    public function __construct()
11
    {
12
        $this->register('Symfony\Component\Console\Input\InputInterface', $this);
13
        $this->register('Symfony\Component\Console\Output\OutputInterface', $this);
14
    }
15
16
    public function register($interfaceName, ParameterInjector $injector)
17
    {
18
        $this->injectors[$interfaceName] = $injector;
0 ignored issues
show
Bug introduced by
The property injectors does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
    }
20
21
    public function args($commandData)
22
    {
23
        return array_merge(
24
            $commandData->injectedInstances(),
25
            $commandData->getArgsAndOptions()
26
        );
27
    }
28
29
    public function injectIntoCommandData($commandData, $injectedClasses)
30
    {
31
        foreach ($injectedClasses as $injectedClass) {
32
            $injectedInstance = $this->getInstanceToInject($commandData, $injectedClass);
33
            $commandData->injectInstance($injectedInstance);
34
        }
35
    }
36
37
    protected function getInstanceToInject(CommandData $commandData, $interfaceName)
38
    {
39
        if (!isset($this->injectors[$interfaceName])) {
40
            return null;
41
        }
42
43
        return $this->injectors[$interfaceName]->get($commandData, $interfaceName);
44
    }
45
46
    public function get(CommandData $commandData, $interfaceName)
47
    {
48
        switch ($interfaceName) {
49
            case 'Symfony\Component\Console\Input\InputInterface':
50
                return $commandData->input();
51
            case 'Symfony\Component\Console\Output\OutputInterface':
52
                return $commandData->output();
53
        }
54
55
        return null;
56
    }
57
}
58