Conditions | 13 |
Paths | 384 |
Total Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
87 | public function getPager(array $criteria, $page, $limit = 10, array $sort = []) |
||
88 | { |
||
89 | if (!isset($criteria['mode'])) { |
||
90 | $criteria['mode'] = 'public'; |
||
91 | } |
||
92 | |||
93 | $parameters = []; |
||
94 | $query = $this->getRepository() |
||
95 | ->createQueryBuilder('p') |
||
96 | ->select('p, t') |
||
97 | ->orderBy('p.publicationDateStart', 'DESC'); |
||
98 | |||
99 | if ('admin' === $criteria['mode']) { |
||
100 | $query |
||
101 | ->leftJoin('p.tags', 't') |
||
102 | ->leftJoin('p.author', 'a') |
||
103 | ; |
||
104 | } else { |
||
105 | $query |
||
106 | ->leftJoin('p.tags', 't', Join::WITH, 't.enabled = true') |
||
107 | ->leftJoin('p.author', 'a', Join::WITH, 'a.enabled = true') |
||
108 | ; |
||
109 | } |
||
110 | |||
111 | if (!isset($criteria['enabled']) && 'public' === $criteria['mode']) { |
||
112 | $criteria['enabled'] = true; |
||
113 | } |
||
114 | if (isset($criteria['enabled'])) { |
||
115 | $query->andWhere('p.enabled = :enabled'); |
||
116 | $parameters['enabled'] = $criteria['enabled']; |
||
117 | } |
||
118 | |||
119 | if (isset($criteria['date'], $criteria['date']['query'], $criteria['date']['params'])) { |
||
120 | $query->andWhere($criteria['date']['query']); |
||
121 | $parameters = array_merge($parameters, $criteria['date']['params']); |
||
122 | } |
||
123 | |||
124 | if (isset($criteria['tag'])) { |
||
125 | $query |
||
126 | ->leftJoin('p.tags', 't2') |
||
127 | ->andWhere('t2.slug LIKE :tag'); |
||
128 | $parameters['tag'] = (string) $criteria['tag']; |
||
129 | } |
||
130 | |||
131 | if (isset($criteria['author'])) { |
||
132 | if (!\is_array($criteria['author']) && stristr($criteria['author'], 'NULL')) { |
||
133 | $query->andWhere('p.author IS '.$criteria['author']); |
||
134 | } else { |
||
135 | $query->andWhere(sprintf('p.author IN (%s)', implode(',', (array) $criteria['author']))); |
||
136 | } |
||
137 | } |
||
138 | |||
139 | if (isset($criteria['collection']) && $criteria['collection'] instanceof CollectionInterface) { |
||
140 | $query->andWhere('p.collection = :collectionid'); |
||
141 | $parameters['collectionid'] = $criteria['collection']->getId(); |
||
|
|||
142 | } |
||
143 | |||
144 | $query->setParameters($parameters); |
||
145 | |||
146 | $pager = new Pager(); |
||
147 | $pager->setMaxPerPage($limit); |
||
148 | $pager->setQuery(new ProxyQuery($query)); |
||
149 | $pager->setPage($page); |
||
150 | $pager->init(); |
||
151 | |||
152 | return $pager; |
||
153 | } |
||
154 | |||
188 |
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.