Test Failed
Push — develop ( f86f45...dfc586 )
by Edwin
01:54
created

Order::open()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace ShopifyClient\Resource;
4
5
/**
6
 * https://help.shopify.com/api/reference/order
7
 */
8
class Order extends AbstractResource
9
{
10
    /**
11
     * @var bool
12
     */
13
    protected $countable = true;
14
15
    /**
16
     * @var OrderRisk
17
     */
18
    public $risks;
19
20
    /**
21
     * @param float $id
22
     * @param array $fields
23
     * @return array
24
     */
25
    public function get(float $id, array $fields = [])
26
    {
27
        $response = $this->request('GET', sprintf('/admin/orders/%s.json', $id), [
28
            'query' => [
29
                'fields' => $fields
30
            ]
31
        ]);
32
33
        return $response['order'];
34
    }
35
36
    /**
37
     * @param array $query
38
     * @return array
39
     */
40 1
    public function all(array $query = [])
41
    {
42 1
        $response = $this->request('GET', '/admin/orders.json', [
43 1
            'query' => $query
44
        ]);
45
46 1
        return $response['orders'];
47
    }
48
49
    /**
50
     * @param array $query
51
     * @return array
52
     */
53 1
    public function count(array $query = [])
54
    {
55 1
        $response = $this->request('GET', '/admin/orders/count.json', [
56 1
            'query' => $query
57
        ]);
58
59 1
        return $response['count'];
60
    }
61
62
    /**
63
     * @param float $id
64
     * @return array
65
     */
66
    public function open(float $id)
67
    {
68
        $response = $this->request('POST', sprintf('/admin/orders/%s/open.json', $id));
69
70
        return $response['order'];
71
    }
72
73
    /**
74
     * @param float $id
75
     * @param array $params
76
     * @return array
77
     */
78
    public function close(float $id, array $params = [])
79
    {
80
        $response = $this->request('POST', sprintf('/admin/orders/%s/close.json', $id), [
81
            'body' => json_encode($params)
82
        ]);
83
84
        return $response['order'];
85
    }
86
87
    /**
88
     * @param float $id
89
     * @param array $params
90
     * @return array
91
     */
92
    public function cancel(float $id, array $params = [])
93
    {
94
        $response = $this->request('POST', sprintf('/admin/orders/%s/cancel.json', $id), [
95
            'body' => json_encode($params)
96
        ]);
97
98
        return $response['order'];
99
    }
100
101
    /**
102
     * @param array $params
103
     * @return array
104
     */
105
    public function create(array $params = [])
106
    {
107
        $response = $this->request('POST', '/admin/orders.json', [
108
            'body' => json_encode([
109
                'order' => $params,
110
            ]),
111
        ]);
112
113
        return $response['order'];
114
    }
115
116
    /**
117
     * @param float $id
118
     * @param array $params
119
     * @return array
120
     */
121
    public function update(float $id, array $params = [])
122
    {
123
        $response = $this->request('PUT', sprintf('/admin/orders/%s.json', $id), [
124
            'body' => json_encode([
125
                'order' => $params,
126
            ]),
127
        ]);
128
129
        return $response['order'];
130
    }
131
132
    /**
133
     * @param float $id
134
     */
135
    public function delete(float $id)
136
    {
137
        $this->request('DELETE', sprintf('/admin/orders/%s.json', $id));
138
    }
139
}
140