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

Products   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 39.13 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 55%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 18
loc 46
ccs 11
cts 20
cp 0.55
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 9 9 1
A update() 9 9 1
A delete() 0 7 1
A fetch() 0 5 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 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