Products   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 11.63 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 3
dl 10
loc 86
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A paginate() 0 4 1
A get() 0 4 1
A create() 0 4 1
A update() 0 4 1
A save() 10 10 3
A delete() 0 4 1
A priceTableInfo() 0 4 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 JulianoBailao\DomusApi\Endpoints;
4
5
use JulianoBailao\DomusApi\Contracts\CreationContract;
6
use JulianoBailao\DomusApi\Contracts\GetContract;
7
use JulianoBailao\DomusApi\Core\Endpoint;
8
use JulianoBailao\DomusApi\Data\ProductData;
9
use JulianoBailao\DomusApi\Endpoints\Secondary\ProductPriceTable;
10
11
class Products extends Endpoint implements GetContract, CreationContract
12
{
13
    /**
14
     * Get a page of products list.
15
     *
16
     * @param array $query the request query string.
17
     *
18
     * @return stdObject
19
     */
20 3
    public function paginate(array $query = [])
21
    {
22 3
        return $this->page('operacional/produtos', $query);
23
    }
24
25
    /**
26
     * Get a specific product.
27
     *
28
     * @param int $id the product id.
29
     *
30
     * @return stdObject
31
     */
32 3
    public function get($id)
33
    {
34 3
        return $this->run('GET', 'operacional/produtos/'.$id);
35
    }
36
37
    /**
38
     * Create a new product.
39
     *
40
     * @return ProductData
41
     */
42 3
    public function create()
43
    {
44 3
        return new ProductData($this);
45
    }
46
47
    /**
48
     * Update a existing product.
49
     *
50
     * @return ProductData
51
     */
52 3
    public function update($id)
53
    {
54 3
        return new ProductData($this, $id);
55
    }
56
57
    /**
58
     * Send the save request.
59
     *
60
     * @param PersonData $data
61
     *
62
     * @return stdClass
63
     */
64 6 View Code Duplication
    public function save(ProductData $data)
0 ignored issues
show
Duplication introduced by
This method 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...
65
    {
66 6
        $id = $data->getId();
67
68 6
        return $this->run(
69 6
            $id == null ? 'POST' : 'PUT',
70 6
            'operacional/produtos'.($id > 0 ? '/'.$id : null),
71 6
            ['json' => $data->toArray()]
72 6
        );
73
    }
74
75
    /**
76
     * Delete a product.
77
     *
78
     * @param int $id
79
     *
80
     * @return bool
81
     */
82 3
    public function delete($id)
83
    {
84 3
        return $this->run('DELETE', 'operacional/produtos/'.$id);
85
    }
86
87
    /**
88
     * Get the product price table info.
89
     *
90
     * @return ProductPriceTable
91
     */
92 6
    public function priceTableInfo()
93
    {
94 6
        return new ProductPriceTable($this->client);
95
    }
96
}
97