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

MePasswordResetRequest::ofTokenAndPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 3
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\ResourceResponse;
13
use Psr\Http\Message\ResponseInterface;
14
use Commercetools\Core\Model\Customer\Customer;
15
use Commercetools\Core\Response\ApiResponseInterface;
16
17
/**
18
 * @package Commercetools\Core\Request\Me
19
 * @method Customer mapResponse(ApiResponseInterface $response)
20
 */
21 View Code Duplication
class MePasswordResetRequest 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...
22
{
23
    const TOKEN_VALUE = 'tokenValue';
24
    const NEW_PASSWORD = 'newPassword';
25
26
    protected $resultClass = '\Commercetools\Core\Model\Customer\Customer';
27
28
    /**
29
     * @var string
30
     */
31
    protected $token;
32
33
    /**
34
     * @var string
35
     */
36
    protected $newPassword;
37
38
    /**
39
     * @param string $token
40
     * @param string $newPassword
41
     * @param Context $context
42
     */
43 1
    public function __construct($token, $newPassword, Context $context = null)
44
    {
45 1
        parent::__construct(MeEndpoint::endpoint(), $context);
46 1
        $this->token = $token;
47 1
        $this->newPassword = $newPassword;
48 1
    }
49
50
    /**
51
     * @param string $token
52
     * @param string $newPassword
53
     * @param Context $context
54
     * @return static
55
     */
56 1
    public static function ofTokenAndPassword(
57
        $token,
58
        $newPassword,
59
        Context $context = null
60
    ) {
61 1
        return new static($token, $newPassword, $context);
62
    }
63
64
    /**
65
     * @return string
66
     * @internal
67
     */
68 1
    protected function getPath()
69
    {
70 1
        return (string)$this->getEndpoint() . '/password/reset' . $this->getParamString();
71
    }
72
73
    /**
74
     * @return JsonRequest
75
     * @internal
76
     */
77 1
    public function httpRequest()
78
    {
79
        $payload = [
80 1
            static::TOKEN_VALUE => $this->token,
81 1
            static::NEW_PASSWORD => $this->newPassword
82
        ];
83 1
        return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload);
84
    }
85
86
    /**
87
     * @param ResponseInterface $response
88
     * @return ResourceResponse
89
     * @internal
90
     */
91 1
    public function buildResponse(ResponseInterface $response)
92
    {
93 1
        return new ResourceResponse($response, $this, $this->getContext());
94
    }
95
}
96