Completed
Branch master (9c37c7)
by Jens
07:29
created

AbstractDeleteRequest::httpRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 * @created: 26.01.15, 17:22
5
 */
6
7
namespace Commercetools\Core\Request;
8
9
use Psr\Http\Message\ResponseInterface;
10
use Commercetools\Core\Client;
11
use Commercetools\Core\Client\HttpMethod;
12
use Commercetools\Core\Client\HttpRequest;
13
use Commercetools\Core\Client\JsonEndpoint;
14
use Commercetools\Core\Model\Common\Context;
15
use Commercetools\Core\Request\Query\Parameter;
16
use Commercetools\Core\Response\ResourceResponse;
17
18
/**
19
 * @package Commercetools\Core\Request
20
 * @method ResourceResponse executeWithClient(Client $client)
21
 */
22
abstract class AbstractDeleteRequest extends AbstractApiRequest
23
{
24
    /**
25
     * @var string
26
     */
27
    protected $id;
28
29
    /**
30
     * @var int
31
     */
32
    protected $version;
33
34
    /**
35
     * @param JsonEndpoint $endpoint
36
     * @param string $id
37
     * @param int $version
38
     * @param Context $context
39
     */
40 325
    public function __construct(JsonEndpoint $endpoint, $id, $version, Context $context = null)
41
    {
42 325
        parent::__construct($endpoint, $context);
43 325
        $this->setId($id);
44 325
        $this->setVersion($version);
45 325
    }
46
47
    /**
48
     * @return string
49
     */
50 275
    public function getId()
51
    {
52 275
        return $this->id;
53
    }
54
55
    /**
56
     * @param $id
57
     * @return $this
58
     */
59 325
    public function setId($id)
60
    {
61 325
        $this->id = $id;
62
63 325
        return $this;
64
    }
65
66
    /**
67
     * @return int
68
     */
69 2
    public function getVersion()
70
    {
71 2
        return $this->version;
72
    }
73
74
    /**
75
     * @param int $version
76
     * @return $this
77
     */
78 325
    public function setVersion($version)
79
    {
80 325
        $this->version = $version;
81 325
        $this->addParamObject(new Parameter('version', $version));
82
83 325
        return $this;
84
    }
85
86
    /**
87
     * @return string
88
     * @internal
89
     */
90 270
    protected function getPath()
91
    {
92 270
        return (string)$this->getEndpoint() . '/' . $this->getId() . $this->getParamString();
93
    }
94
95
    /**
96
     * @return HttpRequest
97
     * @internal
98
     */
99 273
    public function httpRequest()
100
    {
101 273
        return new HttpRequest(HttpMethod::DELETE, $this->getPath());
102
    }
103
104
    /**
105
     * @param ResponseInterface $response
106
     * @return ResourceResponse
107
     * @internal
108
     */
109 269
    public function buildResponse(ResponseInterface $response)
110
    {
111 269
        return new ResourceResponse($response, $this, $this->getContext());
112
    }
113
}
114