| Conditions | 11 |
| Paths | 216 |
| Total Lines | 43 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 2 | 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 |
||
| 170 | public function getQuery() |
||
| 171 | { |
||
| 172 | $dbQuery = $this->serviceManager->get('query'); |
||
| 173 | $criteria = $dbQuery->criteria(); |
||
| 174 | |||
| 175 | /** @var \Zend\Http\Request $request */ |
||
| 176 | $request = $this->getController()->getRequest(); |
||
| 177 | $query = $request->getQuery()->toArray(); |
||
| 178 | |||
| 179 | foreach ($this->propertiesMap as $name => $criterion) { |
||
| 180 | if (is_numeric($name)) { |
||
| 181 | $name = $criterion; |
||
| 182 | $criterion = "startsWith"; |
||
| 183 | } |
||
| 184 | $queryName = $this->queryKeysLowercased ? strtolower($name) : $name; |
||
| 185 | |||
| 186 | if (isset($query[$queryName])) { |
||
| 187 | $criteria->$criterion($name, $query[$queryName]); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | $dbQuery->condition($criteria); |
||
| 191 | $pageParamName = $this->queryKeysLowercased ? strtolower($this->getPageParamName()) : $this->getPageParamName(); |
||
| 192 | $page = $request->getQuery($pageParamName, 1); |
||
| 193 | $itemsPerPage = $this->getItemsPerPage(); |
||
| 194 | $dbQuery->page($page, $itemsPerPage); |
||
| 195 | |||
| 196 | $sortParamName = $this->queryKeysLowercased ? strtolower($this->getSortParamName()) : $this->getSortParamName(); |
||
| 197 | if (isset($query[$sortParamName])) { |
||
| 198 | $sort = $query[$sortParamName]; |
||
| 199 | } else { |
||
| 200 | reset($this->propertiesMap); |
||
| 201 | list ($key, $val) = each($this->propertiesMap); |
||
| 202 | $sort = is_numeric($key) ? $val : $key; |
||
| 203 | } |
||
| 204 | foreach (explode(',', $sort) as $s) { |
||
| 205 | if ("-" == $s{0}) { |
||
| 206 | $dbQuery->sort(substr($s, 1), false); |
||
| 207 | } else { |
||
| 208 | $dbQuery->sort($s); |
||
| 209 | } |
||
| 210 | } |
||
| 211 | return $dbQuery; |
||
| 212 | } |
||
| 213 | |||
| 223 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.