Code Duplication    Length = 23-24 lines in 2 locations

code/control/GitDispatcher.php 1 location

@@ 278-300 (lines=23) @@
275
	 */
276
	protected function getGitPrevDeploys($project) {
277
		$redeploy = [];
278
		foreach ($project->DNEnvironmentList() as $dnEnvironment) {
279
			$envName = $dnEnvironment->Name;
280
			$perEnvDeploys = [];
281
			foreach ($dnEnvironment->DeployHistory()->filter('State', \DNDeployment::STATE_COMPLETED) as $deploy) {
282
				$sha = $deploy->SHA;
283
284
				// Check if exists to make sure the newest deployment date is used.
285
				if (!isset($perEnvDeploys[$sha])) {
286
					$pastValue = sprintf(
287
						"%s (deployed %s)",
288
						substr($sha, 0, 8),
289
						$deploy->obj('LastEdited')->Ago()
290
					);
291
					$perEnvDeploys[$sha] = [
292
						'id' => $sha,
293
						'title' => $pastValue
294
					];
295
				}
296
			}
297
			if (!empty($perEnvDeploys)) {
298
				$redeploy[$envName] = array_values($perEnvDeploys);
299
			}
300
		}
301
		return $redeploy;
302
	}
303

code/control/DNRoot.php 1 location

@@ 1155-1178 (lines=24) @@
1152
		// We are aiming at the format:
1153
		// [{text: 'optgroup text', children: [{id: '<sha>', text: '<inner text>'}]}]
1154
		$redeploy = [];
1155
		foreach ($project->DNEnvironmentList() as $dnEnvironment) {
1156
			$envName = $dnEnvironment->Name;
1157
			$perEnvDeploys = [];
1158
1159
			foreach ($dnEnvironment->DeployHistory()->filter('State', \DNDeployment::STATE_COMPLETED) as $deploy) {
1160
				$sha = $deploy->SHA;
1161
1162
				// Check if exists to make sure the newest deployment date is used.
1163
				if (!isset($perEnvDeploys[$sha])) {
1164
					$pastValue = sprintf("%s (deployed %s)",
1165
						substr($sha, 0, 8),
1166
						$deploy->obj('LastEdited')->Ago()
1167
					);
1168
					$perEnvDeploys[$sha] = [
1169
						'id' => $sha,
1170
						'text' => $pastValue
1171
					];
1172
				}
1173
			}
1174
1175
			if (!empty($perEnvDeploys)) {
1176
				$redeploy[$envName] = array_values($perEnvDeploys);
1177
			}
1178
		}
1179
		// Convert the array to the frontend format (i.e. keyed to regular array)
1180
		foreach ($redeploy as $name => $descr) {
1181
			$data['field_data'][] = ['text' => $name, 'children' => $descr];