StatusDeterminerHookDispatcher   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A determineStatusCode() 23 23 4
A callDeterminer() 9 9 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
4
5
use Consolidation\AnnotatedCommand\ExitCodeInterface;
6
use Consolidation\AnnotatedCommand\Hooks\HookManager;
7
use Consolidation\AnnotatedCommand\Hooks\StatusDeterminerInterface;
8
9
/**
10
 * Call hooks
11
 */
12 View Code Duplication
class StatusDeterminerHookDispatcher extends HookDispatcher implements StatusDeterminerInterface
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...
Deprecated Code introduced by
The interface Consolidation\AnnotatedC...atusDeterminerInterface has been deprecated with message: . Instead of using a Status Determiner hook, commands
should simply return their exit code and result data separately
using a CommandResult object.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
13
{
14
    /**
15
     * Call all status determiners, and see if any of them
16
     * know how to convert to a status code.
17
     */
18
    public function determineStatusCode($result)
19
    {
20
        // If the result (post-processing) is an object that
21
        // implements ExitCodeInterface, then we will ask it
22
        // to give us the status code.
23
        if ($result instanceof ExitCodeInterface) {
24
            return $result->getExitCode();
25
        }
26
27
        $hooks = [
28
            HookManager::STATUS_DETERMINER,
29
        ];
30
        // If the result does not implement ExitCodeInterface,
31
        // then we'll see if there is a determiner that can
32
        // extract a status code from the result.
33
        $determiners = $this->getHooks($hooks);
34
        foreach ($determiners as $determiner) {
35
            $status = $this->callDeterminer($determiner, $result);
36
            if (isset($status)) {
37
                return $status;
38
            }
39
        }
40
    }
41
42
    protected function callDeterminer($determiner, $result)
43
    {
44
        if ($determiner instanceof StatusDeterminerInterface) {
45
            return $determiner->determineStatusCode($result);
46
        }
47
        if (is_callable($determiner)) {
48
            return $determiner($result);
49
        }
50
    }
51
}
52