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

Customer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 103
ccs 22
cts 30
cp 0.7332
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A search() 0 8 1
A count() 0 8 1
A get() 0 10 1
A all() 0 8 1
A create() 0 8 1
A update() 0 8 1
A delete() 0 4 1
A orders() 0 6 1
1
<?php
2
3
namespace ShopifyClient\Resource;
4
5
/**
6
 * https://help.shopify.com/api/reference/customer
7
 */
8
class Customer extends AbstractResource
9
{
10
    /**
11
     * @param float $id
12
     * @param array $fields
13
     * @return array
14
     */
15 2
    public function get(float $id, array $fields = [])
16
    {
17 2
        $response = $this->request('GET', sprintf('/admin/customers/%s.json', $id), [
18
            'query' => [
19 2
                'fields' => $fields
20
            ]
21
        ]);
22
23 1
        return $response['customer'];
24
    }
25
26
    /**
27
     * @param array $query
28
     * @return array
29
     */
30 1
    public function all(array $query = [])
31
    {
32 1
        $response = $this->request('GET', '/admin/customers.json', [
33 1
            'query' => $query
34
        ]);
35
36 1
        return $response['customers'];
37
    }
38
39
    /**
40
     * @param array $query
41
     * @return mixed
42
     */
43
    public function search(array $query = [])
44
    {
45
        $response = $this->request('GET', '/admin/customers/search.json', [
46
            'query' => $query
47
        ]);
48
49
        return $response['customers'];
50
    }
51
52
    /**
53
     * @param array $query
54
     * @return array
55
     */
56
    public function count(array $query = [])
57
    {
58
        $response = $this->request('GET', '/admin/customers/count.json', [
59
            'query' => $query
60
        ]);
61
62
        return $response['count'];
63
    }
64
65
    /**
66
     * @param array $params
67
     * @return array
68
     */
69 2
    public function create(array $params = [])
70
    {
71 2
        $response = $this->request('POST', '/admin/customers.json', [
72 2
            'body' => json_encode(['customer' => $params])
73
        ]);
74
75 1
        return $response['customer'];
76
    }
77
78
    /**
79
     * @param float $id
80
     * @param array $params
81
     * @return array
82
     */
83 1
    public function update(float $id, array $params = [])
84
    {
85 1
        $response = $this->request('PUT', sprintf('/admin/customers/%s.json', $id), [
86 1
            'body' => json_encode(['customer' => $params])
87
        ]);
88
89 1
        return $response['customer'];
90
    }
91
92
    /**
93
     * @param float $id
94
     */
95 1
    public function delete(float $id)
96
    {
97 1
        $this->request('DELETE', sprintf('/admin/customers/%s.json', $id));
98 1
    }
99
100
    /**
101
     * @param float $id
102
     * @return array
103
     */
104 1
    public function orders(float $id)
105
    {
106 1
        $response = $this->request('GET', sprintf('/admin/customers/%s/orders.json', $id));
107
108 1
        return $response['orders'];
109
    }
110
}
111