1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jayS-de <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Request\Me; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Client\HttpMethod; |
9
|
|
|
use Commercetools\Core\Client\HttpRequest; |
10
|
|
|
use Commercetools\Core\Model\Common\Context; |
11
|
|
|
use Commercetools\Core\Request\AbstractApiRequest; |
12
|
|
|
use Commercetools\Core\Request\AbstractByIdGetRequest; |
13
|
|
|
use Commercetools\Core\Model\Cart\Cart; |
14
|
|
|
use Commercetools\Core\Response\ApiResponseInterface; |
15
|
|
|
use Commercetools\Core\Response\ResourceResponse; |
16
|
|
|
use Psr\Http\Message\ResponseInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @package Commercetools\Core\Request\Me |
20
|
|
|
* @link https://dev.commercetools.com/http-api-projects-me-carts.html#get-active-cart |
21
|
|
|
* @method Cart mapResponse(ApiResponseInterface $response) |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
class MeActiveCartRequest extends AbstractApiRequest |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
protected $resultClass = '\Commercetools\Core\Model\Cart\Cart'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param Context $context |
29
|
|
|
*/ |
30
|
|
|
public function __construct(Context $context = null) |
31
|
|
|
{ |
32
|
|
|
parent::__construct(MeEndpoint::endpoint(), $context); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param Context $context |
37
|
|
|
* @return static |
38
|
|
|
*/ |
39
|
|
|
public static function of(Context $context = null) |
40
|
|
|
{ |
41
|
|
|
return new static($context); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return string |
46
|
|
|
* @internal |
47
|
|
|
*/ |
48
|
|
|
protected function getPath() |
49
|
|
|
{ |
50
|
|
|
return (string)$this->getEndpoint() . '/active-cart' . $this->getParamString(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return HttpRequest |
55
|
|
|
* @internal |
56
|
|
|
*/ |
57
|
|
|
public function httpRequest() |
58
|
|
|
{ |
59
|
|
|
return new HttpRequest(HttpMethod::GET, $this->getPath()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param ResponseInterface $response |
64
|
|
|
* @return ResourceResponse |
65
|
|
|
* @internal |
66
|
|
|
*/ |
67
|
|
|
public function buildResponse(ResponseInterface $response) |
68
|
|
|
{ |
69
|
|
|
return new ResourceResponse($response, $this, $this->getContext()); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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.