Completed
Push — develop ( f146aa...02676e )
by Jens
08:33
created

AbstractByTokenGetRequest::getToken()   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

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
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: 12.02.15, 10:35
5
 */
6
7
namespace Commercetools\Core\Request;
8
9
use Commercetools\Core\Client\JsonEndpoint;
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\Response\ResourceResponse;
15
16
abstract class AbstractByTokenGetRequest extends AbstractApiRequest
17
{
18
    const TOKEN = 'token';
19
    const TOKEN_NAME = 'token';
20
21
    protected $token;
22
23
    /**
24
     * @param string $token
25
     * @param Context $context
26
     */
27 7
    public function __construct(JsonEndpoint $endpoint, $token, Context $context = null)
28
    {
29 7
        parent::__construct($endpoint, $context);
30 7
        $this->setToken($token);
31 7
    }
32
33
    /**
34
     * @return string
35
     */
36 6
    public function getToken()
37
    {
38 6
        return $this->token;
39
    }
40
41
    /**
42
     * @param string $token
43
     * @return $this
44
     */
45 7
    public function setToken($token)
46
    {
47 7
        $this->token = $token;
48
49 7
        return $this;
50
    }
51
52
    /**
53
     * @return string
54
     * @internal
55
     */
56 6
    protected function getPath()
57
    {
58 6
        return (string)$this->getEndpoint() . '/' . static::TOKEN_NAME . '=' . $this->getToken() .
59 6
            $this->getParamString();
60
    }
61
62
    /**
63
     * @return HttpRequest
64
     * @internal
65
     */
66 6
    public function httpRequest()
67
    {
68 6
        return new HttpRequest(HttpMethod::GET, $this->getPath());
69
    }
70
71
    /**
72
     * @param ResponseInterface $response
73
     * @return ResourceResponse
74
     * @internal
75
     */
76 4
    public function buildResponse(ResponseInterface $response)
77
    {
78 4
        return new ResourceResponse($response, $this, $this->getContext());
79
    }
80
}
81