Variation   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 148
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 2
dl 148
loc 148
ccs 0
cts 59
cp 0
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 6 6 1
A find() 6 6 1
A create() 6 6 1
A update() 6 6 1
A delete() 6 6 1
A batch() 6 6 1
A paginate() 10 10 1
A count() 6 6 1
A save() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Variation 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   $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