Completed
Pull Request — master (#97)
by
unknown
03:12
created

getReplaceCommandHooks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
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
     * @return int
20
     */
21
    public function hasReplaceCommandHook()
22
    {
23
        return count($this->getReplaceCommandHooks());
24
    }
25
26
    /**
27
     * @return \callable[]
28
     */
29
    public function getReplaceCommandHooks()
30
    {
31
        $hooks = [
32
            HookManager::REPLACE_COMMAND_HOOK,
33
        ];
34
        $replaceCommandHooks = $this->getHooks($hooks);
35
36
        return $replaceCommandHooks;
37
    }
38
39
    /**
40
     * @param \Consolidation\AnnotatedCommand\CommandData $commandData
41
     *
42
     * @return callable
43
     */
44
    public function getReplacementCommand(CommandData $commandData)
45
    {
46
        $replaceCommandHooks = $this->getReplaceCommandHooks($commandData);
0 ignored issues
show
Unused Code introduced by
The call to ReplaceCommandHookDispat...etReplaceCommandHooks() has too many arguments starting with $commandData.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
47
48
        // We only take the first hook implementation of "replace-command" as the replacement. Commands shouldn't have
49
        // more than one replacement.
50
        $replacementCommand = reset($replaceCommandHooks);
51
52
        return $replacementCommand;
53
    }
54
}
55