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