Completed
Push — develop ( e77623...3cc0f7 )
by Jens
09:01
created

MeEmailConfirmRequest::httpRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
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\JsonRequest;
10
use Commercetools\Core\Model\Common\Context;
11
use Commercetools\Core\Request\AbstractApiRequest;
12
use Commercetools\Core\Response\ApiResponseInterface;
13
use Commercetools\Core\Model\Customer\Customer;
14
use Commercetools\Core\Response\ResourceResponse;
15
use Psr\Http\Message\ResponseInterface;
16
17
/**
18
 * @package Commercetools\Core\Request\Me
19
 * @link https://dev.commercetools.com/http-api-projects-me-profile.html#verify-customers-email
20
 * @method Customer mapResponse(ApiResponseInterface $response)
21
 */
22 View Code Duplication
class MeEmailConfirmRequest extends AbstractApiRequest
0 ignored issues
show
Duplication introduced by
This class 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...
23
{
24
    protected $resultClass = '\Commercetools\Core\Model\Customer\Customer';
25
26
    const TOKEN_VALUE = 'tokenValue';
27
28
    /**
29
     * @var string
30
     */
31
    protected $tokenValue;
32
33
    /**
34
     * @param string $tokenValue
35
     * @param Context $context
36
     */
37 1
    public function __construct($tokenValue, Context $context = null)
38
    {
39 1
        parent::__construct(MeEndpoint::endpoint(), $context);
40 1
        $this->tokenValue = $tokenValue;
41 1
    }
42
43
    /**
44
     * @param string $tokenValue
45
     * @param Context $context
46
     * @return static
47
     */
48 1
    public static function ofToken($tokenValue, Context $context = null)
49
    {
50 1
        return new static($tokenValue, $context);
51
    }
52
53
    /**
54
     * @return string
55
     * @internal
56
     */
57 1
    protected function getPath()
58
    {
59 1
        return (string)$this->getEndpoint() . '/email/confirm' .  $this->getParamString();
60
    }
61
62
    /**
63
     * @return JsonRequest
64
     * @internal
65
     */
66 1
    public function httpRequest()
67
    {
68
        $payload = [
69 1
            static::TOKEN_VALUE => $this->tokenValue,
70
        ];
71 1
        return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload);
72
    }
73
74 1
    public function buildResponse(ResponseInterface $response)
75
    {
76 1
        return new ResourceResponse($response, $this, $this->getContext());
77
    }
78
}
79