Conditions | 15 |
Paths | 289 |
Total Lines | 68 |
Code Lines | 46 |
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 |
||
70 | protected function buildCategoryTree($parent, $visible, $level, $previousLevel, $maxLevel, $exclude, &$resultsList) |
||
71 | { |
||
72 | if ($level > $maxLevel) { |
||
73 | return; |
||
74 | } |
||
75 | |||
76 | $search = CategoryQuery::create(); |
||
77 | $this->configureI18nProcessing($search, array('TITLE')); |
||
78 | |||
79 | $search->filterByParent($parent); |
||
80 | |||
81 | if ($visible !== BooleanOrBothType::ANY) { |
||
82 | $search->filterByVisible($visible); |
||
83 | } |
||
84 | |||
85 | if ($exclude != null) { |
||
86 | $search->filterById($exclude, Criteria::NOT_IN); |
||
87 | } |
||
88 | |||
89 | $orders = $this->getOrder(); |
||
90 | |||
91 | foreach ($orders as $order) { |
||
92 | switch ($order) { |
||
93 | case "position": |
||
94 | $search->orderByPosition(Criteria::ASC); |
||
95 | break; |
||
96 | case "position_reverse": |
||
97 | $search->orderByPosition(Criteria::DESC); |
||
98 | break; |
||
99 | case "id": |
||
100 | $search->orderById(Criteria::ASC); |
||
101 | break; |
||
102 | case "id_reverse": |
||
103 | $search->orderById(Criteria::DESC); |
||
104 | break; |
||
105 | case "alpha": |
||
106 | $search->addAscendingOrderByColumn('i18n_TITLE'); |
||
107 | break; |
||
108 | case "alpha_reverse": |
||
109 | $search->addDescendingOrderByColumn('i18n_TITLE'); |
||
110 | break; |
||
111 | } |
||
112 | } |
||
113 | |||
114 | $results = $search->find(); |
||
115 | |||
116 | $needCountChild = $this->getNeedCountChild(); |
||
117 | |||
118 | foreach ($results as $result) { |
||
119 | $row = array( |
||
120 | "ID" => $result->getId(), |
||
121 | "TITLE" => $result->getVirtualColumn('i18n_TITLE'), |
||
122 | "PARENT" => $result->getParent(), |
||
123 | "URL" => $this->getReturnUrl() ? $result->getUrl($this->locale) : null, |
||
124 | "VISIBLE" => $result->getVisible() ? "1" : "0", |
||
125 | "LEVEL" => $level, |
||
126 | 'PREV_LEVEL' => $previousLevel, |
||
127 | ); |
||
128 | |||
129 | if ($needCountChild) { |
||
130 | $row['CHILD_COUNT'] = $result->countChild(); |
||
131 | } |
||
132 | |||
133 | $resultsList[] = $row; |
||
134 | |||
135 | $this->buildCategoryTree($result->getId(), $visible, 1 + $level, $level, $maxLevel, $exclude, $resultsList); |
||
136 | } |
||
137 | } |
||
138 | |||
166 |