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

SalesChannelException   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 46
dl 0
loc 106
rs 10
c 1
b 0
f 0
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A countryStateNotFound() 0 7 1
A salesChannelNotFound() 0 7 1
A invalidLanguageId() 0 6 1
A countryNotFound() 0 7 1
A providedLanguageNotAvailable() 0 6 1
A noContextData() 0 7 1
A unknownPaymentMethod() 0 3 1
A languageNotFound() 0 3 1
A customerNotFoundByIdException() 0 3 1
A currencyNotFound() 0 7 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\System\SalesChannel;
4
5
use Shopware\Core\Checkout\Customer\Exception\CustomerNotFoundByIdException;
6
use Shopware\Core\Checkout\Payment\Exception\UnknownPaymentMethodException;
7
use Shopware\Core\Framework\HttpException;
8
use Shopware\Core\Framework\Log\Package;
9
use Shopware\Core\Framework\Routing\Exception\LanguageNotFoundException;
10
use Shopware\Core\Framework\ShopwareHttpException;
11
use Symfony\Component\HttpFoundation\Response;
12
13
#[Package('system-settings')]
14
class SalesChannelException extends HttpException
15
{
16
    final public const SALES_CHANNEL_DOES_NOT_EXISTS_EXCEPTION = 'SYSTEM__SALES_CHANNEL_DOES_NOT_EXISTS';
17
18
    final public const LANGUAGE_INVALID_EXCEPTION = 'SYSTEM__LANGUAGE_INVALID_EXCEPTION';
19
20
    final public const COUNTRY_DOES_NOT_EXISTS_EXCEPTION = 'SYSTEM__COUNTRY_DOES_NOT_EXISTS_EXCEPTION';
21
22
    final public const CURRENCY_DOES_NOT_EXISTS_EXCEPTION = 'SYSTEM__CURRENCY_DOES_NOT_EXISTS_EXCEPTION';
23
24
    final public const COUNTRY_STATE_DOES_NOT_EXISTS_EXCEPTION = 'SYSTEM__COUNTRY_STATE_DOES_NOT_EXISTS_EXCEPTION';
25
26
    /**
27
     * @deprecated tag:v6.6.0 - Will be removed as the name was misleading, use SALES_CHANNEL_LANGUAGE_NOT_AVAILABLE_EXCEPTION instead
28
     */
29
    final public const SALES_CHANNEL_NOT_AVAILABLE_EXCEPTION = self::SALES_CHANNEL_LANGUAGE_NOT_AVAILABLE_EXCEPTION;
30
31
    final public const SALES_CHANNEL_LANGUAGE_NOT_AVAILABLE_EXCEPTION = 'SYSTEM__SALES_CHANNEL_LANGUAGE_NOT_AVAILABLE_EXCEPTION';
32
33
    final public const NO_CONTEXT_DATA_EXCEPTION = 'SYSTEM__NO_CONTEXT_DATA_EXCEPTION';
34
35
    public static function salesChannelNotFound(string $salesChannelId): self
36
    {
37
        return new self(
38
            Response::HTTP_NOT_FOUND,
39
            self::SALES_CHANNEL_DOES_NOT_EXISTS_EXCEPTION,
40
            'Sales channel with id "{{ salesChannelId }}" not found or not valid!.',
41
            ['salesChannelId' => $salesChannelId]
42
        );
43
    }
44
45
    public static function currencyNotFound(string $currencyId): self
46
    {
47
        return new self(
48
            Response::HTTP_NOT_FOUND,
49
            self::CURRENCY_DOES_NOT_EXISTS_EXCEPTION,
50
            'Currency with id "{{ currencyId }}" not found!.',
51
            ['currencyId' => $currencyId]
52
        );
53
    }
54
55
    public static function countryStateNotFound(string $countryStateId): self
56
    {
57
        return new self(
58
            Response::HTTP_NOT_FOUND,
59
            self::COUNTRY_STATE_DOES_NOT_EXISTS_EXCEPTION,
60
            'Country state with id "{{ countryStateId }}" not found!.',
61
            ['countryStateId' => $countryStateId]
62
        );
63
    }
64
65
    public static function customerNotFoundByIdException(string $customerId): ShopwareHttpException
66
    {
67
        return new CustomerNotFoundByIdException($customerId);
68
    }
69
70
    public static function countryNotFound(string $countryId): self
71
    {
72
        return new self(
73
            Response::HTTP_NOT_FOUND,
74
            self::COUNTRY_DOES_NOT_EXISTS_EXCEPTION,
75
            'Country with id "{{ countryId }}" not found!.',
76
            ['countryId' => $countryId]
77
        );
78
    }
79
80
    public static function noContextData(string $salesChannelId): self
81
    {
82
        return new self(
83
            Response::HTTP_PRECONDITION_FAILED,
84
            self::NO_CONTEXT_DATA_EXCEPTION,
85
            'No context data found for SalesChannel "{{ salesChannelId }}"',
86
            ['salesChannelId' => $salesChannelId]
87
        );
88
    }
89
90
    public static function invalidLanguageId(): ShopwareHttpException
91
    {
92
        return new self(
93
            Response::HTTP_PRECONDITION_FAILED,
94
            self::LANGUAGE_INVALID_EXCEPTION,
95
            'Provided languageId is not a valid uuid',
96
        );
97
    }
98
99
    public static function languageNotFound(string $languageId): ShopwareHttpException
100
    {
101
        return new LanguageNotFoundException($languageId);
102
    }
103
104
    /**
105
     * @param array<string> $availableLanguages
106
     */
107
    public static function providedLanguageNotAvailable(string $languageId, array $availableLanguages): self
108
    {
109
        return new self(
110
            Response::HTTP_PRECONDITION_FAILED,
111
            self::SALES_CHANNEL_LANGUAGE_NOT_AVAILABLE_EXCEPTION,
112
            sprintf('Provided language "%s" is not in list of available languages: %s', $languageId, implode(', ', $availableLanguages)),
113
        );
114
    }
115
116
    public static function unknownPaymentMethod(string $paymentMethodId): ShopwareHttpException
117
    {
118
        return new UnknownPaymentMethodException($paymentMethodId);
119
    }
120
}
121