Conditions | 22 |
Paths | 4752 |
Total Lines | 97 |
Code Lines | 63 |
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 |
||
102 | public function buildModelCriteria() |
||
103 | { |
||
104 | $search = CategoryQuery::create(); |
||
105 | |||
106 | /* manage translations */ |
||
107 | $this->configureI18nProcessing($search, array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM', 'META_TITLE', 'META_DESCRIPTION', 'META_KEYWORDS')); |
||
108 | |||
109 | $id = $this->getId(); |
||
|
|||
110 | |||
111 | if (!is_null($id)) { |
||
112 | $search->filterById($id, Criteria::IN); |
||
113 | } |
||
114 | |||
115 | $parent = $this->getParent(); |
||
116 | |||
117 | if (!is_null($parent)) { |
||
118 | $search->filterByParent($parent); |
||
119 | } |
||
120 | |||
121 | $current = $this->getCurrent(); |
||
122 | |||
123 | if ($current === true) { |
||
124 | $search->filterById($this->request->get("category_id")); |
||
125 | } elseif ($current === false) { |
||
126 | $search->filterById($this->request->get("category_id"), Criteria::NOT_IN); |
||
127 | } |
||
128 | |||
129 | $exclude = $this->getExclude(); |
||
130 | |||
131 | if (!is_null($exclude)) { |
||
132 | $search->filterById($exclude, Criteria::NOT_IN); |
||
133 | } |
||
134 | |||
135 | $visible = $this->getVisible(); |
||
136 | |||
137 | if ($visible !== BooleanOrBothType::ANY) { |
||
138 | $search->filterByVisible($visible ? 1 : 0); |
||
139 | } |
||
140 | |||
141 | $product = $this->getProduct(); |
||
142 | |||
143 | if ($product != null) { |
||
144 | $obj = ProductQuery::create()->findPk($product); |
||
145 | |||
146 | if ($obj != null) { |
||
147 | $search->filterByProduct($obj, Criteria::IN); |
||
148 | } |
||
149 | } |
||
150 | |||
151 | $exclude_product = $this->getExclude_product(); |
||
152 | |||
153 | if ($exclude_product != null) { |
||
154 | $obj = ProductQuery::create()->findPk($exclude_product); |
||
155 | |||
156 | if ($obj != null) { |
||
157 | $search->filterByProduct($obj, Criteria::NOT_IN); |
||
158 | } |
||
159 | } |
||
160 | |||
161 | $orders = $this->getOrder(); |
||
162 | |||
163 | foreach ($orders as $order) { |
||
164 | switch ($order) { |
||
165 | case "id": |
||
166 | $search->orderById(Criteria::ASC); |
||
167 | break; |
||
168 | case "id_reverse": |
||
169 | $search->orderById(Criteria::DESC); |
||
170 | break; |
||
171 | case "alpha": |
||
172 | $search->addAscendingOrderByColumn('i18n_TITLE'); |
||
173 | break; |
||
174 | case "alpha_reverse": |
||
175 | $search->addDescendingOrderByColumn('i18n_TITLE'); |
||
176 | break; |
||
177 | case "manual_reverse": |
||
178 | $search->orderByPosition(Criteria::DESC); |
||
179 | break; |
||
180 | case "manual": |
||
181 | $search->orderByPosition(Criteria::ASC); |
||
182 | break; |
||
183 | case "visible": |
||
184 | $search->orderByVisible(Criteria::ASC); |
||
185 | break; |
||
186 | case "visible_reverse": |
||
187 | $search->orderByVisible(Criteria::DESC); |
||
188 | break; |
||
189 | case "random": |
||
190 | $search->clearOrderByColumns(); |
||
191 | $search->addAscendingOrderByColumn('RAND()'); |
||
192 | break(2); |
||
193 | break; |
||
194 | } |
||
195 | } |
||
196 | |||
197 | return $search; |
||
198 | } |
||
199 | |||
270 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: