Code Duplication    Length = 27-27 lines in 2 locations

code/control/ApprovalsDispatcher.php 2 locations

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