OrderBy::condition()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Created by enea dhack - 19/06/2020 21:09.
4
 */
5
6
namespace Vaened\Searcher\Constraints;
7
8
use Illuminate\Database\Eloquent\Builder;
9
use Vaened\Searcher\Constraint;
10
use Vaened\Searcher\Keywords\OrderDirection;
0 ignored issues
show
Bug introduced by
The type Vaened\Searcher\Keywords\OrderDirection was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
class OrderBy implements Constraint
13
{
14
    private string $column;
15
16
    private ?OrderDirection $direction;
17
18
    public function __construct(string $column, ?OrderDirection $direction = null)
19
    {
20
        $this->column = $column;
21
        $this->direction = $direction;
22
    }
23
24
    public function condition(Builder $builder): Builder
25
    {
26
        return $builder->orderBy($this->column, $this->direction ?: OrderDirection::DESC);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $builder->orderBy...s\OrderDirection::DESC) could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
27
    }
28
}
29