Completed
Push — master ( ef8e02...cd88cd )
by CodexShaper
11:14
created

Term   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 142
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 142
loc 142
ccs 0
cts 25
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\Traits\QueryBuilderTrait;
6
7 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...
8
{
9
    use QueryBuilderTrait;
10
11
    protected $endpoint;
12
13
    /**
14
     * Retrieve all Items.
15
     *
16
     * @param int   $attribute_id
17
     * @param array $options
18
     *
19
     * @return array
20
     */
21
    protected function all($attribute_id, $options = [])
22
    {
23
        $this->endpoint = "products/attributes/{$attribute_id}/terms";
24
25
        return self::all($options);
0 ignored issues
show
Documentation introduced by
$options is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
26
    }
27
28
    /**
29
     * Retrieve single Item.
30
     *
31
     * @param int   $attribute_id
32
     * @param int   $id
33
     * @param array $options
34
     *
35
     * @return object
36
     */
37
    protected function find($attribute_id, $id, $options = [])
38
    {
39
        $this->endpoint = "products/attributes/{$attribute_id}/terms";
40
41
        return self::find($id, $options);
0 ignored issues
show
Documentation introduced by
$options is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
42
    }
43
44
    /**
45
     * Create new Item.
46
     *
47
     * @param int   $attribute_id
48
     * @param array $data
49
     *
50
     * @return object
51
     */
52
    protected function create($attribute_id, $data)
53
    {
54
        $this->endpoint = "products/attributes/{$attribute_id}/terms";
55
56
        return self::create($data);
0 ignored issues
show
Bug introduced by
The call to create() misses a required argument $data.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by
$data is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
    }
58
59
    /**
60
     * Update Existing Item.
61
     *
62
     * @param int   $attribute_id
63
     * @param int   $id
64
     * @param array $data
65
     *
66
     * @return object
67
     */
68
    protected function update($attribute_id, $id, $data)
69
    {
70
        $this->endpoint = "products/attributes/{$attribute_id}/terms";
71
72
        return self::update($id, $data);
0 ignored issues
show
Bug introduced by
The call to update() misses a required argument $data.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by
$data is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
73
    }
74
75
    /**
76
     * Destroy Item.
77
     *
78
     * @param int   $attribute_id
79
     * @param int   $id
80
     * @param array $options
81
     *
82
     * @return object
83
     */
84
    protected function delete($attribute_id, $id, $options = [])
85
    {
86
        $this->endpoint = "products/attributes/{$attribute_id}/terms";
87
88
        return self::delete($id, $options);
0 ignored issues
show
Documentation introduced by
$options is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
89
    }
90
91
    /**
92
     * Batch Update.
93
     *
94
     * @param int   $attribute_id
95
     * @param array $data
96
     *
97
     * @return object
98
     */
99
    protected function batch($attribute_id, $data)
100
    {
101
        $this->endpoint = "products/attributes/{$attribute_id}/terms";
102
103
        return self::batch($data);
0 ignored issues
show
Bug introduced by
The call to batch() misses a required argument $data.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by
$data is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
104
    }
105
106
    /**
107
     * Paginate results.
108
     *
109
     * @param int $per_page
110
     * @param int $current_page
111
     *
112
     * @return array
113
     */
114
    protected function paginate(
115
        $attribute_id, 
116
        $per_page = 10, 
117
        $current_page = 1, 
118
        $options = []
119
    ) {
120
        $this->endpoint = "products/attributes/{$attribute_id}/terms";
121
122
        return self::paginate($per_page, $current_page, $options);
0 ignored issues
show
Documentation introduced by
$options is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
123
    }
124
125
    /**
126
     * Count all results.
127
     *
128
     * @return int
129
     */
130
    protected function count($attribute_id)
131
    {
132
        $this->endpoint = "products/attributes/{$attribute_id}/terms";
133
134
        return self::count();
0 ignored issues
show
Bug introduced by
The call to count() misses a required argument $attribute_id.

This check looks for function calls that miss required arguments.

Loading history...
135
    }
136
137
    /**
138
     * Store data.
139
     *
140
     * @return array
141
     */
142
    public function save($attribute_id)
143
    {
144
        $this->endpoint = "products/attributes/{$attribute_id}/terms";
145
146
        return self::save();
0 ignored issues
show
Bug introduced by
The call to save() misses a required argument $attribute_id.

This check looks for function calls that miss required arguments.

Loading history...
147
    }
148
}
149