| Conditions | 12 |
| Paths | 432 |
| Total Lines | 44 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 16 | public static function buildMenu(array $data = array(), DocumentParser $modx, $_DL, prepare_DL_Extender $_eDL) |
||
| 17 | { |
||
| 18 | $params = $_DL->getCFGDef('params', array()); |
||
| 19 | if ($_DL->getCfgDef('currentDepth', 1) < $_DL->getCFGDef('maxDepth', 5)) { |
||
| 20 | $params['currentDepth'] = $_DL->getCfgDef('currentDepth', 1) + 1; |
||
| 21 | $params['parents'] = $data['id']; |
||
| 22 | $params['idType'] = 'parents'; |
||
| 23 | $params['documents'] = ''; |
||
| 24 | $data['dl.submenu'] = ($data['isfolder']) ? $modx->runSnippet('DLBuildMenu', $params) : ''; |
||
| 25 | } else { |
||
| 26 | $data['dl.submenu'] = ''; |
||
| 27 | } |
||
| 28 | $data['dl.currentDepth'] = $_DL->getCfgDef('currentDepth', 1); |
||
| 29 | |||
| 30 | if (($parentIDs = $_eDL->getStore('parentIDs')) === null) { |
||
| 31 | $parentIDs = array_values($modx->getParentIds($modx->documentObject['id'])); |
||
| 32 | $_eDL->setStore('parentIDs', $parentIDs); |
||
| 33 | } |
||
| 34 | $isActive = ((is_array($parentIDs) && in_array($data['id'], |
||
| 35 | $parentIDs)) || $data['id'] == $modx->documentObject['id']); |
||
| 36 | $activeClass = $_DL->getCfgDef('activeClass', 'active'); |
||
| 37 | if ($isActive) { |
||
| 38 | $data['dl.class'] .= ' ' . $activeClass; |
||
| 39 | } |
||
| 40 | |||
| 41 | if (strpos($data['dl.class'], 'current') !== false && strpos($data['dl.class'], |
||
| 42 | ' ' . $activeClass) === false |
||
| 43 | ) { |
||
| 44 | $data['dl.class'] = str_replace('current', 'current ' . $activeClass, $data['dl.class']); |
||
| 45 | } |
||
| 46 | |||
| 47 | $tpl = empty($data['dl.submenu']) ? 'noChildrenRowTPL' : 'mainRowTpl'; |
||
| 48 | |||
| 49 | $_DL->renderTPL = $_DL->getCfgDef($tpl); |
||
| 50 | if (strpos($data['dl.class'], 'current') !== false) { |
||
| 51 | $_DL->renderTPL = $_DL->getCfgDef('TplCurrent', $_DL->renderTPL); |
||
| 52 | $_DL->renderTPL = $_DL->getCfgDef('TplCurrent' . $data['dl.currentDepth'], $_DL->renderTPL); |
||
| 53 | if (empty($data['dl.submenu'])) { |
||
| 54 | $_DL->renderTPL = $_DL->getCfgDef('TplCurrentNoChildren' . $data['dl.currentDepth'], |
||
| 55 | $_DL->renderTPL); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | return $data; |
||
| 60 | } |
||
| 127 |