1 | <?php |
||
20 | trait OrderProvider |
||
21 | { |
||
22 | /** |
||
23 | * @param string $field |
||
24 | * @param mixed $value |
||
25 | * @param bool $including |
||
26 | * @return Query|$this|self |
||
27 | */ |
||
28 | public function after(string $field, $value, bool $including = false): self |
||
34 | |||
35 | /** |
||
36 | * @param string ...$fields |
||
37 | * @return Query|$this|self |
||
38 | */ |
||
39 | public function asc(string ...$fields): self |
||
47 | |||
48 | /** |
||
49 | * @param string $field |
||
50 | * @param bool $asc |
||
51 | * @return Query|$this|self |
||
52 | */ |
||
53 | 2 | public function orderBy(string $field, bool $asc = true): self |
|
54 | { |
||
55 | 2 | return $this->add(new OrderBy($this, $field, $asc)); |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * @param string $field |
||
60 | * @param mixed $value |
||
61 | * @param bool $including |
||
62 | * @return Query|$this|self |
||
63 | */ |
||
64 | public function before(string $field, $value, bool $including = false): self |
||
70 | |||
71 | /** |
||
72 | * @param string ...$fields |
||
73 | * @return Query|$this|self |
||
74 | */ |
||
75 | 2 | public function desc(string ...$fields): self |
|
76 | { |
||
77 | 2 | foreach ($fields as $field) { |
|
78 | 2 | $this->orderBy($field, false); |
|
79 | } |
||
80 | |||
81 | 2 | return $this; |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param string $field |
||
86 | * @return Query|$this|self |
||
87 | */ |
||
88 | public function latest(string $field = 'createdAt'): self |
||
92 | |||
93 | /** |
||
94 | * @param string $field |
||
95 | * @return Query|$this|self |
||
96 | */ |
||
97 | public function oldest(string $field = 'createdAt'): self |
||
101 | } |
||
102 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.