Code Duplication    Length = 29-29 lines in 2 locations

code/control/ApprovalsDispatcher.php 2 locations

@@ 165-193 (lines=29) @@
162
	 * @param \SS_HTTPRequest $request
163
	 * @return \SS_HTTPResponse
164
	 */
165
	public function approve(SS_HTTPRequest $request) {
166
		if ($request->httpMethod() !== 'POST') {
167
			return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405);
168
		}
169
170
		$deployment = DNDeployment::get()->byId($request->postVar('id'));
171
		$errorResponse = $this->validateDeployment($deployment);
172
		if ($errorResponse instanceof \SS_HTTPResponse) {
173
			return $errorResponse;
174
		}
175
176
		if (!$this->project->allowed(self::ALLOW_APPROVAL, Member::currentUser())) {
177
			return $this->getAPIResponse(['message' => 'You are not authorised to approve this deployment'], 403);
178
		}
179
180
		try {
181
			$deployment->getMachine()->apply(DNDeployment::TR_APPROVE);
182
		} catch (\Exception $e) {
183
			return $this->getAPIResponse([
184
				'status' => 'FAILED',
185
				'message' => $e->getMessage()
186
			], 400);
187
		}
188
189
		return $this->getAPIResponse([
190
			'status' => 'OK',
191
			'deployment' => $this->formatter->getDeploymentData($deployment)
192
		], 200);
193
	}
194
195
	/**
196
	 * @param \SS_HTTPRequest $request
@@ 199-227 (lines=29) @@
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
			'deployment' => $this->formatter->getDeploymentData($deployment)
226
		], 200);
227
	}
228
229
	/**
230
	 * Check if a DNDeployment exists and do permission checks on it. If there is something wrong it will return