Completed
Push — master ( 18bfc7...82e0b5 )
by Jens
18:00 queued 05:19
created

AbstractQueryRequest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 23.4 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A httpRequest() 0 4 1
A buildResponse() 0 4 1
A map() 11 11 3

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
 * @author @jayS-de <[email protected]>
4
 * @created: 26.01.15, 17:27
5
 */
6
7
namespace Commercetools\Core\Request;
8
9
use Commercetools\Core\Model\JsonObjectMapper;
10
use Commercetools\Core\Model\MapperInterface;
11
use Psr\Http\Message\ResponseInterface;
12
use Commercetools\Core\Client;
13
use Commercetools\Core\Client\HttpRequest;
14
use Commercetools\Core\Client\HttpMethod;
15
use Commercetools\Core\Model\Common\Collection;
16
use Commercetools\Core\Model\Common\Context;
17
use Commercetools\Core\Response\PagedQueryResponse;
18
19
/**
20
 * @package Commercetools\Core\Request
21
 * @method PagedQueryResponse executeWithClient(Client $client)
22
 */
23
abstract class AbstractQueryRequest extends AbstractApiRequest implements QueryAllRequestInterface
24
{
25
    use QueryTrait;
26
    use PageTrait;
27
    use SortTrait;
28
    use ExpandTrait;
29
    use WithTotalTrait;
30
31
    protected $resultClass = '\Commercetools\Core\Model\Common\Collection';
32
33
    /**
34
     * @return HttpRequest
35
     * @internal
36
     */
37 67
    public function httpRequest()
38
    {
39 67
        return new HttpRequest(HttpMethod::GET, $this->getPath());
40
    }
41
42
    /**
43
     * @param ResponseInterface $response
44
     * @return PagedQueryResponse
45
     * @internal
46
     */
47 44
    public function buildResponse(ResponseInterface $response)
48
    {
49 44
        return new PagedQueryResponse($response, $this, $this->getContext());
50
    }
51
52
    /**
53
     * @param array $result
54
     * @param Context $context
55
     * @param MapperInterface $mapper
56
     * @return Collection
57
     */
58 86 View Code Duplication
    public function map(array $result, Context $context = null, MapperInterface $mapper = null)
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...
59
    {
60 86
        $data = [];
61 86
        if (!empty($result['results'])) {
62 60
            $data = $result['results'];
63
        }
64 86
        if (is_null($mapper)) {
65 86
            $mapper = JsonObjectMapper::of($context);
66
        }
67 86
        return $mapper->map($data, $this->resultClass);
68
    }
69
}
70