Passed
Push — main ( 383cbf...40aa9a )
by Dylan
02:01
created

Orders::pickups()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Lifeboat\Services;
4
5
use Lifeboat\Exceptions\ApiException;
6
use Lifeboat\Exceptions\InvalidArgumentException;
7
use Lifeboat\Exceptions\OAuthException;
8
use Lifeboat\Models\Model;
9
use Lifeboat\Resource\ListResource;
10
11
/**
12
 * Class Orders
13
 * @package Lifeboat\Services
14
 */
15
class Orders extends ApiService {
16
17
    const PERIOD_ALL    = 'all';
18
    const PERIOD_DAY    = '1';
19
    const PERIOD_7      = '7';
20
    const PERIOD_30     = '30';
21
    const PERIOD_90     = '90';
22
    const PERIOD_120    = '120';
23
24
    const STATUS_OPEN   = 1;
25
    const STATUS_PAID   = 2;
26
27
    const FULFILLMENT_PENDING       = 1;
28
    const FULFILLMENT_FULFILLED     = 2;
29
    const FULFILLMENT_DELIVERED     = 3;
30
31
    /**
32
     * @param int $id
33
     * @return Model|null
34
     * @throws ApiException
35
     * @throws OAuthException
36
     * @throws InvalidArgumentException If param $id is less than 1
37
     */
38
    public function fetch(int $id = -1): ?Model
39
    {
40
        $class = get_called_class();
41
        if ($id <= 0) {
42
            throw new InvalidArgumentException("{$class}::fetch() expects parameter 1 to be a positive integer");
43
        }
44
45
        return $this->retrieve('api/orders/order/' . $id);
46
    }
47
48
    /**
49
     * @param string $period
50
     * @param int $status
51
     * @param int $fulfillment
52
     * @return ListResource
53
     */
54
    public function all(
55
        string $period = self::PERIOD_7,
56
        int $status = self::STATUS_PAID,
57
        int $fulfillment = self::FULFILLMENT_PENDING
58
    ): ListResource {
59
        $data = [
60
            'period'        => $period,
61
            'status'        => $status,
62
            'fulfillment'   => $fulfillment
63
        ];
64
65
        return new ListResource($this->getClient(), 'api/orders/all', $data, 20);
66
    }
67
68
    /**
69
     * @return ListResource
70
     */
71
    public function deliveries(): ListResource
72
    {
73
        return new ListResource($this->getClient(), 'api/orders/delivery', [], 20);
74
    }
75
76
    /**
77
     * @return ListResource
78
     */
79
    public function pickups(): ListResource
80
    {
81
        return new ListResource($this->getClient(), 'api/orders/pickup', [], 20);
82
    }
83
}
84