Completed
Pull Request — master (#97)
by
unknown
02:57 queued 15s
created

getReplaceCommandHooks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
4
5
use Consolidation\AnnotatedCommand\CommandData;
6
use Consolidation\AnnotatedCommand\Hooks\HookManager;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\ConsoleEvents;
9
use Symfony\Component\Console\Event\ConsoleCommandEvent;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
12
/**
13
 * Call hooks.
14
 */
15
class ReplaceCommandHookDispatcher extends HookDispatcher
16
{
17
18
    /**
19
     * @param \Consolidation\AnnotatedCommand\CommandData $commandData
20
     *
21
     * @return int
22
     */
23
    public function hasReplaceCommandHook(CommandData $commandData) {
24
        return count($this->getReplaceCommandHooks($commandData));
25
    }
26
27
    /**
28
     * @param \Consolidation\AnnotatedCommand\CommandData $commandData
29
     *
30
     * @return \callable[]
31
     */
32
    public function getReplaceCommandHooks(CommandData $commandData) {
0 ignored issues
show
Unused Code introduced by
The parameter $commandData is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
        $hooks = [
34
            HookManager::REPLACE_COMMAND_HOOK,
35
        ];
36
        $replaceCommandHooks = $this->getHooks($hooks);
37
38
        return $replaceCommandHooks;
39
    }
40
41
    /**
42
     * @param \Consolidation\AnnotatedCommand\CommandData $commandData
43
     *
44
     * @return callable
45
     */
46
    public function getReplacementCommand(CommandData $commandData) {
47
        $replaceCommandHooks = $this->getReplaceCommandHooks($commandData);
48
49
        // We only take the first hook implementation of "replace-command" as the replacement. Commands shouldn't have
50
        // more than one replacement.
51
        $replacementCommand = reset($replaceCommandHooks);
52
53
        return $replacementCommand;
54
    }
55
}
56