Code Duplication    Length = 30-30 lines in 2 locations

code/control/ApprovalsDispatcher.php 2 locations

@@ 164-193 (lines=30) @@
161
	 * @param \SS_HTTPRequest $request
162
	 * @return \SS_HTTPResponse
163
	 */
164
	public function approve(SS_HTTPRequest $request) {
165
		if ($request->httpMethod() !== 'POST') {
166
			return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405);
167
		}
168
169
		$deployment = DNDeployment::get()->byId($request->postVar('id'));
170
		$errorResponse = $this->validateDeployment($deployment);
171
		if ($errorResponse instanceof \SS_HTTPResponse) {
172
			return $errorResponse;
173
		}
174
175
		if (!$this->project->allowed(self::ALLOW_APPROVAL, Member::currentUser())) {
176
			return $this->getAPIResponse(['message' => 'You are not authorised to approve this deployment'], 403);
177
		}
178
179
		try {
180
			$deployment->getMachine()->apply(DNDeployment::TR_APPROVE);
181
		} catch (\Exception $e) {
182
			return $this->getAPIResponse([
183
				'status' => 'FAILED',
184
				'message' => $e->getMessage()
185
			], 400);
186
		}
187
188
		return $this->getAPIResponse([
189
			'status' => 'OK',
190
			'id' => $deployment->ID,
191
			'new_status' => DNDeployment::STATE_APPROVED
192
		], 200);
193
	}
194
195
	/**
196
	 * @param \SS_HTTPRequest $request
@@ 199-228 (lines=30) @@
196
	 * @param \SS_HTTPRequest $request
197
	 * @return \SS_HTTPResponse
198
	 */
199
	public function reject(SS_HTTPRequest $request) {
200
		if ($request->httpMethod() !== 'POST') {
201
			return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405);
202
		}
203
204
		$deployment = DNDeployment::get()->byId($request->postVar('id'));
205
		$errorResponse = $this->validateDeployment($deployment);
206
		if ($errorResponse instanceof \SS_HTTPResponse) {
207
			return $errorResponse;
208
		}
209
		// reject permissions are the same as can approve
210
		if (!$this->project->allowed(self::ALLOW_APPROVAL, Member::currentUser())) {
211
			return $this->getAPIResponse(['message' => 'You are not authorised to reject this deployment'], 403);
212
		}
213
214
		try {
215
			$deployment->getMachine()->apply(DNDeployment::TR_REJECT);
216
		} catch (\Exception $e) {
217
			return $this->getAPIResponse([
218
				'status' => 'FAILED',
219
				'message' => $e->getMessage()
220
			], 400);
221
		}
222
223
		return $this->getAPIResponse([
224
			'status' => 'OK',
225
			'id' => $deployment->ID,
226
			'new_status' => DNDeployment::STATE_REJECTED
227
		], 200);
228
	}
229
230
	/**
231
	 * Check if a DNDeployment exists and do permission checks on it. If there is something wrong it will return