Completed
Push — master ( efc44e...835840 )
by Pablo
02:59
created

PrePush   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 118
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 4
dl 118
loc 118
ccs 33
cts 36
cp 0.9167
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A isEnabled() 4 4 1
A isUndefined() 4 4 1
A getExecute() 4 4 1
A getMessages() 4 4 1
A setMessages() 9 9 1
A setExecute() 9 9 1
A setEnabled() 15 15 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 PhpGitHooks\Module\Configuration\Domain;
4
5
use PhpGitHooks\Module\Configuration\Model\ExecuteInterface;
6
use PhpGitHooks\Module\Configuration\Model\HookInterface;
7
8 View Code Duplication
class PrePush implements HookInterface
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...
9
{
10
    /**
11
     * @var Undefined
12
     */
13
    private $undefined;
14
    /**
15
     * @var Enabled
16
     */
17
    private $enabled;
18
    /**
19
     * @var ExecuteInterface
20
     */
21
    private $execute;
22
    /**
23
     * @var Messages
24
     */
25
    private $messages;
26
27
    /**
28
     * PrePush constructor.
29
     *
30
     * @param Undefined        $undefined
31
     * @param Enabled          $enabled
32
     * @param ExecuteInterface $execute
33
     * @param Messages         $messages
34
     */
35 5
    public function __construct(Undefined $undefined, Enabled $enabled, ExecuteInterface $execute, Messages $messages)
36
    {
37 5
        $this->undefined = $undefined;
38 5
        $this->enabled = $enabled;
39 5
        $this->execute = $execute;
40 5
        $this->messages = $messages;
41 5
    }
42
43
    /**
44
     * @return bool
45
     */
46 3
    public function isEnabled()
47
    {
48 3
        return $this->enabled->value();
49
    }
50
51
    /**
52
     * @return bool
53
     */
54 2
    public function isUndefined()
55
    {
56 2
        return $this->undefined->value();
57
    }
58
59
    /**
60
     * @return ExecuteInterface
61
     */
62 3
    public function getExecute()
63
    {
64 3
        return $this->execute;
65
    }
66
67
    /**
68
     * @return Messages
69
     */
70 3
    public function getMessages()
71
    {
72 3
        return $this->messages;
73
    }
74
75
    /**
76
     * @param ExecuteInterface $execute
77
     *
78
     * @return PreCommit
79
     */
80 2
    public function setExecute(ExecuteInterface $execute)
81
    {
82 2
        return new self(
83 2
            $this->undefined,
84 2
            $this->enabled,
85
            $execute,
86 2
            $this->messages
87
        );
88
    }
89
90
    /**
91
     * @param Enabled $enabled
92
     *
93
     * @return PrePush
94
     */
95 1
    public function setEnabled(Enabled $enabled)
96
    {
97 1
        $execute = $this->execute;
98 1
        $messages = $this->messages;
99
        /** @var Execute $execute */
100 1
        $execute = false === $enabled->value() ? $execute->disableTools() : $execute;
101 1
        $messages = false === $enabled->value() ? $messages->disable() : $messages;
102
103 1
        return new self(
104 1
            new Undefined(false),
105
            $enabled,
106
            $execute,
107 1
            $messages
108
        );
109
    }
110
111
    /**
112
     * @param Messages $messages
113
     *
114
     * @return PrePush
115
     */
116 1
    public function setMessages(Messages $messages)
117
    {
118 1
        return new self(
119 1
            $this->undefined,
120 1
            $this->enabled,
121 1
            $this->execute,
122 1
            $messages
123
        );
124
    }
125
}
126