Completed
Push — master ( 2c3182...70677e )
by Juliano
02:18
created

Products::save()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 1
nop 1
crap 3
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