| Conditions | 16 |
| Paths | 20 |
| Total Lines | 87 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | 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 |
||
| 171 | public function addWhereCondition(Builder $model, array $filters, $type = 'and', $index = 0): Builder |
||
| 172 | { |
||
| 173 | // Get key and value |
||
| 174 | $firstFilterKey = array_key_first($filters); |
||
| 175 | if ($firstFilterKey === null) { |
||
| 176 | return $model; |
||
| 177 | } |
||
| 178 | $firstFilterValue = $filters[$firstFilterKey]; |
||
| 179 | |||
| 180 | switch ($firstFilterKey) { |
||
| 181 | // if final query |
||
| 182 | case $this->queryFilterTitle: |
||
| 183 | |||
| 184 | $firstFilterInnerKey = array_key_first($filters[$firstFilterKey]); |
||
| 185 | if ($firstFilterInnerKey === null) { |
||
| 186 | return $model; |
||
| 187 | } |
||
| 188 | |||
| 189 | // if not first record and type is or |
||
| 190 | if ($type == "or" && $index > 0) { |
||
| 191 | $model = $model->orWhere([$firstFilterValue[$firstFilterInnerKey]]); |
||
| 192 | } else { |
||
| 193 | $model = $model->where([$firstFilterValue[$firstFilterInnerKey]]); |
||
| 194 | } |
||
| 195 | |||
| 196 | // Get Inner key and value |
||
| 197 | if (count($filters[$firstFilterKey])===1) { |
||
| 198 | break; |
||
| 199 | // return $model; |
||
| 200 | } |
||
| 201 | unset($filters[$firstFilterKey][$firstFilterInnerKey]); |
||
| 202 | return $this->addWhereCondition($model, $filters, $type, ++$index); |
||
| 203 | |||
| 204 | // if and |
||
| 205 | case 'and_' . $this->queryFilterTitle: |
||
| 206 | // if not first record and type is or |
||
| 207 | if ($type == "or" && $index > 0) { |
||
| 208 | $model = $model->orWhere(function (Builder $builder) use ($firstFilterValue) { |
||
| 209 | $builder = $this->addWhereCondition($builder, $firstFilterValue, 'and', 0); |
||
| 210 | return $builder; |
||
| 211 | }); |
||
| 212 | } else { |
||
| 213 | $model = $model->where(function (Builder $builder) use ($firstFilterValue) { |
||
| 214 | $builder = $this->addWhereCondition($builder, $firstFilterValue, 'and', 0); |
||
| 215 | return $builder; |
||
| 216 | }); |
||
| 217 | } |
||
| 218 | break; |
||
| 219 | |||
| 220 | // if or |
||
| 221 | case 'or_' . $this->queryFilterTitle: |
||
| 222 | // if not first record and type is or |
||
| 223 | if ($type == "or" && $index > 0) { |
||
| 224 | $model = $model->orWhere(function (Builder $builder) use ($firstFilterValue) { |
||
| 225 | $builder = $this->addWhereCondition($builder, $firstFilterValue, 'or', 0); |
||
| 226 | return $builder; |
||
| 227 | }); |
||
| 228 | } else { |
||
| 229 | $model = $model->where(function (Builder $builder) use ($firstFilterValue) { |
||
| 230 | $builder = $this->addWhereCondition($builder, $firstFilterValue, 'or', 0); |
||
| 231 | return $builder; |
||
| 232 | }); |
||
| 233 | } |
||
| 234 | break; |
||
| 235 | |||
| 236 | // if relational |
||
| 237 | default: |
||
| 238 | // if not first record and type is or |
||
| 239 | if ($type == "or" && $index > 0) { |
||
| 240 | $model = $model->orWhereHas($firstFilterKey, function (Builder $builder) use ($firstFilterValue) { |
||
| 241 | $builder = $this->addWhereCondition($builder, $firstFilterValue, 'or', 0); |
||
| 242 | return $builder; |
||
| 243 | }); |
||
| 244 | } else { |
||
| 245 | $model = $model->whereHas($firstFilterKey, function (Builder $builder) use ($firstFilterValue) { |
||
| 246 | $builder = $this->addWhereCondition($builder, $firstFilterValue, 'or', 0); |
||
| 247 | return $builder; |
||
| 248 | }); |
||
| 249 | } |
||
| 250 | break; |
||
| 251 | } |
||
| 252 | |||
| 253 | unset($filters[$firstFilterKey]); |
||
| 254 | if (count($filters)) { |
||
| 255 | return $this->addWhereCondition($model, $filters, $type, ++$index); |
||
| 256 | } |
||
| 257 | return $model; |
||
| 258 | |||
| 353 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths