Passed
Push — develop ( f86f45...dfc586 )
by Edwin
01:46
created

ProductVariant   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 89
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 89
ccs 24
cts 24
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 6 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_variant
7
 */
8
class ProductVariant 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 1
    public function get(float $id, array $fields = [])
21
    {
22 1
        $response = $this->request('GET', sprintf('/admin/variants/%s.json', $id), [
23
            'query' => [
24 1
                'fields' => $fields,
25
            ],
26
        ]);
27
28 1
        return $response['variant'];
29
    }
30
31
    /**
32
     * @param float $id product id
33
     * @param array $query
34
     * @return array
35
     */
36 1
    public function all(float $id, array $query = [])
37
    {
38 1
        $response = $this->request('GET', sprintf('/admin/products/%s/variants.json', $id), [
39 1
            'query' => $query,
40
        ]);
41
42 1
        return $response['variants'];
43
    }
44
45
    /**
46
     * @param float $id product id
47
     * @return array
48
     */
49 1
    public function count(float $id)
50
    {
51 1
        $response = $this->request('GET', sprintf('/admin/products/%s/variants/count.json', $id));
52
53 1
        return $response['count'];
54
    }
55
56
    /**
57
     * @param float $id product id
58
     * @param array $params
59
     * @return array
60
     */
61 1
    public function create(float $id, array $params = [])
62
    {
63 1
        $response = $this->request('POST', sprintf('/admin/products/%s/variants.json', $id), [
64 1
            'body' => json_encode([
65 1
                'variant' => $params,
66
            ]),
67
        ]);
68
69 1
        return $response['variant'];
70
    }
71
72
    /**
73
     * @param float $id
74
     * @param array $params
75
     * @return array
76
     */
77 1
    public function update(float $id, array $params = [])
78
    {
79 1
        $response = $this->request('PUT', sprintf('/admin/variants/%s.json', $id), [
80 1
            'body' => json_encode([
81 1
                'variant' => $params,
82
            ]),
83
        ]);
84
85 1
        return $response['variant'];
86
    }
87
88
    /**
89
     * @param float $productId
90
     * @param float $variantId
91
     */
92 1
    public function delete(float $productId, float $variantId)
93
    {
94 1
        $this->request('DELETE', sprintf('/admin/products/%s/variants/%s.json', $productId, $variantId));
95 1
    }
96
}
97