Test Failed
Push — master ( b021d0...538ee6 )
by Yunus Emre
03:51
created

ProductRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
dl 0
loc 53
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A sortById() 0 3 1
A sortByName() 0 3 1
A findByCode() 0 5 1
A includeCategory() 0 5 1
A createMeta() 0 3 1
A findByName() 0 5 1
1
<?php
2
3
namespace TarfinLabs\Parasut\Repositories;
4
5
use TarfinLabs\Parasut\Models\Product;
6
use TarfinLabs\Parasut\Repositories\Meta\BaseMeta;
7
use TarfinLabs\Parasut\Repositories\Meta\ProductMeta;
8
9
class ProductRepository extends BaseRepository
10
{
11
    protected string $endpoint = 'products';
12
    protected string $model = Product::class;
13
14
    // region Sorts
15
16
    public function sortById(bool $descending = false): self
17
    {
18
        return $this->sortByAttribute('id', $descending);
19
    }
20
21
    public function sortByName(bool $descending = false): self
22
    {
23
        return $this->sortByAttribute('name', $descending);
24
    }
25
26
    // endregion
27
28
    // region Filters
29
30
    public function findByName(string $name): self
31
    {
32
        $this->filters['name'] = $name;
33
34
        return $this;
35
    }
36
37
    public function findByCode(string $code): self
38
    {
39
        $this->filters['code'] = $code;
40
41
        return $this;
42
    }
43
44
    // endregion
45
46
    // region Includes
47
48
    public function includeCategory(): self
49
    {
50
        $this->includes[] = 'category';
51
52
        return $this;
53
    }
54
55
    // endregion
56
57
    // region Meta
58
59
    protected static function createMeta(array $meta): BaseMeta
60
    {
61
        return new ProductMeta($meta);
62
    }
63
64
    // endregion
65
}
66