Code Duplication    Length = 28-28 lines in 2 locations

code/control/ApprovalsDispatcher.php 2 locations

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