Code Duplication    Length = 23-24 lines in 2 locations

code/control/DeployPlanDispatcher.php 1 location

@@ 173-195 (lines=23) @@
170
	 */
171
	protected function getGitPrevDeploys($project) {
172
		$redeploy = [];
173
		foreach($project->DNEnvironmentList() as $dnEnvironment) {
174
			$envName = $dnEnvironment->Name;
175
			$perEnvDeploys = [];
176
			foreach($dnEnvironment->DeployHistory() as $deploy) {
177
				$sha = $deploy->SHA;
178
179
				// Check if exists to make sure the newest deployment date is used.
180
				if(!isset($perEnvDeploys[$sha])) {
181
					$pastValue = sprintf(
182
						"%s (deployed %s)",
183
						substr($sha, 0, 8),
184
						$deploy->obj('LastEdited')->Ago()
185
					);
186
					$perEnvDeploys[$sha] = [
187
						'key' => $sha,
188
						'value' => $pastValue
189
					];
190
				}
191
			}
192
			if(!empty($perEnvDeploys)) {
193
				$redeploy[$envName] = array_values($perEnvDeploys);
194
			}
195
		}
196
		return $redeploy;
197
	}
198
}

code/control/DNRoot.php 1 location

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