Code Duplication    Length = 29-29 lines in 2 locations

code/control/ApprovalsDispatcher.php 2 locations

@@ 166-194 (lines=29) @@
163
	 * @param \SS_HTTPRequest $request
164
	 * @return \SS_HTTPResponse
165
	 */
166
	public function approve(SS_HTTPRequest $request) {
167
		if ($request->httpMethod() !== 'POST') {
168
			return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405);
169
		}
170
171
		$deployment = DNDeployment::get()->byId($request->postVar('id'));
172
		$errorResponse = $this->validateDeployment($deployment);
173
		if ($errorResponse instanceof \SS_HTTPResponse) {
174
			return $errorResponse;
175
		}
176
177
		if (!$this->project->allowed(self::ALLOW_APPROVAL, Member::currentUser())) {
178
			return $this->getAPIResponse(['message' => 'You are not authorised to approve this deployment'], 403);
179
		}
180
181
		try {
182
			$deployment->getMachine()->apply(DNDeployment::TR_APPROVE);
183
		} catch (\Exception $e) {
184
			return $this->getAPIResponse([
185
				'status' => 'FAILED',
186
				'message' => $e->getMessage()
187
			], 400);
188
		}
189
190
		return $this->getAPIResponse([
191
			'status' => 'OK',
192
			'deployment' => $this->formatter->getDeploymentData($deployment)
193
		], 200);
194
	}
195
196
	/**
197
	 * @param \SS_HTTPRequest $request
@@ 200-228 (lines=29) @@
197
	 * @param \SS_HTTPRequest $request
198
	 * @return \SS_HTTPResponse
199
	 */
200
	public function reject(SS_HTTPRequest $request) {
201
		if ($request->httpMethod() !== 'POST') {
202
			return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405);
203
		}
204
205
		$deployment = DNDeployment::get()->byId($request->postVar('id'));
206
		$errorResponse = $this->validateDeployment($deployment);
207
		if ($errorResponse instanceof \SS_HTTPResponse) {
208
			return $errorResponse;
209
		}
210
		// reject permissions are the same as can approve
211
		if (!$this->project->allowed(self::ALLOW_APPROVAL, Member::currentUser())) {
212
			return $this->getAPIResponse(['message' => 'You are not authorised to reject this deployment'], 403);
213
		}
214
215
		try {
216
			$deployment->getMachine()->apply(DNDeployment::TR_REJECT);
217
		} catch (\Exception $e) {
218
			return $this->getAPIResponse([
219
				'status' => 'FAILED',
220
				'message' => $e->getMessage()
221
			], 400);
222
		}
223
224
		return $this->getAPIResponse([
225
			'status' => 'OK',
226
			'deployment' => $this->formatter->getDeploymentData($deployment)
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