Code Duplication    Length = 28-30 lines in 2 locations

code/control/ApprovalsDispatcher.php 2 locations

@@ 114-141 (lines=28) @@
111
	 * @param \SS_HTTPRequest $request
112
	 * @return \SS_HTTPResponse
113
	 */
114
	public function approve(SS_HTTPRequest $request) {
115
		if ($request->httpMethod() !== 'POST') {
116
			return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405);
117
		}
118
119
		$deployment = DNDeployment::get()->byId($request->param('ID'));
120
		$errorResponse = $this->validateDeployment($deployment);
121
		if ($errorResponse instanceof \SS_HTTPResponse) {
122
			return $errorResponse;
123
		}
124
		if (!$this->canApprove()) {
125
			return $this->getAPIResponse(['message' => 'You are not authorised to reject this deployment'], 403);
126
		}
127
128
		try {
129
			$deployment->getMachine()->apply(DNDeployment::TR_APPROVE);
130
		} catch (\Exception $e) {
131
			return $this->getAPIResponse([
132
				'status' => 'FAILED',
133
				'message' => $e->getMessage()
134
			], 400);
135
		}
136
137
		return $this->getAPIResponse([
138
			'status' => 'OK',
139
			'id' => $deployment->ID
140
		], 200);
141
	}
142
143
	/**
144
	 * @param \SS_HTTPRequest $request
@@ 147-176 (lines=30) @@
144
	 * @param \SS_HTTPRequest $request
145
	 * @return \SS_HTTPResponse
146
	 */
147
	public function reject(SS_HTTPRequest $request) {
148
		if ($request->httpMethod() !== 'POST') {
149
			return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405);
150
		}
151
152
		$deployment = DNDeployment::get()->byId($request->param('ID'));
153
		$errorResponse = $this->validateDeployment($deployment);
154
		if ($errorResponse instanceof \SS_HTTPResponse) {
155
			return $errorResponse;
156
		}
157
		// can reject permissions are the same as can approve
158
		if (!$this->canApprove()) {
159
			return $this->getAPIResponse(['message' => 'You are not authorised to reject this deployment'], 403);
160
		}
161
162
		try {
163
			$deployment->getMachine()->apply(DNDeployment::TR_REJECT);
164
		} catch (\Exception $e) {
165
			return $this->getAPIResponse([
166
				'status' => 'FAILED',
167
				'message' => $e->getMessage()
168
			], 400);
169
		}
170
171
		return $this->getAPIResponse([
172
			'status' => 'OK',
173
			'message' => 'Deployment has been rejected',
174
			'id' => $deployment->ID,
175
		], 200);
176
	}
177
178
	/**
179
	 * Check if a DNDeployment exists and do permission checks on it. If there is something wrong it will return