Completed
Push — master ( 743367...2eb0ee )
by Gabriel
06:30
created

Categories::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Waredesk;
4
5
use Waredesk\Mappers\CategoriesMapper;
6
use Waredesk\Mappers\CategoryMapper;
7
use Waredesk\Models\Category;
8
9
class Categories extends Controller
10
{
11
    private const ENDPOINT = '/v1-alpha/categories';
12
13 1
    public function create(Category $category): Category
14
    {
15 1
        return $this->doCreate(
16 1
            self::ENDPOINT,
17
            $category,
18
            function ($response) use ($category) {
19 1
                return (new CategoryMapper())->map($category, $response);
20 1
            }
21
        );
22
    }
23
24
    public function delete(Category $category): bool
25
    {
26
        $this->validateIsNotNewEntity($category->getId());
27
        return $this->doDelete(self::ENDPOINT."/{$category->getId()}");
28
    }
29
30 4
    public function fetch(string $orderBy = null, string $order = self::ORDER_BY_ASC, int $limit = null): Collections\Categories
31
    {
32 4
        return $this->doFetch(
33 4
            self::ENDPOINT,
34
            $orderBy,
35
            $order,
36
            $limit,
37
            function ($response) {
38 4
                return (new CategoriesMapper())->map(new Collections\Categories(), $response);
39 4
            }
40
        );
41
    }
42
43
    public function fetchOne(string $orderBy = null, string $order = self::ORDER_BY_ASC): ? Category
44
    {
45
        return $this->doFetchOne(
46
            self::ENDPOINT,
47
            $orderBy,
48
            $order,
49
            function ($response) {
50
                return (new CategoriesMapper())->map(new Collections\Categories(), $response);
51
            }
52
        );
53
    }
54
55
    public function findOneBy(array $criteria, string $orderBy = null, string $order = self::ORDER_BY_ASC): ? Category
56
    {
57
        return $this->doFindOneBy(
58
            self::ENDPOINT,
59
            $criteria,
60
            $orderBy,
61
            $order,
62
            function ($response) {
63
                return (new CategoriesMapper())->map(new Collections\Categories(), $response);
64
            }
65
        );
66
    }
67
}
68