Code Duplication    Length = 28-30 lines in 2 locations

code/control/ApprovalsDispatcher.php 2 locations

@@ 132-159 (lines=28) @@
129
	 * @param \SS_HTTPRequest $request
130
	 * @return \SS_HTTPResponse
131
	 */
132
	public function approve(SS_HTTPRequest $request) {
133
		if ($request->httpMethod() !== 'POST') {
134
			return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405);
135
		}
136
137
		$deployment = DNDeployment::get()->byId($request->param('ID'));
138
		$errorResponse = $this->validateDeployment($deployment);
139
		if ($errorResponse instanceof \SS_HTTPResponse) {
140
			return $errorResponse;
141
		}
142
		if (!$this->canApprove()) {
143
			return $this->getAPIResponse(['message' => 'You are not authorised to approve this deployment'], 403);
144
		}
145
146
		try {
147
			$deployment->getMachine()->apply(DNDeployment::TR_APPROVE);
148
		} catch (\Exception $e) {
149
			return $this->getAPIResponse([
150
				'status' => 'FAILED',
151
				'message' => $e->getMessage()
152
			], 400);
153
		}
154
155
		return $this->getAPIResponse([
156
			'status' => 'OK',
157
			'id' => $deployment->ID
158
		], 200);
159
	}
160
161
	/**
162
	 * @param \SS_HTTPRequest $request
@@ 165-194 (lines=30) @@
162
	 * @param \SS_HTTPRequest $request
163
	 * @return \SS_HTTPResponse
164
	 */
165
	public function reject(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->param('ID'));
171
		$errorResponse = $this->validateDeployment($deployment);
172
		if ($errorResponse instanceof \SS_HTTPResponse) {
173
			return $errorResponse;
174
		}
175
		// can reject permissions are the same as can approve
176
		if (!$this->canApprove()) {
177
			return $this->getAPIResponse(['message' => 'You are not authorised to reject this deployment'], 403);
178
		}
179
180
		try {
181
			$deployment->getMachine()->apply(DNDeployment::TR_REJECT);
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
			'message' => 'Deployment has been rejected',
192
			'id' => $deployment->ID,
193
		], 200);
194
	}
195
196
	/**
197
	 * Check if a DNDeployment exists and do permission checks on it. If there is something wrong it will return