Passed
Push — master ( f0e277...a14668 )
by Rougin
03:58
created

Order   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 16
dl 0
loc 70
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A set() 0 5 1
A ascending() 0 5 1
A __call() 0 3 1
A descending() 0 5 1
A __construct() 0 7 1
1
<?php
2
3
namespace Rougin\Windstorm\Eloquent;
4
5
use Illuminate\Database\Eloquent\Builder;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\Builder 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...
6
use Rougin\Windstorm\OrderInterface;
7
8
/**
9
 * Order Query
10
 *
11
 * @package Windstorm
12
 * @author  Rougin Gutib <[email protected]>
13
 */
14
class Order implements OrderInterface
15
{
16
    protected $key;
17
18
    protected $builder;
19
20
    protected $order = 'asc';
21
22
    protected $query;
23
24
    public function __construct(Query $query, Builder $builder, $key)
25
    {
26
        $this->query = $query;
27
28
        $this->builder = $builder;
29
30
        $this->key = $key;
31
    }
32
33
    /**
34
     * Sets the order in ascending.
35
     *
36
     * @return \Rougin\Windstorm\QueryInterface
37
     */
38
    public function ascending()
39
    {
40
        $this->order = 'asc';
41
42
        return $this;
43
    }
44
45
    /**
46
     * Sets the order in descending.
47
     *
48
     * @return \Rougin\Windstorm\QueryInterface
49
     */
50
    public function descending()
51
    {
52
        $this->order = 'desc';
53
54
        return $this;
55
    }
56
57
    /**
58
     * Calls a method from a QueryInterface instance.
59
     *
60
     * @param  string $method
61
     * @param  array  $parameters
62
     * @return \Rougin\Windstorm\QueryInterface
63
     */
64
    public function __call($method, $parameters)
65
    {
66
        return call_user_func_array(array($this->set(), $method), $parameters);
67
    }
68
69
    /**
70
     * Calls a __toString() from a QueryInterface instance.
71
     *
72
     * @return string
73
     */
74
    public function __toString()
75
    {
76
        return $this->set()->__toString();
77
    }
78
79
    protected function set()
80
    {
81
        $this->builder = $this->builder->orderBy($this->key, $this->order);
82
83
        return $this->query->builder($this->builder);
84
    }
85
}
86