| Conditions | 10 |
| Paths | 12 |
| Total Lines | 22 |
| Code Lines | 15 |
| 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 |
||
| 59 | public function getCatTitles($cats = null) |
||
| 60 | { |
||
| 61 | $catTitles = []; |
||
| 62 | $criteria = new \CriteriaCompo(); |
||
| 63 | if (isset($cats) && is_array($cats)) { |
||
| 64 | $catIdString = !empty($cats) ? '(' . implode(',', $cats) . ')' : ''; |
||
| 65 | if ($catIdString) { |
||
| 66 | $criteria->add(new \Criteria('cid', $catIdString, 'IN')); |
||
| 67 | } |
||
| 68 | } elseif (isset($cats) && ((int)$cats > 0)) { |
||
| 69 | $criteria->add(new \Criteria('cid', (int)$cats, '=')); |
||
| 70 | } |
||
| 71 | $catFields = ['title']; |
||
| 72 | $categoryArray = $this->getAll($criteria, $catFields, false); |
||
| 73 | $catTitles = []; |
||
| 74 | if (is_array($categoryArray) && count($categoryArray)) { |
||
| 75 | foreach ($categoryArray as $catItem) { |
||
| 76 | $catTitles[$catItem['cid']] = $catItem['title']; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | return $catTitles; |
||
| 81 | } |
||
| 92 |