Code Duplication    Length = 23-24 lines in 2 locations

code/control/GitDispatcher.php 1 location

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

code/control/DNRoot.php 1 location

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