Completed
Push — master ( 2eb0ee...664b37 )
by Gabriel
02:30
created

Items   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 5
dl 0
loc 70
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 10 1
A batchCreate() 0 10 1
A delete() 0 5 1
A fetch() 0 12 1
A fetchOne() 0 11 1
A findOneBy() 0 12 1
1
<?php
2
3
namespace Waredesk\Inventory;
4
5
use Waredesk\Controller;
6
use Waredesk\Mappers\Inventory\ItemMapper;
7
use Waredesk\Mappers\Inventory\ItemsMapper;
8
use Waredesk\Models\Inventory\Item;
9
use Waredesk\Collections;
10
11
class Items extends Controller
12
{
13
    private const ENDPOINT = '/v1-alpha/inventory/items';
14
15 1
    public function create(Item $item): Item
16
    {
17 1
        return $this->doCreate(
18 1
            self::ENDPOINT,
19
            $item,
20
            function ($response) use ($item) {
21 1
                return (new ItemMapper())->map($item, $response);
22 1
            }
23
        );
24
    }
25
26 1
    public function batchCreate(array $items): Collections\Inventory\Items
27
    {
28 1
        return $this->doCreate(
29 1
            self::ENDPOINT.'/batch',
30
            $items,
31
            function ($response) {
32 1
                return (new ItemsMapper())->map(new Collections\Inventory\Items(), $response);
33 1
            }
34
        );
35
    }
36
37 2
    public function delete(Item $item): bool
38
    {
39 2
        $this->validateIsNotNewEntity($item->getId());
40 2
        return $this->doDelete(self::ENDPOINT."/{$item->getId()}");
41
    }
42
43 1
    public function fetch(string $orderBy = null, string $order = self::ORDER_BY_ASC, int $limit = null): Collections\Inventory\Items
44
    {
45 1
        return $this->doFetch(
46 1
            self::ENDPOINT,
47
            $orderBy,
48
            $order,
49
            $limit,
50
            function ($response) {
51 1
                return (new ItemsMapper())->map(new Collections\Inventory\Items(), $response);
52 1
            }
53
        );
54
    }
55
56
    public function fetchOne(string $orderBy = null, string $order = self::ORDER_BY_ASC): ? Item
57
    {
58
        return $this->doFetchOne(
59
            self::ENDPOINT,
60
            $orderBy,
61
            $order,
62
            function ($response) {
63
                return (new ItemsMapper())->map(new Collections\Inventory\Items(), $response);
64
            }
65
        );
66
    }
67
68
    public function findOneBy(array $criteria, string $orderBy = null, string $order = self::ORDER_BY_ASC): ? Item
69
    {
70
        return $this->doFindOneBy(
71
            self::ENDPOINT,
72
            $criteria,
73
            $orderBy,
74
            $order,
75
            function ($response) {
76
                return (new ItemsMapper())->map(new Collections\Inventory\Items(), $response);
77
            }
78
        );
79
    }
80
}
81