| Conditions | 13 |
| Paths | 384 |
| Total Lines | 67 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 73 | public function getPager(array $criteria, $page, $limit = 10, array $sort = array()) |
||
| 74 | { |
||
| 75 | if (!isset($criteria['mode'])) { |
||
| 76 | $criteria['mode'] = 'public'; |
||
| 77 | } |
||
| 78 | |||
| 79 | $parameters = array(); |
||
| 80 | $query = $this->getRepository() |
||
| 81 | ->createQueryBuilder('p') |
||
| 82 | ->select('p, t') |
||
| 83 | ->orderBy('p.publicationDateStart', 'DESC'); |
||
| 84 | |||
| 85 | if ($criteria['mode'] == 'admin') { |
||
| 86 | $query |
||
| 87 | ->leftJoin('p.tags', 't') |
||
| 88 | ->leftJoin('p.author', 'a') |
||
| 89 | ; |
||
| 90 | } else { |
||
| 91 | $query |
||
| 92 | ->leftJoin('p.tags', 't', Join::WITH, 't.enabled = true') |
||
| 93 | ->leftJoin('p.author', 'a', Join::WITH, 'a.enabled = true') |
||
| 94 | ; |
||
| 95 | } |
||
| 96 | |||
| 97 | if (!isset($criteria['enabled']) && $criteria['mode'] == 'public') { |
||
| 98 | $criteria['enabled'] = true; |
||
| 99 | } |
||
| 100 | if (isset($criteria['enabled'])) { |
||
| 101 | $query->andWhere('p.enabled = :enabled'); |
||
| 102 | $parameters['enabled'] = $criteria['enabled']; |
||
| 103 | } |
||
| 104 | |||
| 105 | if (isset($criteria['date'], $criteria['date']['query'], $criteria['date']['params'])) { |
||
| 106 | $query->andWhere($criteria['date']['query']); |
||
| 107 | $parameters = array_merge($parameters, $criteria['date']['params']); |
||
| 108 | } |
||
| 109 | |||
| 110 | if (isset($criteria['tag'])) { |
||
| 111 | $query |
||
| 112 | ->leftJoin('p.tags', 't2') |
||
| 113 | ->andWhere('t2.slug LIKE :tag'); |
||
| 114 | $parameters['tag'] = (string) $criteria['tag']; |
||
| 115 | } |
||
| 116 | |||
| 117 | if (isset($criteria['author'])) { |
||
| 118 | if (!is_array($criteria['author']) && stristr($criteria['author'], 'NULL')) { |
||
| 119 | $query->andWhere('p.author IS '.$criteria['author']); |
||
| 120 | } else { |
||
| 121 | $query->andWhere(sprintf('p.author IN (%s)', implode((array) $criteria['author'], ','))); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | if (isset($criteria['collection']) && $criteria['collection'] instanceof CollectionInterface) { |
||
| 126 | $query->andWhere('p.collection = :collectionid'); |
||
| 127 | $parameters['collectionid'] = $criteria['collection']->getId(); |
||
|
|
|||
| 128 | } |
||
| 129 | |||
| 130 | $query->setParameters($parameters); |
||
| 131 | |||
| 132 | $pager = new Pager(); |
||
| 133 | $pager->setMaxPerPage($limit); |
||
| 134 | $pager->setQuery(new ProxyQuery($query)); |
||
| 135 | $pager->setPage($page); |
||
| 136 | $pager->init(); |
||
| 137 | |||
| 138 | return $pager; |
||
| 139 | } |
||
| 140 | |||
| 174 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.