1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jayS-de <[email protected]> |
4
|
|
|
* @created: 11.02.15, 16:42 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Commercetools\Core\Request\Customers; |
8
|
|
|
|
9
|
|
|
use Commercetools\Core\Client\HttpMethod; |
10
|
|
|
use Commercetools\Core\Client\JsonRequest; |
11
|
|
|
use Commercetools\Core\Model\Common\Context; |
12
|
|
|
use Commercetools\Core\Request\AbstractApiRequest; |
13
|
|
|
use Commercetools\Core\Request\AbstractUpdateRequest; |
14
|
|
|
use Commercetools\Core\Model\Customer\Customer; |
15
|
|
|
use Commercetools\Core\Response\ApiResponseInterface; |
16
|
|
|
use Commercetools\Core\Response\ResourceResponse; |
17
|
|
|
use Psr\Http\Message\ResponseInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @package Commercetools\Core\Request\Customers |
21
|
|
|
* @link https://dev.commercetools.com/http-api-projects-customers.html#change-password |
22
|
|
|
* @method Customer mapResponse(ApiResponseInterface $response) |
23
|
|
|
*/ |
24
|
|
|
class CustomerPasswordChangeRequest extends AbstractApiRequest |
25
|
|
|
{ |
26
|
|
|
const ID = 'id'; |
27
|
|
|
const VERSION = 'version'; |
28
|
|
|
const CURRENT_PASSWORD = 'currentPassword'; |
29
|
|
|
const NEW_PASSWORD = 'newPassword'; |
30
|
|
|
|
31
|
|
|
protected $resultClass = '\Commercetools\Core\Model\Customer\Customer'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $id; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var int |
40
|
|
|
*/ |
41
|
|
|
protected $version; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected $currentPassword; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected $newPassword; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $id |
55
|
|
|
* @param int $version |
56
|
|
|
* @param string $currentPassword |
57
|
|
|
* @param string $newPassword |
58
|
|
|
* @param Context $context |
59
|
|
|
*/ |
60
|
6 |
View Code Duplication |
public function __construct($id, $version, $currentPassword, $newPassword, Context $context = null) |
|
|
|
|
61
|
|
|
{ |
62
|
6 |
|
parent::__construct(CustomersEndpoint::endpoint(), $context); |
63
|
6 |
|
$this->setId($id); |
64
|
6 |
|
$this->setVersion($version); |
65
|
6 |
|
$this->currentPassword = $currentPassword; |
66
|
6 |
|
$this->newPassword = $newPassword; |
67
|
6 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $id |
71
|
|
|
* @param int $version |
72
|
|
|
* @param string $currentPassword |
73
|
|
|
* @param string $newPassword |
74
|
|
|
* @param Context $context |
75
|
|
|
* @return static |
76
|
|
|
*/ |
77
|
6 |
|
public static function ofIdVersionAndPasswords( |
78
|
|
|
$id, |
79
|
|
|
$version, |
80
|
|
|
$currentPassword, |
81
|
|
|
$newPassword, |
82
|
|
|
Context $context = null |
83
|
|
|
) { |
84
|
6 |
|
return new static($id, $version, $currentPassword, $newPassword, $context); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
* @internal |
90
|
|
|
*/ |
91
|
6 |
|
protected function getPath() |
92
|
|
|
{ |
93
|
6 |
|
return (string)$this->getEndpoint() . '/password' . $this->getParamString(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return JsonRequest |
98
|
|
|
* @internal |
99
|
|
|
*/ |
100
|
6 |
|
public function httpRequest() |
101
|
|
|
{ |
102
|
|
|
$payload = [ |
103
|
6 |
|
static::ID => $this->getId(), |
104
|
6 |
|
static::VERSION => $this->getVersion(), |
105
|
6 |
|
static::CURRENT_PASSWORD => $this->currentPassword, |
106
|
6 |
|
static::NEW_PASSWORD => $this->newPassword |
107
|
|
|
]; |
108
|
6 |
|
return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param ResponseInterface $response |
113
|
|
|
* @return ResourceResponse |
114
|
|
|
* @internal |
115
|
|
|
*/ |
116
|
1 |
|
public function buildResponse(ResponseInterface $response) |
117
|
|
|
{ |
118
|
1 |
|
return new ResourceResponse($response, $this, $this->getContext()); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
6 |
|
public function getId() |
125
|
|
|
{ |
126
|
6 |
|
return $this->id; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param string $id |
131
|
|
|
* @return $this |
132
|
|
|
*/ |
133
|
6 |
|
public function setId($id) |
134
|
|
|
{ |
135
|
6 |
|
$this->id = $id; |
136
|
|
|
|
137
|
6 |
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return int |
142
|
|
|
*/ |
143
|
6 |
|
public function getVersion() |
144
|
|
|
{ |
145
|
6 |
|
return $this->version; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param int $version |
150
|
|
|
* @return $this |
151
|
|
|
*/ |
152
|
6 |
|
public function setVersion($version) |
153
|
|
|
{ |
154
|
6 |
|
$this->version = $version; |
155
|
|
|
|
156
|
6 |
|
return $this; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
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.