Code Duplication    Length = 23-24 lines in 2 locations

code/control/GitDispatcher.php 1 location

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

code/control/DNRoot.php 1 location

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