Completed
Push — master ( 879230...0afc29 )
by Pablo
05:15
created

PreCommit::getExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 0
crap 1
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