ProductRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 13.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
dl 0
loc 53
ccs 2
cts 15
cp 0.1333
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\Enums\ResourceNames;
6
use TarfinLabs\Parasut\Models\Product;
7
use TarfinLabs\Parasut\Repositories\Meta\BaseMeta;
8
use TarfinLabs\Parasut\Repositories\Meta\ProductMeta;
9
10
class ProductRepository extends BaseRepository
11
{
12
    protected string $endpoint = ResourceNames::PRODUCT;
13
    protected string $model = Product::class;
14
15
    // region Sorts
16
17
    public function sortById(bool $descending = false): self
18
    {
19
        return $this->sortByAttribute('id', $descending);
20
    }
21
22
    public function sortByName(bool $descending = false): self
23
    {
24
        return $this->sortByAttribute('name', $descending);
25
    }
26
27
    // endregion
28
29
    // region Filters
30
31
    public function findByName(string $name): self
32
    {
33
        $this->filters['name'] = $name;
34
35
        return $this;
36
    }
37
38
    public function findByCode(string $code): self
39
    {
40
        $this->filters['code'] = $code;
41
42
        return $this;
43
    }
44
45
    // endregion
46
47
    // region Includes
48
49
    public function includeCategory(): self
50
    {
51
        $this->includes[] = 'category';
52
53
        return $this;
54
    }
55
56
    // endregion
57
58
    // region Meta
59
60 1
    protected static function createMeta(array $meta): BaseMeta
61
    {
62 1
        return new ProductMeta($meta);
63
    }
64
65
    // endregion
66
}
67