Test Failed
Push — develop ( 47e1b5...e72b23 )
by Jens
18:53 queued 15s
created

AbstractByIdHeadRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 4
c 1
b 0
f 0
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
namespace Commercetools\Core\Request;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Commercetools\Core\Client;
7
use Commercetools\Core\Client\HttpMethod;
8
use Commercetools\Core\Client\HttpRequest;
9
use Commercetools\Core\Client\JsonEndpoint;
10
use Commercetools\Core\Model\Common\Context;
11
use Commercetools\Core\Response\ResourceResponse;
12
13
/**
14
 * @package Commercetools\Core\Request
15
 * @method ResourceResponse executeWithClient(Client $client)
16
 */
17
abstract class AbstractByIdHeadRequest extends AbstractApiRequest
18
{
19
    use ExpandTrait;
20
21
    /**
22
     * @var string
23
     */
24
    protected $id;
25
26
    /**
27
     * @param JsonEndpoint $endpoint
28
     * @param string $id
29
     * @param Context $context
30
     */
31
    public function __construct(JsonEndpoint $endpoint, $id, Context $context = null)
32
    {
33
        parent::__construct($endpoint, $context);
34
        $this->setId($id);
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getId()
41
    {
42
        return $this->id;
43
    }
44
45
    /**
46
     * @param string $id
47
     * @return $this
48
     */
49
    public function setId($id)
50
    {
51
        $this->id = $id;
52
53
        return $this;
54
    }
55
56
    /**
57
     * @return string
58
     * @internal
59
     */
60
    protected function getPath()
61
    {
62
        return (string)$this->getEndpoint() . '/' . $this->getId() . $this->getParamString();
63
    }
64
65
    /**
66
     * @return HttpRequest
67
     * @internal
68
     */
69
    public function httpRequest()
70
    {
71
        return new HttpRequest(HttpMethod::HEAD, $this->getPath());
72
    }
73
74
    /**
75
     * @param ResponseInterface $response
76
     * @return ResourceResponse
77
     * @internal
78
     */
79
    public function buildResponse(ResponseInterface $response)
80
    {
81
        return new ResourceResponse($response, $this, $this->getContext());
82
    }
83
}
84