AuthorCollection::sortBy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Leonidas\Library\System\Model\Author;
6
7
use Leonidas\Contracts\System\Model\Author\AuthorCollectionInterface;
8
use Leonidas\Contracts\System\Model\Author\AuthorInterface;
9
use Leonidas\Library\System\Model\Abstracts\AbstractModelCollection;
10
use Leonidas\Library\System\Model\Abstracts\PoweredByModelCollectionKernelTrait;
11
12
class AuthorCollection extends AbstractModelCollection implements AuthorCollectionInterface
13
{
14
    use PoweredByModelCollectionKernelTrait;
15
16
    public function __construct(AuthorInterface ...$authors)
17
    {
18
        $this->initKernel($authors);
19
    }
20
21
    public function collect(AuthorInterface ...$authors): void
22
    {
23
        $this->kernel->collect($authors);
24
    }
25
26
    public function add(AuthorInterface $author): void
27
    {
28
        $this->kernel->insert($author);
29
    }
30
31
    public function hasWithId(int ...$id): bool
32
    {
33
        return $this->kernel->hasWhere('id', 'in', $id);
34
    }
35
36
    public function hasWith(string $property, ...$values): bool
37
    {
38
        return $this->kernel->hasWhere($property, 'in', $values);
39
    }
40
41
    public function hasWhere(string $property, string $operator, $value): bool
42
    {
43
        return $this->kernel->hasWhere($property, $operator, $value);
44
    }
45
46
    public function matches(AuthorCollectionInterface $authors): bool
47
    {
48
        return $this->kernel->matches($authors->toArray());
49
    }
50
51
    public function getById(int $id): ?AuthorInterface
52
    {
53
        return $this->kernel->firstWhere('id', '=', $id);
54
    }
55
56
    public function getByEmail(string $email): ?AuthorInterface
57
    {
58
        return $this->kernel->firstWhere('email', '=', $email);
59
    }
60
61
    public function getByLogin(string $login): ?AuthorInterface
62
    {
63
        return $this->kernel->firstWhere('login', '=', $login);
64
    }
65
66
    public function getByNicename(string $nicename): ?AuthorInterface
67
    {
68
        return $this->kernel->firstWhere('nicename', '=', $nicename);
69
    }
70
71
    public function getBy(string $property, $value): ?AuthorInterface
72
    {
73
        return $this->kernel->firstWhere($property, '=', $value);
74
    }
75
76
    public function firstWhere(string $property, string $operator, $value): ?AuthorInterface
77
    {
78
        return $this->kernel->firstWhere($property, $operator, $value);
79
    }
80
81
    public function first(): ?AuthorInterface
82
    {
83
        return $this->kernel->first();
84
    }
85
86
    public function last(): ?AuthorInterface
87
    {
88
        return $this->kernel->last();
89
    }
90
91
    public function withId(int ...$id): AuthorCollection
92
    {
93
        return $this->kernel->where('id', 'in', $id);
94
    }
95
96
    public function withoutId(int ...$id): AuthorCollection
97
    {
98
        return $this->kernel->where('id', 'not in', $id);
99
    }
100
101
    public function with(string $property, ...$values): AuthorCollection
102
    {
103
        return $this->kernel->where($property, 'in', $values);
104
    }
105
106
    public function without(string $property, ...$values): AuthorCollection
107
    {
108
        return $this->kernel->where($property, 'not in', $values);
109
    }
110
111
    public function where(string $property, string $operator, $value): AuthorCollection
112
    {
113
        return $this->kernel->where($property, $operator, $value);
114
    }
115
116
    public function filter(callable $callback): AuthorCollection
117
    {
118
        return $this->kernel->filter($callback);
119
    }
120
121
    public function diff(AuthorCollectionInterface ...$authors): AuthorCollection
122
    {
123
        return $this->kernel->diff(...$this->expose(...$authors));
124
    }
125
126
    public function contrast(AuthorCollectionInterface ...$authors): AuthorCollection
127
    {
128
        return $this->kernel->contrast(...$this->expose(...$authors));
129
    }
130
131
    public function intersect(AuthorCollectionInterface ...$authors): AuthorCollection
132
    {
133
        return $this->kernel->intersect(...$this->expose(...$authors));
134
    }
135
136
    public function merge(AuthorCollectionInterface ...$authors): AuthorCollection
137
    {
138
        return $this->kernel->merge(...$this->expose(...$authors));
139
    }
140
141
    public function sortBy(string $property, string $order = 'asc'): AuthorCollection
142
    {
143
        return $this->kernel->sortBy($property, $order);
144
    }
145
146
    public function sortMapped(array $map, string $property, string $order = 'asc'): AuthorCollection
147
    {
148
        return $this->kernel->sortMapped($map, $property, $order);
149
    }
150
151
    public function sortCustom(callable $callback, string $order = 'asc'): AuthorCollection
152
    {
153
        return $this->kernel->sortCustom($callback, $order);
154
    }
155
}
156