Code Duplication    Length = 29-30 lines in 2 locations

code/control/ApprovalsDispatcher.php 2 locations

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