ProductRepository::findByName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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