Completed
Push — master ( 23d58c...27ec94 )
by Greg
02:24
created

InitializeHookDispatcher::initialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 2
1
<?php
2
3
namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
4
5
use Consolidation\AnnotatedCommand\Hooks\HookManager;
6
use Consolidation\AnnotatedCommand\AnnotationData;
7
use Consolidation\AnnotatedCommand\Hooks\InitializeHookInterface;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputInterface;
10
11
/**
12
 * Call hooks
13
 */
14 View Code Duplication
class InitializeHookDispatcher extends HookDispatcher implements InitializeHookInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    public function initialize(
17
        InputInterface $input,
18
        AnnotationData $annotationData
19
    ) {
20
        $hooks = [
21
            HookManager::PRE_INITIALIZE,
22
            HookManager::INITIALIZE,
23
            HookManager::POST_INITIALIZE
24
        ];
25
        $providers = $this->getHooks($hooks, $annotationData);
26
        foreach ($providers as $provider) {
27
            $this->callInitializeHook($provider, $input, $annotationData);
28
        }
29
    }
30
31
    protected function callInitializeHook($provider, $input, AnnotationData $annotationData)
32
    {
33
        if ($provider instanceof InitializeHookInterface) {
34
            return $provider->initialize($input, $annotationData);
35
        }
36
        if (is_callable($provider)) {
37
            return $provider($input, $annotationData);
38
        }
39
    }
40
}
41