Completed
Push — master ( a1ce72...051ac9 )
by Tobias
33:52 queued 23:54
created

Product::get()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace FAPI\Sylius\Api;
11
12
use FAPI\Sylius\Exception;
13
use FAPI\Sylius\Model\Product\ProductCollection;
14
use FAPI\Sylius\Model\Product\VariantCollection;
15
use FAPI\Sylius\Model\Product\Product as Model;
16
use Psr\Http\Message\ResponseInterface;
17
18
/**
19
 * @author Kasim Taskin <[email protected]>
20
 */
21
final class Product extends HttpApi
22
{
23 View Code Duplication
    public function get(string $productCode)
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...
24
    {
25
        $response = $this->httpGet("/api/v1/products/{$productCode}");
26
27
        if (!$this->hydrator) {
28
            return $response;
29
        }
30
31
        // Use any valid status code here
32
        if (200 !== $response->getStatusCode()) {
33
            $this->handleErrors($response);
34
        }
35
36
        return $this->hydrator->hydrate($response, Model::class);
37
    }
38
39
    /**
40
     * @param array $params
41
     *
42
     * @throws Exception\DomainException
43
     *
44
     * @return ProductCollection|ResponseInterface
45
     */
46 View Code Duplication
    public function getAll(array $params = [])
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...
47
    {
48
        $response = $this->httpGet('/api/v1/products/', $params);
49
50
        if (!$this->hydrator) {
51
            return $response;
52
        }
53
54
        // Use any valid status code here
55
        if (200 !== $response->getStatusCode()) {
56
            $this->handleErrors($response);
57
        }
58
59
        return $this->hydrator->hydrate($response, ProductCollection::class);
60
    }
61
62
    /**
63
     * @param string $productCode
64
     * @param array  $params
65
     *
66
     * @return VariantCollection|ResponseInterface
67
     *
68
     * @throws Exception\DomainException
69
     */
70 View Code Duplication
    public function getVariants(string $productCode, array $params = [])
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...
71
    {
72
        $response = $this->httpGet("/api/v1/products/{$productCode}/variants/", $params);
73
74
        if (!$this->hydrator) {
75
            return $response;
76
        }
77
78
        // Use any valid status code here
79
        if (200 !== $response->getStatusCode()) {
80
            $this->handleErrors($response);
81
        }
82
83
        return $this->hydrator->hydrate($response, VariantCollection::class);
84
    }
85
}
86