| Conditions | 11 |
| Paths | 13 |
| Total Lines | 32 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 24 | public function filter(ProxyQueryInterface $proxyQuery, $alias, $field, $data) |
||
| 25 | { |
||
| 26 | if (!$data || !is_array($data) || !array_key_exists('value', $data) || !is_numeric($data['value'])) { |
||
| 27 | return; |
||
| 28 | } |
||
| 29 | |||
| 30 | $type = isset($data['type']) ? $data['type'] : false; |
||
| 31 | $where = $this->getWhere($proxyQuery); |
||
|
|
|||
| 32 | |||
| 33 | $value = $data['value']; |
||
| 34 | |||
| 35 | switch ($type) { |
||
| 36 | case NumberType::TYPE_GREATER_EQUAL: |
||
| 37 | $where->gte()->field('a.'.$field)->literal($value); |
||
| 38 | break; |
||
| 39 | case NumberType::TYPE_GREATER_THAN: |
||
| 40 | $where->gt()->field('a.'.$field)->literal($value); |
||
| 41 | break; |
||
| 42 | case NumberType::TYPE_LESS_EQUAL: |
||
| 43 | $where->lte()->field('a.'.$field)->literal($value); |
||
| 44 | break; |
||
| 45 | case NumberType::TYPE_LESS_THAN: |
||
| 46 | $where->lt()->field('a.'.$field)->literal($value); |
||
| 47 | break; |
||
| 48 | case NumberType::TYPE_EQUAL: |
||
| 49 | default: |
||
| 50 | $where->eq()->field('a.'.$field)->literal($value); |
||
| 51 | } |
||
| 52 | |||
| 53 | // filter is active as we have now modified the query |
||
| 54 | $this->active = true; |
||
| 55 | } |
||
| 56 | |||
| 77 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.