Code Duplication    Length = 148-148 lines in 2 locations

src/Models/Term.php 1 location

@@ 8-155 (lines=148) @@
5
use Codexshaper\WooCommerce\Facades\Query;
6
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
7
8
class Term extends BaseModel
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

src/Models/Variation.php 1 location

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