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

Product   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 93
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 10 1
A all() 0 8 1
A count() 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/product
7
 */
8
class Product extends AbstractResource
9
{
10
    /**
11
     * @var bool
12
     */
13
    protected $countable = true;
14
15
    /**
16
     * @var ProductVariant
17
     */
18
    public $variants;
19
20
    /**
21
     * @param float $id
22
     * @param array $fields
23
     * @return array
24
     */
25 1
    public function get(float $id, array $fields = [])
26
    {
27 1
        $response = $this->request('GET', sprintf('/admin/products/%s.json', $id), [
28
            'query' => [
29 1
                'fields' => $fields
30
            ]
31
        ]);
32
33 1
        return $response['product'];
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/products.json', [
43 1
            'query' => $query
44
        ]);
45
46 1
        return $response['products'];
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/products/count.json', [
56 1
            'query' => $query
57
        ]);
58
59 1
        return $response['count'];
60
    }
61
62
    /**
63
     * @param array $params
64
     * @return array
65
     */
66 1
    public function create(array $params = [])
67
    {
68 1
        $response = $this->request('POST', '/admin/products.json', [
69 1
            'body' => json_encode([
70 1
                'product' => $params,
71
            ]),
72
        ]);
73
74 1
        return $response['product'];
75
    }
76
77
    /**
78
     * @param float $id
79
     * @param array $params
80
     * @return array
81
     */
82 1
    public function update(float $id, array $params = [])
83
    {
84 1
        $response = $this->request('PUT', sprintf('/admin/products/%s.json', $id), [
85 1
            'body' => json_encode([
86 1
                'product' => $params,
87
            ]),
88
        ]);
89
90 1
        return $response['product'];
91
    }
92
93
    /**
94
     * @param float $id
95
     */
96 1
    public function delete(float $id)
97
    {
98 1
        $this->request('DELETE', sprintf('/admin/products/%s.json', $id));
99 1
    }
100
}
101