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

ReplaceCommandHookDispatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 40
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasReplaceCommandHook() 0 4 1
A getReplaceCommandHooks() 0 9 1
A getReplacementCommand() 0 10 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
     * @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