Passed
Push — trunk ( fd0441...5431f0 )
by Christian
11:15 queued 14s
created

CustomerException::groupRequestNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 7
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\Framework\HttpException;
6
use Shopware\Core\Framework\Log\Package;
7
use Shopware\Core\Framework\ShopwareHttpException;
8
use Symfony\Component\HttpFoundation\Response;
9
10
#[Package('customer-order')]
11
class CustomerException extends HttpException
12
{
13
    public const CUSTOMER_NOT_FOUND = 'CHECKOUT__CUSTOMER_NOT_FOUND';
14
    public const CUSTOMER_GROUP_NOT_FOUND = 'CHECKOUT__CUSTOMER_GROUP_NOT_FOUND';
15
    public const CUSTOMER_GROUP_REQUEST_NOT_FOUND = 'CHECKOUT__CUSTOMER_GROUP_REQUEST_NOT_FOUND';
16
    public const CUSTOMER_NOT_LOGGED_IN = 'CHECKOUT__CUSTOMER_NOT_LOGGED_IN';
17
    public const LINE_ITEM_DOWNLOAD_FILE_NOT_FOUND = 'CHECKOUT__LINE_ITEM_DOWNLOAD_FILE_NOT_FOUND';
18
    public const CUSTOMER_IDS_PARAMETER_IS_MISSING = 'CHECKOUT__CUSTOMER_IDS_PARAMETER_IS_MISSING';
19
20
    public static function customerGroupNotFound(string $id): self
21
    {
22
        return new self(
23
            Response::HTTP_BAD_REQUEST,
24
            self::CUSTOMER_GROUP_NOT_FOUND,
25
            'Customer group with id "{{ id }}" not found',
26
            ['id' => $id]
27
        );
28
    }
29
30
    public static function groupRequestNotFound(string $id): self
31
    {
32
        return new self(
33
            Response::HTTP_BAD_REQUEST,
34
            self::CUSTOMER_GROUP_REQUEST_NOT_FOUND,
35
            'Group request for customer "{{ id }}" is not found',
36
            ['id' => $id]
37
        );
38
    }
39
40
    /**
41
     * @param string[] $ids
42
     */
43
    public static function customersNotFound(array $ids): self
44
    {
45
        return new self(
46
            Response::HTTP_NOT_FOUND,
47
            self::CUSTOMER_NOT_FOUND,
48
            'These customers "{{ ids }}" are not found',
49
            ['ids' => implode(', ', $ids)]
50
        );
51
    }
52
53
    public static function customerNotLoggedIn(): self
54
    {
55
        return new self(
56
            Response::HTTP_FORBIDDEN,
57
            self::CUSTOMER_NOT_LOGGED_IN,
58
            'Customer is not logged in.',
59
        );
60
    }
61
62
    public static function downloadFileNotFound(string $downloadId): ShopwareHttpException
63
    {
64
        return new self(
65
            Response::HTTP_NOT_FOUND,
66
            self::LINE_ITEM_DOWNLOAD_FILE_NOT_FOUND,
67
            'Line item download file with id "{{ downloadId }}" not found.',
68
            ['downloadId' => $downloadId]
69
        );
70
    }
71
72
    public static function customerIdsParameterIsMissing(): ShopwareHttpException
73
    {
74
        return new self(
75
            Response::HTTP_BAD_REQUEST,
76
            self::CUSTOMER_IDS_PARAMETER_IS_MISSING,
77
            'Parameter "customerIds" is missing.',
78
        );
79
    }
80
}
81