Completed
Push — develop ( 1b5cd2...b91b03 )
by Edwin
02:13
created

Order   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 127
ccs 36
cts 36
cp 1
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 10 1
A all() 0 8 1
A count() 0 8 1
A open() 0 6 1
A close() 0 8 1
A cancel() 0 8 1
A create() 0 10 1
A update() 0 10 1
A delete() 0 4 1
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
     * @param float $id
17
     * @param array $fields
18
     * @return array
19
     */
20 2
    public function get(float $id, array $fields = [])
21
    {
22 2
        $response = $this->request('GET', sprintf('/admin/orders/%s.json', $id), [
23
            'query' => [
24 2
                'fields' => $fields
25
            ]
26
        ]);
27
28 2
        return $response['order'];
29
    }
30
31
    /**
32
     * @param array $query
33
     * @return array
34
     */
35 1
    public function all(array $query = [])
36
    {
37 1
        $response = $this->request('GET', '/admin/orders.json', [
38 1
            'query' => $query
39
        ]);
40
41 1
        return $response['orders'];
42
    }
43
44
    /**
45
     * @param array $query
46
     * @return array
47
     */
48 1
    public function count(array $query = [])
49
    {
50 1
        $response = $this->request('GET', '/admin/orders/count.json', [
51 1
            'query' => $query
52
        ]);
53
54 1
        return $response['count'];
55
    }
56
57
    /**
58
     * @param float $id
59
     * @return array
60
     */
61 1
    public function open(float $id)
62
    {
63 1
        $response = $this->request('POST', sprintf('/admin/orders/%s/open.json', $id));
64
65 1
        return $response['order'];
66
    }
67
68
    /**
69
     * @param float $id
70
     * @param array $params
71
     * @return array
72
     */
73 1
    public function close(float $id, array $params = [])
74
    {
75 1
        $response = $this->request('POST', sprintf('/admin/orders/%s/close.json', $id), [
76 1
            'body' => json_encode($params)
77
        ]);
78
79 1
        return $response['order'];
80
    }
81
82
    /**
83
     * @param float $id
84
     * @param array $params
85
     * @return array
86
     */
87 1
    public function cancel(float $id, array $params = [])
88
    {
89 1
        $response = $this->request('POST', sprintf('/admin/orders/%s/cancel.json', $id), [
90 1
            'body' => json_encode($params)
91
        ]);
92
93 1
        return $response['order'];
94
    }
95
96
    /**
97
     * @param array $params
98
     * @return array
99
     */
100 2
    public function create(array $params = [])
101
    {
102 2
        $response = $this->request('POST', '/admin/orders.json', [
103 2
            'body' => json_encode([
104 2
                'order' => $params,
105
            ]),
106
        ]);
107
108 2
        return $response['order'];
109
    }
110
111
    /**
112
     * @param float $id
113
     * @param array $params
114
     * @return array
115
     */
116 1
    public function update(float $id, array $params = [])
117
    {
118 1
        $response = $this->request('PUT', sprintf('/admin/orders/%s.json', $id), [
119 1
            'body' => json_encode([
120 1
                'order' => $params,
121
            ]),
122
        ]);
123
124 1
        return $response['order'];
125
    }
126
127
    /**
128
     * @param float $id
129
     */
130 2
    public function delete(float $id)
131
    {
132 2
        $this->request('DELETE', sprintf('/admin/orders/%s.json', $id));
133 2
    }
134
}
135