Term::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 6
loc 6
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Codexshaper\WooCommerce\Models;
4
5
use Codexshaper\WooCommerce\Facades\Query;
6
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
7
8 View Code Duplication
class Term extends BaseModel
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    use QueryBuilderTrait;
11
12
    protected $endpoint;
13
14
    /**
15
     * Retrieve all Items.
16
     *
17
     * @param int   $attribute_id
18
     * @param array $options
19
     *
20
     * @return array
21
     */
22
    protected function all($attribute_id, $options = [])
23
    {
24
        return Query::init()
25
            ->setEndpoint("products/attributes/{$attribute_id}/terms")
26
            ->all($options);
27
    }
28
29
    /**
30
     * Retrieve single Item.
31
     *
32
     * @param int   $attribute_id
33
     * @param int   $id
34
     * @param array $options
35
     *
36
     * @return object
37
     */
38
    protected function find($attribute_id, $id, $options = [])
39
    {
40
        return Query::init()
41
            ->setEndpoint("products/attributes/{$attribute_id}/terms")
42
            ->find($id, $options);
43
    }
44
45
    /**
46
     * Create new Item.
47
     *
48
     * @param int   $attribute_id
49
     * @param array $data
50
     *
51
     * @return object
52
     */
53
    protected function create($attribute_id, $data)
54
    {
55
        return Query::init()
56
            ->setEndpoint("products/attributes/{$attribute_id}/terms")
57
            ->create($data);
58
    }
59
60
    /**
61
     * Update Existing Item.
62
     *
63
     * @param int   $attribute_id
64
     * @param int   $id
65
     * @param array $data
66
     *
67
     * @return object
68
     */
69
    protected function update($attribute_id, $id, $data)
70
    {
71
        return Query::init()
72
            ->setEndpoint("products/attributes/{$attribute_id}/terms")
73
            ->update($id, $data);
74
    }
75
76
    /**
77
     * Destroy Item.
78
     *
79
     * @param int   $attribute_id
80
     * @param int   $id
81
     * @param array $options
82
     *
83
     * @return object
84
     */
85
    protected function delete($attribute_id, $id, $options = [])
86
    {
87
        return Query::init()
88
            ->setEndpoint("products/attributes/{$attribute_id}/terms")
89
            ->delete($id, $options);
90
    }
91
92
    /**
93
     * Batch Update.
94
     *
95
     * @param int   $attribute_id
96
     * @param array $data
97
     *
98
     * @return object
99
     */
100
    protected function batch($attribute_id, $data)
101
    {
102
        return Query::init()
103
            ->setEndpoint("products/attributes/{$attribute_id}/terms")
104
            ->batch($data);
105
    }
106
107
    /**
108
     * Paginate results.
109
     *
110
     * @param int   $attribute_id
111
     * @param int   $per_page
112
     * @param int   $current_page
113
     * @param array $options
114
     *
115
     * @return array
116
     */
117
    protected function paginate(
118
        $attribute_id,
119
        $per_page = 10,
120
        $current_page = 1,
121
        $options = []
122
    ) {
123
        return Query::init()
124
            ->setEndpoint("products/attributes/{$attribute_id}/terms")
125
            ->paginate($per_page, $current_page, $options);
126
    }
127
128
    /**
129
     * Count all results.
130
     *
131
     * @param int $attribute_id
132
     *
133
     * @return int
134
     */
135
    protected function count($attribute_id)
136
    {
137
        return Query::init()
138
            ->setEndpoint("products/attributes/{$attribute_id}/terms")
139
            ->count();
140
    }
141
142
    /**
143
     * Store data.
144
     *
145
     * @param int $attribute_id
146
     *
147
     * @return array
148
     */
149
    public function save($attribute_id)
150
    {
151
        return Query::init()
152
            ->setEndpoint("products/attributes/{$attribute_id}/terms")
153
            ->save();
154
    }
155
}
156