VariantManager   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 96
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getServiceName() 0 4 1
A getResourceName() 0 4 1
A getParentResourceName() 0 4 1
A getModelClass() 0 4 1
A findAll() 0 6 1
A find() 0 6 1
A count() 0 6 1
A update() 0 8 1
A remove() 0 4 1
A create() 0 8 1
1
<?php
2
3
/*
4
 * This file is part of the slince/shopify-api-php
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Slince\Shopify\Manager\ProductVariant;
13
14
use Slince\Shopify\Common\Manager\AbstractManager;
15
16
class VariantManager extends AbstractManager implements VariantManagerInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public static function getServiceName()
22
    {
23
        return 'product_variants';
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function getResourceName()
30
    {
31
        return 'variant';
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getParentResourceName()
38
    {
39
        return 'product';
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getModelClass()
46
    {
47
        return Variant::class;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function findAll($productId, array $query = [])
54
    {
55
        $data = $this->client->get('products'.'/'.$productId.'/variants', $query);
56
57
        return $this->createMany($data['variants']);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function find($id)
64
    {
65
        $data = $this->client->get('/variants/'.$id);
66
67
        return $this->fromArray($data['variant']);
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function count($productId, array $query = [])
74
    {
75
        $data = $this->client->get('products'.'/'.$productId.'/variants/count', $query);
76
77
        return $data['count'];
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function update($id, array $data)
84
    {
85
        $data = $this->client->put('/variants/'.$id, [
86
            'variant' => $data,
87
        ]);
88
89
        return $this->fromArray($data['variant']);
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function remove($productId, $id)
96
    {
97
        $this->client->delete('products'.'/'.$productId.'/variants/'.$id);
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function create($productId, array $data)
104
    {
105
        $data = $this->client->post('products/'.$productId.'/variants', [
106
            'variant' => $data,
107
        ]);
108
109
        return $this->fromArray($data['variant']);
110
    }
111
}