Code Duplication    Length = 23-24 lines in 2 locations

code/control/DNRoot.php 1 location

@@ 1180-1203 (lines=24) @@
1177
		// We are aiming at the format:
1178
		// [{text: 'optgroup text', children: [{id: '<sha>', text: '<inner text>'}]}]
1179
		$redeploy = [];
1180
		foreach ($project->DNEnvironmentList() as $dnEnvironment) {
1181
			$envName = $dnEnvironment->Name;
1182
			$perEnvDeploys = [];
1183
1184
			foreach ($dnEnvironment->DeployHistory() as $deploy) {
1185
				$sha = $deploy->SHA;
1186
1187
				// Check if exists to make sure the newest deployment date is used.
1188
				if (!isset($perEnvDeploys[$sha])) {
1189
					$pastValue = sprintf("%s (deployed %s)",
1190
						substr($sha, 0, 8),
1191
						$deploy->obj('LastEdited')->Ago()
1192
					);
1193
					$perEnvDeploys[$sha] = [
1194
						'id' => $sha,
1195
						'text' => $pastValue
1196
					];
1197
				}
1198
			}
1199
1200
			if (!empty($perEnvDeploys)) {
1201
				$redeploy[$envName] = array_values($perEnvDeploys);
1202
			}
1203
		}
1204
		// Convert the array to the frontend format (i.e. keyed to regular array)
1205
		foreach ($redeploy as $name => $descr) {
1206
			$data['field_data'][] = ['text' => $name, 'children' => $descr];

code/control/GitDispatcher.php 1 location

@@ 243-265 (lines=23) @@
240
	 */
241
	protected function getGitPrevDeploys($project) {
242
		$redeploy = [];
243
		foreach ($project->DNEnvironmentList() as $dnEnvironment) {
244
			$envName = $dnEnvironment->Name;
245
			$perEnvDeploys = [];
246
			foreach ($dnEnvironment->DeployHistory() as $deploy) {
247
				$sha = $deploy->SHA;
248
249
				// Check if exists to make sure the newest deployment date is used.
250
				if (!isset($perEnvDeploys[$sha])) {
251
					$pastValue = sprintf(
252
						"%s (deployed %s)",
253
						substr($sha, 0, 8),
254
						$deploy->obj('LastEdited')->Ago()
255
					);
256
					$perEnvDeploys[$sha] = [
257
						'key' => $sha,
258
						'value' => $pastValue
259
					];
260
				}
261
			}
262
			if (!empty($perEnvDeploys)) {
263
				$redeploy[$envName] = array_values($perEnvDeploys);
264
			}
265
		}
266
		return $redeploy;
267
	}
268