| Conditions | 10 |
| Paths | 160 |
| Total Lines | 49 |
| Code Lines | 35 |
| 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 |
||
| 61 | public function get($filter = self::FILTER_ALL, $state = self::STATE_ACTIVE, $type = self::TYPE_ALL) |
||
| 62 | { |
||
| 63 | $qb = $this->getEntityManager()->createQueryBuilder() |
||
| 64 | ->select('t') |
||
| 65 | ->from('ZikulaThemeModule:ThemeEntity', 't'); |
||
| 66 | |||
| 67 | if ($state != self::STATE_ALL) { |
||
| 68 | $qb->andWhere('t.state = :state') |
||
| 69 | ->setParameter('state', $state); |
||
| 70 | } |
||
| 71 | if ($type != self::TYPE_ALL) { |
||
| 72 | $qb->andWhere('t.type = :type') |
||
| 73 | ->setParameter('type', $type); |
||
| 74 | } |
||
| 75 | switch ($filter) { |
||
| 76 | case self::FILTER_USER: |
||
| 77 | $qb->andWhere('t.user = 1'); |
||
| 78 | break; |
||
| 79 | case self::FILTER_SYSTEM: |
||
| 80 | $qb->andWhere('t.system = 1'); |
||
| 81 | break; |
||
| 82 | case self::FILTER_ADMIN: |
||
| 83 | $qb->andWhere('t.admin = 1'); |
||
| 84 | break; |
||
| 85 | } |
||
| 86 | |||
| 87 | $qb->orderBy('t.displayname', 'ASC'); |
||
| 88 | $query = $qb->getQuery(); |
||
| 89 | |||
| 90 | /** @var $result ThemeEntity[] */ |
||
| 91 | $result = $query->getResult(); |
||
| 92 | $themesArray = []; |
||
| 93 | foreach ($result as $theme) { |
||
| 94 | $themesArray[$theme->getName()]= $theme->toArray(); |
||
| 95 | $kernel = $this->getKernel(); // allow to throw exception outside the try/catch block |
||
| 96 | try { |
||
| 97 | $themeBundle = $kernel->getTheme($theme['name']); |
||
| 98 | } catch (\Exception $e) { |
||
| 99 | $themeBundle = null; |
||
| 100 | } |
||
| 101 | $themesArray[$theme['name']]['vars'] = isset($themeBundle) ? $themeBundle->getThemeVars() : false; |
||
| 102 | } |
||
| 103 | |||
| 104 | if (!$themesArray) { |
||
|
|
|||
| 105 | return false; |
||
| 106 | } |
||
| 107 | |||
| 108 | return $themesArray; |
||
| 109 | } |
||
| 110 | |||
| 123 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.