Completed
Push — master ( f07867...2c3182 )
by Juliano
02:12
created

Products   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 11.63 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 89.47%

Importance

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