Test Failed
Push — develop ( e299a6...38ffd9 )
by Jens
47:56 queued 29:38
created

CartByCustomerIdGetRequest::byCustomerId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * @author @jenschude <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Request\Carts;
7
8
use Commercetools\Core\Request\InStores\InStoreRequestDecorator;
9
use Commercetools\Core\Request\InStores\InStoreTrait;
10
use Psr\Http\Message\ResponseInterface;
11
use Commercetools\Core\Client\HttpMethod;
12
use Commercetools\Core\Client\HttpRequest;
13
use Commercetools\Core\Model\Common\Context;
14
use Commercetools\Core\Request\AbstractApiRequest;
15
use Commercetools\Core\Response\ResourceResponse;
16
use Commercetools\Core\Model\Cart\Cart;
17
use Commercetools\Core\Response\ApiResponseInterface;
18
use Commercetools\Core\Model\MapperInterface;
19
20
/**
21
 * @package Commercetools\Core\Request\Carts
22
 * @link https://docs.commercetools.com/http-api-projects-carts.html#get-cart-by-customer-id
23
 * @method Cart mapResponse(ApiResponseInterface $response)
24
 * @method Cart mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null)
25
 * @method CartByCustomerIdGetRequest|InStoreRequestDecorator inStore($storeKey)
26
 */
27
class CartByCustomerIdGetRequest extends AbstractApiRequest
28
{
29
    use InStoreTrait;
30
31
    protected $resultClass = Cart::class;
32
33
    /**
34
     * @var string
35
     */
36
    protected $customerId;
37
38
    /**
39 7
     * @param string $customerId
40
     * @param Context $context
41 7
     */
42 7
    public function __construct($customerId, Context $context = null)
43 7
    {
44
        parent::__construct(CartsEndpoint::endpoint(), $context);
45
        $this->customerId = $customerId;
46
    }
47
48
    public function byCustomerId($customerId)
49
    {
50 7
        $this->customerId = $customerId;
51
52 7
        return $this;
53
    }
54
55
    /**
56
     * @param string $customerId
57
     * @param Context $context
58
     * @return static
59 4
     */
60
    public static function ofCustomerId($customerId, Context $context = null)
61 4
    {
62
        return new static($customerId, $context);
63
    }
64
65
    /**
66
     * @return string
67
     * @internal
68 2
     */
69
    protected function getPath()
70 2
    {
71
        return (string)$this->getEndpoint() . '/customer-id=' . $this->customerId . $this->getParamString();
72
    }
73
74
    /**
75
     * @return HttpRequest
76
     * @internal
77
     */
78
    public function httpRequest()
79
    {
80
        return new HttpRequest(HttpMethod::GET, $this->getPath());
81
    }
82
83
    /**
84
     * @param ResponseInterface $response
85
     * @return ResourceResponse
86
     */
87
    public function buildResponse(ResponseInterface $response)
88
    {
89
        return new ResourceResponse($response, $this, $this->getContext());
90
    }
91
}
92