| Conditions | 10 |
| Paths | 13 |
| Total Lines | 33 |
| Code Lines | 22 |
| 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 |
||
| 22 | public function filter(ProxyQueryInterface $proxyQuery, $alias, $field, $data) |
||
| 23 | { |
||
| 24 | if (!$data || !is_array($data) || !array_key_exists('value', $data)) { |
||
| 25 | return; |
||
| 26 | } |
||
| 27 | |||
| 28 | $data['value'] = trim($data['value']); |
||
| 29 | $data['type'] = empty($data['type']) ? ChoiceType::TYPE_CONTAINS : $data['type']; |
||
| 30 | |||
| 31 | if (strlen($data['value']) == 0) { |
||
| 32 | return; |
||
| 33 | } |
||
| 34 | |||
| 35 | $where = $this->getWhere($proxyQuery); |
||
|
|
|||
| 36 | |||
| 37 | switch ($data['type']) { |
||
| 38 | case ChoiceType::TYPE_EQUAL: |
||
| 39 | $where->eq()->field('a.'.$field)->literal($data['value']); |
||
| 40 | break; |
||
| 41 | case ChoiceType::TYPE_NOT_CONTAINS: |
||
| 42 | $where->fullTextSearch('a.'.$field, '* -'.$data['value']); |
||
| 43 | break; |
||
| 44 | case ChoiceType::TYPE_CONTAINS: |
||
| 45 | $where->like()->field('a.'.$field)->literal('%'.$data['value'].'%'); |
||
| 46 | break; |
||
| 47 | case ChoiceType::TYPE_CONTAINS_WORDS: |
||
| 48 | default: |
||
| 49 | $where->fullTextSearch('a.'.$field, $data['value']); |
||
| 50 | } |
||
| 51 | |||
| 52 | // filter is active as we have now modified the query |
||
| 53 | $this->active = true; |
||
| 54 | } |
||
| 55 | |||
| 78 |
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.