Completed
Push — master ( cb44f9...1fdaf4 )
by Gabriel
07:02
created

Products::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Waredesk;
4
5
use Waredesk\Mappers\ProductMapper;
6
use Waredesk\Mappers\ProductsMapper;
7
use Waredesk\Models\Product;
8
9
class Products
10
{
11
    private $requestHandler;
12
13 12
    public function __construct(RequestHandler $requestHandler)
14
    {
15 12
        $this->requestHandler = $requestHandler;
16 12
    }
17
18 2 View Code Duplication
    public function create(Product $product): Product
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...
19
    {
20 2
        $response = $this->requestHandler->post(
21 2
            '/v1/products',
22
            $product
23
        );
24 2
        $product = (new ProductMapper())->map($product, $response);
25 2
        return $product;
26
    }
27
28 View Code Duplication
    public function update(Product $product): Product
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...
29
    {
30
        $response = $this->requestHandler->update(
31
            "/v1/products/{$product->getId()}",
32
            $product
33
        );
34
        $product = (new ProductMapper())->map($product, $response);
35
        return $product;
36
    }
37
38
    public function delete(Product $product): bool
39
    {
40
        $this->requestHandler->delete(
41
            "/v1/products/{$product->getId()}"
42
        );
43
        return true;
44
    }
45
46
    /**
47
     * @return Collections\Products|Product[]
48
     */
49 1
    public function fetch(): Collections\Products
50
    {
51 1
        $response = $this->requestHandler->get('/v1/products');
52 1
        return (new ProductsMapper())->map(new Collections\Products(), $response);
53
    }
54
}
55