ShippingZone::updateShippingZoneMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
1
<?php
2
3
namespace Codexshaper\WooCommerce\Models;
4
5
use Codexshaper\WooCommerce\Facades\Query;
6
use Codexshaper\WooCommerce\Facades\WooCommerce;
7
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
8
9
class ShippingZone extends BaseModel
10
{
11
    use QueryBuilderTrait;
12
13
    protected $endpoint = 'shipping/zones';
14
15
    /**
16
     * Retrieve all Items.
17
     *
18
     * @param int   $id
19
     * @param array $options
20
     *
21
     * @return array
22
     */
23
    protected function getLocations($id, $options = [])
24
    {
25
        return Query::init()
26
            ->setEndpoint("shipping/zones/{$id}/locations")
27
            ->all($options);
28
    }
29
30
    /**
31
     * Update Existing Item.
32
     *
33
     * @param int   $id
34
     * @param array $data
35
     *
36
     * @return object
37
     */
38
    protected function updateLocations($id, $data = [])
39
    {
40
        return WooCommerce::update("shipping/zones/{$id}/locations", $data);
41
    }
42
43
    /**
44
     * Create new Item.
45
     *
46
     * @param int   $id
47
     * @param array $data
48
     *
49
     * @return object
50
     */
51
    protected function addShippingZoneMethod($id, $data)
52
    {
53
        return Query::init()
54
            ->setEndpoint("shipping/zones/{$id}/methods")
55
            ->create($data);
56
    }
57
58
    /**
59
     * Retrieve single Item.
60
     *
61
     * @param int   $zone_id
62
     * @param int   $id
63
     * @param array $options
64
     *
65
     * @return object
66
     */
67
    protected function getShippingZoneMethod($zone_id, $id, $options = [])
68
    {
69
        return Query::init()
70
            ->setEndpoint("shipping/zones/{$zone_id}/methods")
71
            ->find($id, $options);
72
    }
73
74
    /**
75
     * Retrieve all Items.
76
     *
77
     * @param int   $id
78
     * @param array $options
79
     *
80
     * @return array
81
     */
82
    protected function getShippingZoneMethods($id, $options = [])
83
    {
84
        return Query::init()
85
            ->setEndpoint("shipping/zones/{$id}/methods")
86
            ->all($options);
87
    }
88
89
    /**
90
     * Update Existing Item.
91
     *
92
     * @param int   $zone_id
93
     * @param int   $id
94
     * @param array $data
95
     *
96
     * @return object
97
     */
98
    protected function updateShippingZoneMethod($zone_id, $id, $data = [])
99
    {
100
        return Query::init()
101
            ->setEndpoint("shipping/zones/{$zone_id}/methods")
102
            ->update($id, $data);
103
    }
104
105
    /**
106
     * Destroy Item.
107
     *
108
     * @param int   $zone_id
109
     * @param int   $id
110
     * @param array $options
111
     *
112
     * @return object
113
     */
114
    protected function deleteShippingZoneMethod($zone_id, $id, $options = [])
115
    {
116
        return Query::init()
117
            ->setEndpoint("shipping/zones/{$zone_id}/methods")
118
            ->delete($id, $options);
119
    }
120
}
121