Passed
Push — trunk ( 2ef630...41af6c )
by Christian
10:02 queued 15s
created

CustomerException::addressNotFound()   A

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 1
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 Symfony\Component\HttpFoundation\Response;
29
30
#[Package('customer-order')]
31
class CustomerException extends HttpException
32
{
33
    public const CUSTOMERS_NOT_FOUND = 'CHECKOUT__CUSTOMERS_NOT_FOUND';
34
    public const CUSTOMER_NOT_FOUND = 'CHECKOUT__CUSTOMER_NOT_FOUND';
35
    public const CUSTOMER_GROUP_NOT_FOUND = 'CHECKOUT__CUSTOMER_GROUP_NOT_FOUND';
36
    public const CUSTOMER_GROUP_REQUEST_NOT_FOUND = 'CHECKOUT__CUSTOMER_GROUP_REQUEST_NOT_FOUND';
37
    public const CUSTOMER_NOT_LOGGED_IN = 'CHECKOUT__CUSTOMER_NOT_LOGGED_IN';
38
    public const LINE_ITEM_DOWNLOAD_FILE_NOT_FOUND = 'CHECKOUT__LINE_ITEM_DOWNLOAD_FILE_NOT_FOUND';
39
    public const CUSTOMER_IDS_PARAMETER_IS_MISSING = 'CHECKOUT__CUSTOMER_IDS_PARAMETER_IS_MISSING';
40
    public const PRODUCT_IDS_PARAMETER_IS_MISSING = 'CHECKOUT__PRODUCT_IDS_PARAMETER_IS_MISSING';
41
    public const CUSTOMER_ADDRESS_NOT_FOUND = 'CHECKOUT__CUSTOMER_ADDRESS_NOT_FOUND';
42
    public const CUSTOMER_AUTH_BAD_CREDENTIALS = 'CHECKOUT__CUSTOMER_AUTH_BAD_CREDENTIALS';
43
    public const CUSTOMER_ADDRESS_IS_ACTIVE = 'CHECKOUT__CUSTOMER_ADDRESS_IS_ACTIVE';
44
    public const CUSTOMER_ADDRESS_IS_DEFAULT = 'CHECKOUT__CUSTOMER_ADDRESS_IS_DEFAULT';
45
    public const CUSTOMER_IS_ALREADY_CONFIRMED = 'CHECKOUT__CUSTOMER_IS_ALREADY_CONFIRMED';
46
    public const CUSTOMER_GROUP_REGISTRATION_NOT_FOUND = 'CHECKOUT__CUSTOMER_GROUP_REGISTRATION_NOT_FOUND';
47
    public const CUSTOMER_NOT_FOUND_BY_HASH = 'CHECKOUT__CUSTOMER_NOT_FOUND_BY_HASH';
48
    public const CUSTOMER_NOT_FOUND_BY_ID = 'CHECKOUT__CUSTOMER_NOT_FOUND_BY_ID';
49
    public const CUSTOMER_RECOVERY_HASH_EXPIRED = 'CHECKOUT__CUSTOMER_RECOVERY_HASH_EXPIRED';
50
    public const WISHLIST_IS_NOT_ACTIVATED = 'CHECKOUT__WISHLIST_IS_NOT_ACTIVATED';
51
    public const WISHLIST_NOT_FOUND = 'CHECKOUT__WISHLIST_NOT_FOUND';
52
    public const DUPLICATE_WISHLIST_PRODUCT = 'CHECKOUT__DUPLICATE_WISHLIST_PRODUCT';
53
    public const CUSTOMER_IS_INACTIVE = 'CHECKOUT__CUSTOMER_IS_INACTIVE';
54
    public const LEGACY_PASSWORD_ENCODER_NOT_FOUND = 'CHECKOUT__LEGACY_PASSWORD_ENCODER_NOT_FOUND';
55
    public const NO_HASH_PROVIDED = 'CHECKOUT__NO_HASH_PROVIDED';
56
    public const WISHLIST_PRODUCT_NOT_FOUND = 'CHECKOUT__WISHLIST_PRODUCT_NOT_FOUND';
57
    public const CUSTOMER_AUTH_THROTTLED = 'CHECKOUT__CUSTOMER_AUTH_THROTTLED';
58
    public const CUSTOMER_OPTIN_NOT_COMPLETED = 'CHECKOUT__CUSTOMER_OPTIN_NOT_COMPLETED';
59
60
    public static function customerGroupNotFound(string $id): self
61
    {
62
        return new self(
63
            Response::HTTP_BAD_REQUEST,
64
            self::CUSTOMER_GROUP_NOT_FOUND,
65
            'Customer group with id "{{ id }}" not found',
66
            ['id' => $id]
67
        );
68
    }
69
70
    public static function groupRequestNotFound(string $id): self
71
    {
72
        return new self(
73
            Response::HTTP_BAD_REQUEST,
74
            self::CUSTOMER_GROUP_REQUEST_NOT_FOUND,
75
            'Group request for customer "{{ id }}" is not found',
76
            ['id' => $id]
77
        );
78
    }
79
80
    /**
81
     * @param string[] $ids
82
     */
83
    public static function customersNotFound(array $ids): self
84
    {
85
        return new self(
86
            Response::HTTP_NOT_FOUND,
87
            self::CUSTOMERS_NOT_FOUND,
88
            'These customers "{{ ids }}" are not found',
89
            ['ids' => implode(', ', $ids)]
90
        );
91
    }
92
93
    public static function customerNotLoggedIn(): self
94
    {
95
        return new self(
96
            Response::HTTP_FORBIDDEN,
97
            self::CUSTOMER_NOT_LOGGED_IN,
98
            'Customer is not logged in.',
99
        );
100
    }
101
102
    public static function downloadFileNotFound(string $downloadId): ShopwareHttpException
103
    {
104
        return new self(
105
            Response::HTTP_NOT_FOUND,
106
            self::LINE_ITEM_DOWNLOAD_FILE_NOT_FOUND,
107
            'Line item download file with id "{{ downloadId }}" not found.',
108
            ['downloadId' => $downloadId]
109
        );
110
    }
111
112
    public static function customerIdsParameterIsMissing(): ShopwareHttpException
113
    {
114
        return new self(
115
            Response::HTTP_BAD_REQUEST,
116
            self::CUSTOMER_IDS_PARAMETER_IS_MISSING,
117
            'Parameter "customerIds" is missing.',
118
        );
119
    }
120
121
    public static function productIdsParameterIsMissing(): ShopwareHttpException
122
    {
123
        return new self(
124
            Response::HTTP_BAD_REQUEST,
125
            self::PRODUCT_IDS_PARAMETER_IS_MISSING,
126
            'Parameter "productIds" is missing.',
127
        );
128
    }
129
130
    public static function addressNotFound(string $id): AddressNotFoundException
131
    {
132
        return new AddressNotFoundException($id);
133
    }
134
135
    public static function badCredentials(): BadCredentialsException
136
    {
137
        return new BadCredentialsException();
138
    }
139
140
    public static function cannotDeleteActiveAddress(string $id): ShopwareHttpException
141
    {
142
        if (!Feature::isActive('v6.6.0.0')) {
143
            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

143
            return /** @scrutinizer ignore-deprecated */ new CannotDeleteActiveAddressException($id);
Loading history...
144
        }
145
146
        return new self(
147
            Response::HTTP_BAD_REQUEST,
148
            self::CUSTOMER_ADDRESS_IS_ACTIVE,
149
            'Customer address with id "{{ addressId }}" is an active address and cannot be deleted.',
150
            ['addressId' => $id]
151
        );
152
    }
153
154
    public static function cannotDeleteDefaultAddress(string $id): CannotDeleteDefaultAddressException
155
    {
156
        return new CannotDeleteDefaultAddressException($id);
157
    }
158
159
    public static function customerAlreadyConfirmed(string $id): CustomerAlreadyConfirmedException
160
    {
161
        return new CustomerAlreadyConfirmedException($id);
162
    }
163
164
    public static function customerGroupRegistrationConfigurationNotFound(string $customerGroupId): ShopwareHttpException
165
    {
166
        if (!Feature::isActive('v6.6.0.0')) {
167
            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

167
            return /** @scrutinizer ignore-deprecated */ new CustomerGroupRegistrationConfigurationNotFound($customerGroupId);
Loading history...
168
        }
169
170
        return new self(
171
            Response::HTTP_NOT_FOUND,
172
            self::CUSTOMER_GROUP_REGISTRATION_NOT_FOUND,
173
            'Customer group registration for id {{ customerGroupId }} not found.',
174
            ['customerGroupId' => $customerGroupId]
175
        );
176
    }
177
178
    public static function customerNotFoundByHash(string $hash): CustomerNotFoundByHashException
179
    {
180
        return new CustomerNotFoundByHashException($hash);
181
    }
182
183
    public static function customerNotFoundByIdException(string $id): CustomerNotFoundByIdException
184
    {
185
        return new CustomerNotFoundByIdException($id);
186
    }
187
188
    public static function customerNotFound(string $email): CustomerNotFoundException
189
    {
190
        return new CustomerNotFoundException($email);
191
    }
192
193
    public static function customerRecoveryHashExpired(string $hash): CustomerRecoveryHashExpiredException
194
    {
195
        return new CustomerRecoveryHashExpiredException($hash);
196
    }
197
198
    public static function customerWishlistNotActivated(): ShopwareHttpException
199
    {
200
        if (!Feature::isActive('v6.6.0.0')) {
201
            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

201
            return /** @scrutinizer ignore-deprecated */ new CustomerWishlistNotActivatedException();
Loading history...
202
        }
203
204
        return new self(
205
            Response::HTTP_FORBIDDEN,
206
            self::WISHLIST_IS_NOT_ACTIVATED,
207
            'Wishlist is not activated!'
208
        );
209
    }
210
211
    public static function customerWishlistNotFound(): CustomerWishlistNotFoundException
212
    {
213
        return new CustomerWishlistNotFoundException();
214
    }
215
216
    public static function duplicateWishlistProduct(): DuplicateWishlistProductException
217
    {
218
        return new DuplicateWishlistProductException();
219
    }
220
221
    public static function legacyPasswordEncoderNotFound(string $encoder): ShopwareHttpException
222
    {
223
        if (!Feature::isActive('v6.6.0.0')) {
224
            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

224
            return /** @scrutinizer ignore-deprecated */ new LegacyPasswordEncoderNotFoundException($encoder);
Loading history...
225
        }
226
227
        return new self(
228
            Response::HTTP_BAD_REQUEST,
229
            self::LEGACY_PASSWORD_ENCODER_NOT_FOUND,
230
            'Encoder with name "{{ encoder }}" not found.',
231
            ['encoder' => $encoder]
232
        );
233
    }
234
235
    public static function noHashProvided(): ShopwareHttpException
236
    {
237
        if (!Feature::isActive('v6.6.0.0')) {
238
            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

238
            return /** @scrutinizer ignore-deprecated */ new NoHashProvidedException();
Loading history...
239
        }
240
241
        return new self(
242
            Response::HTTP_NOT_FOUND,
243
            self::NO_HASH_PROVIDED,
244
            'The given hash is empty.'
245
        );
246
    }
247
248
    public static function wishlistProductNotFound(string $productId): ShopwareHttpException
249
    {
250
        if (!Feature::isActive('v6.6.0.0')) {
251
            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

251
            return /** @scrutinizer ignore-deprecated */ new WishlistProductNotFoundException($productId);
Loading history...
252
        }
253
254
        return new self(
255
            Response::HTTP_NOT_FOUND,
256
            self::WISHLIST_PRODUCT_NOT_FOUND,
257
            'Wishlist product with id {{ productId }} not found',
258
            ['productId' => $productId]
259
        );
260
    }
261
262
    public static function inactiveCustomer(string $id): ShopwareHttpException
263
    {
264
        if (!Feature::isActive('v6.6.0.0')) {
265
            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

265
            return /** @scrutinizer ignore-deprecated */ new InactiveCustomerException($id);
Loading history...
266
        }
267
268
        return self::customerOptinNotCompleted($id);
269
    }
270
271
    public static function customerOptinNotCompleted(string $id, ?string $message = null): CustomerOptinNotCompletedException
272
    {
273
        return new CustomerOptinNotCompletedException($id, $message);
274
    }
275
276
    public static function customerAuthThrottledException(int $waitTime, ?\Throwable $e = null): CustomerAuthThrottledException
277
    {
278
        return new CustomerAuthThrottledException(
279
            $waitTime,
280
            $e
281
        );
282
    }
283
}
284