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

Items::batchCreate()   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\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