CustomerException::customerOptinNotCompleted()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Customer;
4
5
use Shopware\Core\Checkout\Customer\Exception\AddressNotFoundException;
6
use Shopware\Core\Checkout\Customer\Exception\BadCredentialsException;
7
use Shopware\Core\Checkout\Customer\Exception\CannotDeleteActiveAddressException;
8
use Shopware\Core\Checkout\Customer\Exception\CannotDeleteDefaultAddressException;
9
use Shopware\Core\Checkout\Customer\Exception\CustomerAlreadyConfirmedException;
10
use Shopware\Core\Checkout\Customer\Exception\CustomerAuthThrottledException;
11
use Shopware\Core\Checkout\Customer\Exception\CustomerGroupRegistrationConfigurationNotFound;
12
use Shopware\Core\Checkout\Customer\Exception\CustomerNotFoundByHashException;
13
use Shopware\Core\Checkout\Customer\Exception\CustomerNotFoundByIdException;
14
use Shopware\Core\Checkout\Customer\Exception\CustomerNotFoundException;
15
use Shopware\Core\Checkout\Customer\Exception\CustomerOptinNotCompletedException;
16
use Shopware\Core\Checkout\Customer\Exception\CustomerRecoveryHashExpiredException;
17
use Shopware\Core\Checkout\Customer\Exception\CustomerWishlistNotActivatedException;
18
use Shopware\Core\Checkout\Customer\Exception\CustomerWishlistNotFoundException;
19
use Shopware\Core\Checkout\Customer\Exception\DuplicateWishlistProductException;
20
use Shopware\Core\Checkout\Customer\Exception\InactiveCustomerException;
21
use Shopware\Core\Checkout\Customer\Exception\LegacyPasswordEncoderNotFoundException;
22
use Shopware\Core\Checkout\Customer\Exception\NoHashProvidedException;
23
use Shopware\Core\Checkout\Customer\Exception\WishlistProductNotFoundException;
24
use Shopware\Core\Framework\Feature;
25
use Shopware\Core\Framework\HttpException;
26
use Shopware\Core\Framework\Log\Package;
27
use Shopware\Core\Framework\ShopwareHttpException;
28
use Shopware\Core\System\Country\Exception\CountryNotFoundException;
29
use Symfony\Component\HttpFoundation\Response;
30
31
#[Package('checkout')]
32
class CustomerException extends HttpException
33
{
34
    public const CUSTOMERS_NOT_FOUND = 'CHECKOUT__CUSTOMERS_NOT_FOUND';
35
    public const CUSTOMER_NOT_FOUND = 'CHECKOUT__CUSTOMER_NOT_FOUND';
36
    public const CUSTOMER_GROUP_NOT_FOUND = 'CHECKOUT__CUSTOMER_GROUP_NOT_FOUND';
37
    public const CUSTOMER_GROUP_REQUEST_NOT_FOUND = 'CHECKOUT__CUSTOMER_GROUP_REQUEST_NOT_FOUND';
38
    public const CUSTOMER_NOT_LOGGED_IN = 'CHECKOUT__CUSTOMER_NOT_LOGGED_IN';
39
    public const LINE_ITEM_DOWNLOAD_FILE_NOT_FOUND = 'CHECKOUT__LINE_ITEM_DOWNLOAD_FILE_NOT_FOUND';
40
    public const CUSTOMER_IDS_PARAMETER_IS_MISSING = 'CHECKOUT__CUSTOMER_IDS_PARAMETER_IS_MISSING';
41
    public const PRODUCT_IDS_PARAMETER_IS_MISSING = 'CHECKOUT__PRODUCT_IDS_PARAMETER_IS_MISSING';
42
    public const CUSTOMER_ADDRESS_NOT_FOUND = 'CHECKOUT__CUSTOMER_ADDRESS_NOT_FOUND';
43
    public const CUSTOMER_AUTH_BAD_CREDENTIALS = 'CHECKOUT__CUSTOMER_AUTH_BAD_CREDENTIALS';
44
    public const CUSTOMER_ADDRESS_IS_ACTIVE = 'CHECKOUT__CUSTOMER_ADDRESS_IS_ACTIVE';
45
    public const CUSTOMER_ADDRESS_IS_DEFAULT = 'CHECKOUT__CUSTOMER_ADDRESS_IS_DEFAULT';
46
    public const CUSTOMER_IS_ALREADY_CONFIRMED = 'CHECKOUT__CUSTOMER_IS_ALREADY_CONFIRMED';
47
    public const CUSTOMER_GROUP_REGISTRATION_NOT_FOUND = 'CHECKOUT__CUSTOMER_GROUP_REGISTRATION_NOT_FOUND';
48
    public const CUSTOMER_NOT_FOUND_BY_HASH = 'CHECKOUT__CUSTOMER_NOT_FOUND_BY_HASH';
49
    public const CUSTOMER_NOT_FOUND_BY_ID = 'CHECKOUT__CUSTOMER_NOT_FOUND_BY_ID';
50
    public const CUSTOMER_RECOVERY_HASH_EXPIRED = 'CHECKOUT__CUSTOMER_RECOVERY_HASH_EXPIRED';
51
    public const WISHLIST_IS_NOT_ACTIVATED = 'CHECKOUT__WISHLIST_IS_NOT_ACTIVATED';
52
    public const WISHLIST_NOT_FOUND = 'CHECKOUT__WISHLIST_NOT_FOUND';
53
    public const COUNTRY_NOT_FOUND = 'CHECKOUT__CUSTOMER_COUNTRY_NOT_FOUND';
54
    public const DUPLICATE_WISHLIST_PRODUCT = 'CHECKOUT__DUPLICATE_WISHLIST_PRODUCT';
55
    public const CUSTOMER_IS_INACTIVE = 'CHECKOUT__CUSTOMER_IS_INACTIVE';
56
    public const LEGACY_PASSWORD_ENCODER_NOT_FOUND = 'CHECKOUT__LEGACY_PASSWORD_ENCODER_NOT_FOUND';
57
    public const NO_HASH_PROVIDED = 'CHECKOUT__NO_HASH_PROVIDED';
58
    public const WISHLIST_PRODUCT_NOT_FOUND = 'CHECKOUT__WISHLIST_PRODUCT_NOT_FOUND';
59
    public const CUSTOMER_AUTH_THROTTLED = 'CHECKOUT__CUSTOMER_AUTH_THROTTLED';
60
    public const CUSTOMER_OPTIN_NOT_COMPLETED = 'CHECKOUT__CUSTOMER_OPTIN_NOT_COMPLETED';
61
    public const CUSTOMER_CHANGE_PAYMENT_ERROR = 'CHECKOUT__CUSTOMER_CHANGE_PAYMENT_METHOD_NOT_FOUND';
62
63
    public static function customerGroupNotFound(string $id): self
64
    {
65
        return new self(
66
            Response::HTTP_BAD_REQUEST,
67
            self::CUSTOMER_GROUP_NOT_FOUND,
68
            'Customer group with id "{{ id }}" not found',
69
            ['id' => $id]
70
        );
71
    }
72
73
    public static function groupRequestNotFound(string $id): self
74
    {
75
        return new self(
76
            Response::HTTP_BAD_REQUEST,
77
            self::CUSTOMER_GROUP_REQUEST_NOT_FOUND,
78
            'Group request for customer "{{ id }}" is not found',
79
            ['id' => $id]
80
        );
81
    }
82
83
    /**
84
     * @param string[] $ids
85
     */
86
    public static function customersNotFound(array $ids): self
87
    {
88
        return new self(
89
            Response::HTTP_NOT_FOUND,
90
            self::CUSTOMERS_NOT_FOUND,
91
            'These customers "{{ ids }}" are not found',
92
            ['ids' => implode(', ', $ids)]
93
        );
94
    }
95
96
    public static function customerNotLoggedIn(): self
97
    {
98
        return new self(
99
            Response::HTTP_FORBIDDEN,
100
            self::CUSTOMER_NOT_LOGGED_IN,
101
            'Customer is not logged in.',
102
        );
103
    }
104
105
    public static function downloadFileNotFound(string $downloadId): ShopwareHttpException
106
    {
107
        return new self(
108
            Response::HTTP_NOT_FOUND,
109
            self::LINE_ITEM_DOWNLOAD_FILE_NOT_FOUND,
110
            'Line item download file with id "{{ downloadId }}" not found.',
111
            ['downloadId' => $downloadId]
112
        );
113
    }
114
115
    public static function customerIdsParameterIsMissing(): ShopwareHttpException
116
    {
117
        return new self(
118
            Response::HTTP_BAD_REQUEST,
119
            self::CUSTOMER_IDS_PARAMETER_IS_MISSING,
120
            'Parameter "customerIds" is missing.',
121
        );
122
    }
123
124
    public static function unknownPaymentMethod(string $paymentMethodId): ShopwareHttpException
125
    {
126
        return new self(
127
            Response::HTTP_BAD_REQUEST,
128
            self::CUSTOMER_CHANGE_PAYMENT_ERROR,
129
            'Change Payment to method {{ paymentMethodId }} not possible.',
130
            ['paymentMethodId' => $paymentMethodId]
131
        );
132
    }
133
134
    public static function productIdsParameterIsMissing(): ShopwareHttpException
135
    {
136
        return new self(
137
            Response::HTTP_BAD_REQUEST,
138
            self::PRODUCT_IDS_PARAMETER_IS_MISSING,
139
            'Parameter "productIds" is missing.',
140
        );
141
    }
142
143
    public static function addressNotFound(string $id): AddressNotFoundException
144
    {
145
        return new AddressNotFoundException($id);
146
    }
147
148
    public static function countryNotFound(string $countryId): HttpException
149
    {
150
        if (!Feature::isActive('v6.6.0.0')) {
151
            return new CountryNotFoundException($countryId);
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\System\Cou...ountryNotFoundException has been deprecated: tag:v6.6.0 - reason:remove-exception - will be removed, use CountryException::countryNotFound instead ( Ignorable by Annotation )

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

151
            return /** @scrutinizer ignore-deprecated */ new CountryNotFoundException($countryId);
Loading history...
152
        }
153
154
        return new self(
155
            Response::HTTP_BAD_REQUEST,
156
            self::COUNTRY_NOT_FOUND,
157
            'Country with id "{{ countryId }}" not found.',
158
            ['countryId' => $countryId]
159
        );
160
    }
161
162
    public static function badCredentials(): BadCredentialsException
163
    {
164
        return new BadCredentialsException();
165
    }
166
167
    public static function cannotDeleteActiveAddress(string $id): ShopwareHttpException
168
    {
169
        if (!Feature::isActive('v6.6.0.0')) {
170
            return new CannotDeleteActiveAddressException($id);
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\Checkout\C...eActiveAddressException has been deprecated: tag:v6.6.0 - reason:remove-exception - will be removed, use CustomerException::cannotDeleteActiveAddress instead ( Ignorable by Annotation )

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

170
            return /** @scrutinizer ignore-deprecated */ new CannotDeleteActiveAddressException($id);
Loading history...
171
        }
172
173
        return new self(
174
            Response::HTTP_BAD_REQUEST,
175
            self::CUSTOMER_ADDRESS_IS_ACTIVE,
176
            'Customer address with id "{{ addressId }}" is an active address and cannot be deleted.',
177
            ['addressId' => $id]
178
        );
179
    }
180
181
    public static function cannotDeleteDefaultAddress(string $id): CannotDeleteDefaultAddressException
182
    {
183
        return new CannotDeleteDefaultAddressException($id);
184
    }
185
186
    public static function customerAlreadyConfirmed(string $id): CustomerAlreadyConfirmedException
187
    {
188
        return new CustomerAlreadyConfirmedException($id);
189
    }
190
191
    public static function customerGroupRegistrationConfigurationNotFound(string $customerGroupId): ShopwareHttpException
192
    {
193
        if (!Feature::isActive('v6.6.0.0')) {
194
            return new CustomerGroupRegistrationConfigurationNotFound($customerGroupId);
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\Checkout\C...onConfigurationNotFound has been deprecated: tag:v6.6.0 - reason:remove-exception - will be removed, use CustomerException::customerGroupRegistrationConfigurationNotFound instead ( Ignorable by Annotation )

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

194
            return /** @scrutinizer ignore-deprecated */ new CustomerGroupRegistrationConfigurationNotFound($customerGroupId);
Loading history...
195
        }
196
197
        return new self(
198
            Response::HTTP_NOT_FOUND,
199
            self::CUSTOMER_GROUP_REGISTRATION_NOT_FOUND,
200
            'Customer group registration for id {{ customerGroupId }} not found.',
201
            ['customerGroupId' => $customerGroupId]
202
        );
203
    }
204
205
    public static function customerNotFoundByHash(string $hash): CustomerNotFoundByHashException
206
    {
207
        return new CustomerNotFoundByHashException($hash);
208
    }
209
210
    public static function customerNotFoundByIdException(string $id): CustomerNotFoundByIdException
211
    {
212
        return new CustomerNotFoundByIdException($id);
213
    }
214
215
    public static function customerNotFound(string $email): CustomerNotFoundException
216
    {
217
        return new CustomerNotFoundException($email);
218
    }
219
220
    public static function customerRecoveryHashExpired(string $hash): CustomerRecoveryHashExpiredException
221
    {
222
        return new CustomerRecoveryHashExpiredException($hash);
223
    }
224
225
    public static function customerWishlistNotActivated(): ShopwareHttpException
226
    {
227
        if (!Feature::isActive('v6.6.0.0')) {
228
            return new CustomerWishlistNotActivatedException();
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\Checkout\C...stNotActivatedException has been deprecated: tag:v6.6.0 - reason:remove-exception - will be removed, use CustomerException::customerWishlistNotActivated instead ( Ignorable by Annotation )

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

228
            return /** @scrutinizer ignore-deprecated */ new CustomerWishlistNotActivatedException();
Loading history...
229
        }
230
231
        return new self(
232
            Response::HTTP_FORBIDDEN,
233
            self::WISHLIST_IS_NOT_ACTIVATED,
234
            'Wishlist is not activated!'
235
        );
236
    }
237
238
    public static function customerWishlistNotFound(): CustomerWishlistNotFoundException
239
    {
240
        return new CustomerWishlistNotFoundException();
241
    }
242
243
    public static function duplicateWishlistProduct(): DuplicateWishlistProductException
244
    {
245
        return new DuplicateWishlistProductException();
246
    }
247
248
    public static function legacyPasswordEncoderNotFound(string $encoder): ShopwareHttpException
249
    {
250
        if (!Feature::isActive('v6.6.0.0')) {
251
            return new LegacyPasswordEncoderNotFoundException($encoder);
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\Checkout\C...ncoderNotFoundException has been deprecated: tag:v6.6.0 - reason:remove-exception - will be removed, use CustomerException::legacyPasswordEncoderNotFound instead ( Ignorable by Annotation )

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

251
            return /** @scrutinizer ignore-deprecated */ new LegacyPasswordEncoderNotFoundException($encoder);
Loading history...
252
        }
253
254
        return new self(
255
            Response::HTTP_BAD_REQUEST,
256
            self::LEGACY_PASSWORD_ENCODER_NOT_FOUND,
257
            'Encoder with name "{{ encoder }}" not found.',
258
            ['encoder' => $encoder]
259
        );
260
    }
261
262
    public static function noHashProvided(): ShopwareHttpException
263
    {
264
        if (!Feature::isActive('v6.6.0.0')) {
265
            return new NoHashProvidedException();
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\Checkout\C...NoHashProvidedException has been deprecated: tag:v6.6.0 - reason:remove-exception - will be removed, use CustomerException::noHashProvided instead ( Ignorable by Annotation )

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

265
            return /** @scrutinizer ignore-deprecated */ new NoHashProvidedException();
Loading history...
266
        }
267
268
        return new self(
269
            Response::HTTP_NOT_FOUND,
270
            self::NO_HASH_PROVIDED,
271
            'The given hash is empty.'
272
        );
273
    }
274
275
    public static function wishlistProductNotFound(string $productId): ShopwareHttpException
276
    {
277
        if (!Feature::isActive('v6.6.0.0')) {
278
            return new WishlistProductNotFoundException($productId);
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\Checkout\C...roductNotFoundException has been deprecated: tag:v6.6.0 - reason:remove-exception - will be removed, use CustomerException::wishlistProductNotFound instead ( Ignorable by Annotation )

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

278
            return /** @scrutinizer ignore-deprecated */ new WishlistProductNotFoundException($productId);
Loading history...
279
        }
280
281
        return new self(
282
            Response::HTTP_NOT_FOUND,
283
            self::WISHLIST_PRODUCT_NOT_FOUND,
284
            'Wishlist product with id {{ productId }} not found',
285
            ['productId' => $productId]
286
        );
287
    }
288
289
    public static function inactiveCustomer(string $id): ShopwareHttpException
290
    {
291
        if (!Feature::isActive('v6.6.0.0')) {
292
            return new InactiveCustomerException($id);
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\Checkout\C...activeCustomerException has been deprecated: tag:v6.6.0 - reason:remove-exception - Will be removed without replacement, not in use any more. Use `BadCredentialsException` or `CustomerOptinNotCompletedException` instead ( Ignorable by Annotation )

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

292
            return /** @scrutinizer ignore-deprecated */ new InactiveCustomerException($id);
Loading history...
293
        }
294
295
        return self::customerOptinNotCompleted($id);
296
    }
297
298
    public static function customerOptinNotCompleted(string $id, ?string $message = null): CustomerOptinNotCompletedException
299
    {
300
        return new CustomerOptinNotCompletedException($id, $message);
301
    }
302
303
    public static function customerAuthThrottledException(int $waitTime, ?\Throwable $e = null): CustomerAuthThrottledException
304
    {
305
        return new CustomerAuthThrottledException(
306
            $waitTime,
307
            $e
308
        );
309
    }
310
}
311