Passed
Push — develop ( f53d0b...3a55e6 )
by Jens
09:08
created

CustomerRequestBuilder::createResetPasswordToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * @author @jenschude <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Builder\Request;
7
8
use Commercetools\Core\Model\Customer\Customer;
9
use Commercetools\Core\Model\Customer\CustomerDraft;
10
use Commercetools\Core\Request\Customers\CustomerByEmailTokenGetRequest;
11
use Commercetools\Core\Request\Customers\CustomerByIdGetRequest;
12
use Commercetools\Core\Request\Customers\CustomerByKeyGetRequest;
13
use Commercetools\Core\Request\Customers\CustomerByTokenGetRequest;
14
use Commercetools\Core\Request\Customers\CustomerCreateRequest;
15
use Commercetools\Core\Request\Customers\CustomerDeleteByKeyRequest;
16
use Commercetools\Core\Request\Customers\CustomerDeleteRequest;
17
use Commercetools\Core\Request\Customers\CustomerEmailConfirmRequest;
18
use Commercetools\Core\Request\Customers\CustomerEmailTokenRequest;
19
use Commercetools\Core\Request\Customers\CustomerLoginRequest;
20
use Commercetools\Core\Request\Customers\CustomerPasswordChangeRequest;
21
use Commercetools\Core\Request\Customers\CustomerPasswordResetRequest;
22
use Commercetools\Core\Request\Customers\CustomerPasswordTokenRequest;
23
use Commercetools\Core\Request\Customers\CustomerQueryRequest;
24
use Commercetools\Core\Request\Customers\CustomerUpdateByKeyRequest;
25
use Commercetools\Core\Request\Customers\CustomerUpdateRequest;
26
27
class CustomerRequestBuilder
28
{
29
    /**
30
     * @return CustomerQueryRequest
31
     */
32 1
    public function query()
33
    {
34 1
        return CustomerQueryRequest::of();
35
    }
36
37
    /**
38
     * @param Customer $customer
39
     * @return CustomerUpdateRequest
40
     */
41 1
    public function update(Customer $customer)
42
    {
43 1
        return CustomerUpdateRequest::ofIdAndVersion($customer->getId(), $customer->getVersion());
44
    }
45
46
    /**
47
     * @param Customer $customer
48
     * @return CustomerUpdateByKeyRequest
49
     */
50 1
    public function updateByKey(Customer $customer)
51
    {
52 1
        return CustomerUpdateByKeyRequest::ofKeyAndVersion($customer->getKey(), $customer->getVersion());
53
    }
54
55
    /**
56
     * @param CustomerDraft $customerDraft
57
     * @return CustomerCreateRequest
58
     */
59 1
    public function create(CustomerDraft $customerDraft)
60
    {
61 1
        return CustomerCreateRequest::ofDraft($customerDraft);
62
    }
63
64
    /**
65
     * @param Customer $customer
66
     * @return CustomerDeleteRequest
67
     */
68 1
    public function delete(Customer $customer)
69
    {
70 1
        return CustomerDeleteRequest::ofIdAndVersion($customer->getId(), $customer->getVersion());
71
    }
72
73
    /**
74
     * @param Customer $customer
75
     * @return CustomerDeleteByKeyRequest
76
     */
77 1
    public function deleteByKey(Customer $customer)
78
    {
79 1
        return CustomerDeleteByKeyRequest::ofKeyAndVersion($customer->getKey(), $customer->getVersion());
80
    }
81
82
    /**
83
     * @param string $email
84
     * @param string $password
85
     * @param bool $updateProductData
86
     * @param string $anonymousCartId
87
     * @return CustomerLoginRequest
88
     */
89
    public function login($email, $password, $updateProductData = false, $anonymousCartId = null)
90
    {
91
        return CustomerLoginRequest::ofEmailPasswordAndUpdateProductData(
92
            $email,
93
            $password,
94
            $anonymousCartId,
0 ignored issues
show
Bug introduced by
It seems like $anonymousCartId can also be of type string; however, parameter $updateProductData of Commercetools\Core\Reque...dAndUpdateProductData() does only seem to accept boolean, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

94
            /** @scrutinizer ignore-type */ $anonymousCartId,
Loading history...
95
            $updateProductData
96
        );
97
    }
98
99
    /**
100
     * @param Customer $customer
101
     * @param string $currentPassword
102
     * @param string $newPassword
103
     * @return CustomerPasswordChangeRequest
104
     */
105
    public function changePassword(Customer $customer, $currentPassword, $newPassword)
106
    {
107
        return CustomerPasswordChangeRequest::ofIdVersionAndPasswords(
108
            $customer->getId(),
109
            $customer->getVersion(),
110
            $currentPassword,
111
            $newPassword
112
        );
113
    }
114
115
    /**
116
     * @param string $email
117
     * @return CustomerPasswordTokenRequest
118
     */
119
    public function createResetPasswordToken($email)
120
    {
121
        return CustomerPasswordTokenRequest::ofEmail($email);
122
    }
123
124
    /**
125
     * @param string $tokenValue
126
     * @param string $newPassword
127
     * @return CustomerPasswordResetRequest
128
     */
129
    public function resetPassword($tokenValue, $newPassword)
130
    {
131
        return CustomerPasswordResetRequest::ofTokenAndPassword($tokenValue, $newPassword);
132
    }
133
134
    /**
135
     * @param Customer $customer
136
     * @param int $ttlMinutes
137
     * @return CustomerEmailTokenRequest
138
     */
139
    public function createEmailVerificationToken(Customer $customer, $ttlMinutes)
140
    {
141
        return CustomerEmailTokenRequest::ofIdVersionAndTtl($customer->getId(), $customer->getVersion(), $ttlMinutes);
142
    }
143
144
    /**
145
     * @param string $tokenValue
146
     * @return CustomerEmailConfirmRequest
147
     */
148
    public function confirmEmail($tokenValue)
149
    {
150
        return CustomerEmailConfirmRequest::ofToken($tokenValue);
151
    }
152
153
    /**
154
     * @param string $id
155
     * @return CustomerByIdGetRequest
156
     */
157 1
    public function getById($id)
158
    {
159 1
        return CustomerByIdGetRequest::ofId($id);
160
    }
161
162
    /**
163
     * @param string $key
164
     * @return CustomerByKeyGetRequest
165
     */
166 1
    public function getByKey($key)
167
    {
168 1
        return CustomerByKeyGetRequest::ofKey($key);
169
    }
170
171
    /**
172
     * @param string $tokenValue
173
     * @return CustomerByTokenGetRequest
174
     */
175
    public function getByPasswordToken($tokenValue)
176
    {
177
        return CustomerByTokenGetRequest::ofToken($tokenValue);
178
    }
179
180
    /**
181
     * @param string $tokenValue
182
     * @return CustomerByEmailTokenGetRequest
183
     */
184
    public function getByEmailToken($tokenValue)
185
    {
186
        return CustomerByEmailTokenGetRequest::ofToken($tokenValue);
187
    }
188
}
189