Passed
Push — develop ( a89f38...e77623 )
by Jens
19:19
created

MeOrderCreateFromCartRequest::setCartId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Request\Me;
7
8
use Psr\Http\Message\ResponseInterface;
9
use Commercetools\Core\Client\HttpMethod;
10
use Commercetools\Core\Client\HttpRequestInterface;
11
use Commercetools\Core\Client\JsonRequest;
12
use Commercetools\Core\Model\Common\Context;
13
use Commercetools\Core\Request\AbstractApiRequest;
14
use Commercetools\Core\Response\AbstractApiResponse;
15
use Commercetools\Core\Response\ResourceResponse;
16
use Commercetools\Core\Model\Order\Order;
17
use Commercetools\Core\Response\ApiResponseInterface;
18
19
/**
20
 * @package Commercetools\Core\Request\Me
21
 * @link https://dev.commercetools.com/http-api-projects-me-orders.html#create-order-from-a-cart
22
 * @method Order mapResponse(ApiResponseInterface $response)
23
 */
24
class MeOrderCreateFromCartRequest extends AbstractApiRequest
25
{
26
    const ID = 'id';
27
    const VERSION = 'version';
28
29
    protected $cartId;
30
    protected $version;
31
32
    protected $resultClass = '\Commercetools\Core\Model\Order\Order';
33
34
    /**
35
     * @return mixed
36
     */
37 3
    public function getCartId()
38
    {
39 3
        return $this->cartId;
40
    }
41
42
    /**
43
     * @param $cartId
44
     * @return $this
45
     */
46 3
    public function setCartId($cartId)
47
    {
48 3
        $this->cartId = $cartId;
49
50 3
        return $this;
51
    }
52
53
    /**
54
     * @return mixed
55
     */
56 3
    public function getVersion()
57
    {
58 3
        return $this->version;
59
    }
60
61
    /**
62
     * @param $version
63
     * @return $this
64
     */
65 3
    public function setVersion($version)
66
    {
67 3
        $this->version = $version;
68
69 3
        return $this;
70
    }
71
72
    /**
73
     * @param string $cartId
74
     * @param int $version
75
     * @param Context $context
76
     */
77 3
    public function __construct($cartId, $version, Context $context = null)
78
    {
79 3
        parent::__construct(MeOrdersEndpoint::endpoint(), $context);
80 3
        $this->setCartId($cartId)->setVersion($version);
81 3
    }
82
83
    /**
84
     * @param string $cartId
85
     * @param int $version
86
     * @param Context $context
87
     * @return static
88
     */
89 3
    public static function ofCartIdAndVersion($cartId, $version, Context $context = null)
90
    {
91 3
        return new static($cartId, $version, $context);
92
    }
93
94
    /**
95
     * @param ResponseInterface $response
96
     * @return AbstractApiResponse
97
     * @internal
98
     */
99 3
    public function buildResponse(ResponseInterface $response)
100
    {
101 3
        return new ResourceResponse($response, $this, $this->getContext());
102
    }
103
104
    /**
105
     * @return HttpRequestInterface
106
     * @internal
107
     */
108 3 View Code Duplication
    public function httpRequest()
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...
109
    {
110
        $payload = [
111 3
            static::ID => $this->getCartId(),
112 3
            static::VERSION => $this->getVersion(),
113
        ];
114
115 3
        return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload);
116
    }
117
}
118