| Conditions | 12 |
| Paths | 28 |
| Total Lines | 42 |
| Code Lines | 27 |
| 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 |
||
| 83 | public function getFilteredQuery() |
||
| 84 | { |
||
| 85 | $query = clone $this->queryBuilder; |
||
| 86 | $columns = &$this->requestParams['columns']; |
||
| 87 | $c = count($columns); |
||
| 88 | // Search |
||
| 89 | if (array_key_exists('search', $this->requestParams)) { |
||
| 90 | if ($value = trim($this->requestParams['search']['value'])) { |
||
| 91 | $orX = $query->expr()->orX(); |
||
| 92 | for ($i = 0; $i < $c; $i++) { |
||
| 93 | $column = &$columns[$i]; |
||
| 94 | if ($column['searchable'] == 'true') { |
||
| 95 | if (array_key_exists($column[$this->columnField], $this->columnAliases)) { |
||
| 96 | $column[$this->columnField] = $this->columnAliases[$column[$this->columnField]]; |
||
| 97 | } |
||
| 98 | $orX->add($query->expr()->like($column[$this->columnField], ':search')); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | if ($orX->count() >= 1) { |
||
| 102 | $query->andWhere($orX) |
||
| 103 | ->setParameter('search', "%{$value}%"); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | } |
||
| 107 | // Filter |
||
| 108 | for ($i = 0; $i < $c; $i++) { |
||
| 109 | $column = &$columns[$i]; |
||
| 110 | $andX = $query->expr()->andX(); |
||
| 111 | if (($column['searchable'] == 'true') && ($value = trim($column['search']['value']))) { |
||
| 112 | if (array_key_exists($column[$this->columnField], $this->columnAliases)) { |
||
| 113 | $column[$this->columnField] = $this->columnAliases[$column[$this->columnField]]; |
||
| 114 | } |
||
| 115 | $andX->add($query->expr()->eq($column[$this->columnField], ":filter_{$i}")); |
||
| 116 | $query->setParameter("filter_{$i}", $value); |
||
| 117 | } |
||
| 118 | if ($andX->count() >= 1) { |
||
| 119 | $query->andWhere($andX); |
||
| 120 | } |
||
| 121 | } |
||
| 122 | // Done |
||
| 123 | return $query; |
||
| 124 | } |
||
| 125 | |||
| 213 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..