Code Duplication    Length = 23-24 lines in 2 locations

code/control/DeployPlanDispatcher.php 1 location

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

code/control/DNRoot.php 1 location

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