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

AbstractQueryRequest::map()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 3

Importance

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