PreCommit   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 118
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A isEnabled() 4 4 1
A getExecute() 4 4 1
A isUndefined() 4 4 1
A getMessages() 4 4 1
A setEnabled() 15 15 3
A setExecute() 9 9 1
A setMessages() 9 9 1

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