Code Duplication    Length = 24-25 lines in 2 locations

code/control/ApprovalsDispatcher.php 2 locations

@@ 95-118 (lines=24) @@
92
	 * @param \SS_HTTPRequest $request
93
	 * @return \SS_HTTPResponse
94
	 */
95
	public function submit(SS_HTTPRequest $request) {
96
		if ($request->httpMethod() !== 'POST') {
97
			return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405);
98
		}
99
100
		$deployment = DNDeployment::get()->byId($request->postVar('id'));
101
		$errorResponse = $this->validateDeployment($deployment);
102
		if ($errorResponse instanceof \SS_HTTPResponse) {
103
			return $errorResponse;
104
		}
105
106
		try {
107
			$deployment->getMachine()->apply(DNDeployment::TR_SUBMIT);
108
		} catch (\Exception $e) {
109
			return $this->getAPIResponse([
110
				'message' => $e->getMessage()
111
			], 400);
112
		}
113
114
		return $this->getAPIResponse([
115
			'message' => 'Deployment request has been submitted',
116
			'deployment' => $this->formatter->getDeploymentData($deployment)
117
		], 200);
118
	}
119
120
	/**
121
	 * @param \SS_HTTPRequest $request
@@ 124-148 (lines=25) @@
121
	 * @param \SS_HTTPRequest $request
122
	 * @return \SS_HTTPResponse
123
	 */
124
	public function cancel(SS_HTTPRequest $request) {
125
		if ($request->httpMethod() !== 'POST') {
126
			return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405);
127
		}
128
129
		$deployment = DNDeployment::get()->byId($request->postVar('id'));
130
		$errorResponse = $this->validateDeployment($deployment);
131
		if ($errorResponse instanceof \SS_HTTPResponse) {
132
			return $errorResponse;
133
		}
134
135
		// @todo permission checking for cancelling an approval request
136
		try {
137
			$deployment->getMachine()->apply(DNDeployment::TR_NEW);
138
		} catch (\Exception $e) {
139
			return $this->getAPIResponse([
140
				'message' => $e->getMessage()
141
			], 400);
142
		}
143
144
		return $this->getAPIResponse([
145
			'message' => 'Deployment request has been cancelled',
146
			'deployment' => $this->formatter->getDeploymentData($deployment)
147
		], 200);
148
	}
149
150
	/**
151
	 * @param \SS_HTTPRequest $request