Conditions | 21 |
Paths | 8103 |
Total Lines | 185 |
Code Lines | 110 |
Lines | 0 |
Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
172 | function getMetadataCompareTable(&$sthToImport) { |
||
173 | $html = ''; |
||
174 | |||
175 | // True if there is sth to import in dst project. |
||
176 | $sthToImport = false; |
||
177 | |||
178 | // For source project, only get the 'Used' metadata. |
||
179 | $srcMdFactory = new Docman_MetadataFactory($this->srcGo->getGroupId()); |
||
180 | $srcMdIter = $srcMdFactory->getMetadataForGroup(true); |
||
181 | |||
182 | // For destination (current) project, get all metadata. |
||
183 | $dstMdFactory = new Docman_MetadataFactory($this->dstGo->getGroupId()); |
||
184 | $dstMdIter = $dstMdFactory->getMetadataForGroup(); |
||
185 | $dstMdArray = $this->getArrayFromIterator($dstMdIter, 'getLabel'); |
||
186 | |||
187 | // Get mapping between the 2 definitions |
||
188 | $mdMap = array(); |
||
189 | $srcMdFactory->getMetadataMapping($this->dstGo->getGroupId(), $mdMap); |
||
190 | |||
191 | $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_desc', array($this->dstGo->getPublicName(), $this->srcGo->getPublicName())); |
||
192 | |||
193 | // Table |
||
194 | $html .= "<table border=\"1\">\n"; |
||
195 | |||
196 | $html .= "<tr>\n"; |
||
197 | $html .= "<th colspan=\"2\">".$GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_prop')."</th>\n"; |
||
198 | $html .= "<th>".$this->srcGo->getPublicName()."</th>\n"; |
||
199 | $html .= "<th>".$this->dstGo->getPublicName()."</th>\n"; |
||
200 | $html .= "<th>".$GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_diff', array($this->dstGo->getPublicName(), $this->srcGo->getPublicName()))."</th>\n"; |
||
201 | $html .= "<th>".$GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_action', array($this->dstGo->getPublicName()))."</th>\n"; |
||
202 | $html .= "</tr>\n"; |
||
203 | |||
204 | // Keep a trace of metadata that matched in the dst metadata list. |
||
205 | $matchingMd = array(); |
||
206 | $srcMdIter->rewind(); |
||
207 | while($srcMdIter->valid()) { |
||
208 | $srcMd = $srcMdIter->current(); |
||
209 | $dstMd = null; |
||
210 | |||
211 | // |
||
212 | // Compute the differences between the 2 projects |
||
213 | // |
||
214 | $dstMdStatus = 'missing'; |
||
215 | $dstMdLabel = ''; |
||
216 | if($srcMdFactory->isRealMetadata($srcMd->getLabel())) { |
||
217 | if(isset($mdMap['md'][$srcMd->getId()])) { |
||
218 | $dstMdLabel = $srcMdFactory->getLabelFromId($mdMap['md'][$srcMd->getId()]); |
||
219 | } |
||
220 | } else { |
||
221 | $dstMdLabel = $srcMd->getLabel(); |
||
222 | } |
||
223 | |||
224 | if(isset($dstMdArray[$dstMdLabel])) { |
||
225 | $dstMd = $dstMdArray[$dstMdLabel]; |
||
226 | if($dstMd !== false) { |
||
227 | $matchingMd[$dstMdLabel] = true; |
||
228 | $dstMdStatus = 'equivalent'; |
||
229 | if($dstMd->equals($srcMd)) { |
||
230 | $dstMdStatus = 'equals'; |
||
231 | } else { |
||
232 | $sthToImport = true; |
||
233 | } |
||
234 | } else { |
||
235 | $sthToImport = true; |
||
236 | } |
||
237 | } else { |
||
238 | // The metadata is not in the metadata map list, check if it's |
||
239 | // not a name conflict |
||
240 | $dstMdi = $dstMdFactory->findByName($srcMd->getName()); |
||
241 | if ($dstMdi->count() == 1) { |
||
242 | $dstMdStatus = 'conflict'; |
||
243 | } else { |
||
244 | $sthToImport = true; |
||
245 | } |
||
246 | } |
||
247 | |||
248 | |||
249 | // |
||
250 | // Display result |
||
251 | // |
||
252 | $html .= "<tr>\n"; |
||
253 | |||
254 | // Property |
||
255 | $html .= "<td colspan=\"2\" style=\"font-weight: bold;\">"; |
||
256 | $html .= $srcMd->getName(); |
||
257 | $html .= "</td>"; |
||
258 | |||
259 | // Presence in source project |
||
260 | $html .= "<td align=\"center\">"; |
||
261 | $html .= '<img src="'.$this->docmanIcons->getThemeIcon('tick.png').'" />'; |
||
262 | $html .= "</td>"; |
||
263 | |||
264 | // Presence in destination project |
||
265 | $html .= "<td align=\"center\">"; |
||
266 | switch($dstMdStatus) { |
||
267 | case 'equals': |
||
268 | case 'equivalent': |
||
269 | $html .= '<img src="'.$this->docmanIcons->getThemeIcon('tick.png').'" />'; |
||
270 | break; |
||
271 | } |
||
272 | $html .= "</td>"; |
||
273 | |||
274 | // Differences |
||
275 | $html .= "<td class=\"docman_md_".$dstMdStatus."\">"; |
||
276 | switch($dstMdStatus) { |
||
277 | case 'equivalent': |
||
278 | case 'missing': |
||
279 | case 'conflict': |
||
280 | $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_status_'.$dstMdStatus); |
||
281 | break; |
||
282 | } |
||
283 | $html .= "</td>"; |
||
284 | |||
285 | // Action |
||
286 | $html .= "<td>"; |
||
287 | switch($dstMdStatus) { |
||
288 | case 'equals': |
||
289 | // Nothing to do |
||
290 | break; |
||
291 | case 'equivalent': |
||
292 | $diffArray = $this->checkMdDifferences($srcMd, $dstMd, $mdMap['love']); |
||
293 | $diffStr = '<ul style="padding:0;padding-left:1.5em;margin:0;"><li>'; |
||
294 | $diffStr .= implode('</li><li>', $diffArray); |
||
295 | $diffStr .= '</li></ul>'; |
||
296 | |||
297 | $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_act_update_md', array($srcMd->getName(), $this->dstGo->getPublicName(), $diffStr)); |
||
298 | break; |
||
299 | case 'missing': |
||
300 | $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_act_import_md', array($srcMd->getName())); |
||
301 | break; |
||
302 | case 'conflict': |
||
303 | $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_act_conflict'); |
||
304 | break; |
||
305 | } |
||
306 | $html .= "</td>"; |
||
307 | |||
308 | $html .= "</tr>\n"; |
||
309 | |||
310 | // |
||
311 | // List of values |
||
312 | // |
||
313 | if($srcMd->getType() == PLUGIN_DOCMAN_METADATA_TYPE_LIST) { |
||
314 | if($dstMd !== null) { |
||
315 | $html .= $this->getLoveCompareTable($srcMd, $dstMd, $mdMap, $sthToImport); |
||
316 | } |
||
317 | } |
||
318 | |||
319 | unset($dstMd); |
||
320 | $srcMdIter->next(); |
||
321 | } |
||
322 | |||
323 | // Append to the table the metadata in the dst project that where not |
||
324 | // present in the src project. |
||
325 | foreach($dstMdArray as $md) { |
||
326 | if(!isset($matchingMd[$md->getLabel()])) { |
||
327 | $html .= "<tr>\n"; |
||
328 | |||
329 | // Name |
||
330 | $html .= "<td colspan=\"2\" style=\"font-weight: bold;\">"; |
||
331 | $html .= $md->getName(); |
||
332 | $html .= "</td>"; |
||
333 | |||
334 | // Presence in source project |
||
335 | $html .= "<td></td>"; |
||
336 | |||
337 | // Presence in destination project |
||
338 | $html .= "<td align=\"center\">"; |
||
339 | $html .= '<img src="'.$this->docmanIcons->getThemeIcon('tick.png').'" />'; |
||
340 | $html .= "</td>"; |
||
341 | |||
342 | // Differences |
||
343 | $html .= "<td></td>"; |
||
344 | |||
345 | // Action |
||
346 | $html .= "<td></td>"; |
||
347 | |||
348 | $html .= "</td>"; |
||
349 | $html .= "</tr>\n"; |
||
350 | } |
||
351 | } |
||
352 | |||
353 | $html .= "</table>\n"; |
||
354 | |||
355 | return $html; |
||
356 | } |
||
357 | } |
||
360 |