Passed
Push — trunk ( 04b0a9...ad65a5 )
by Christian
24:30 queued 13:01
created

DocumentException::documentNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Document;
4
5
use Shopware\Core\Checkout\Document\Exception\InvalidDocumentGeneratorTypeException;
6
use Shopware\Core\Framework\HttpException;
7
use Shopware\Core\Framework\Log\Package;
8
use Symfony\Component\HttpFoundation\Response;
9
10
#[Package('customer-order')]
11
class DocumentException extends HttpException
12
{
13
    public const INVALID_DOCUMENT_GENERATOR_TYPE_CODE = 'DOCUMENT__INVALID_GENERATOR_TYPE';
14
15
    public const ORDER_NOT_FOUND = 'DOCUMENT__ORDER_NOT_FOUND';
16
17
    public const DOCUMENT_NOT_FOUND = 'DOCUMENT__DOCUMENT_NOT_FOUND';
18
19
    public const GENERATION_ERROR = 'DOCUMENT__GENERATION_ERROR';
20
21
    public static function invalidDocumentGeneratorType(string $type): self
22
    {
23
        return new InvalidDocumentGeneratorTypeException($type);
24
    }
25
26
    public static function orderNotFound(string $orderId, ?\Throwable $e = null): self
27
    {
28
        return new self(
29
            Response::HTTP_NOT_FOUND,
30
            self::ORDER_NOT_FOUND,
31
            'The order with id {{ orderId }} is invalid or could not be found.',
32
            [
33
                'orderId' => $orderId,
34
            ],
35
            $e
36
        );
37
    }
38
39
    public static function documentNotFound(string $documentId, ?\Throwable $e = null): self
40
    {
41
        return new self(
42
            Response::HTTP_NOT_FOUND,
43
            self::DOCUMENT_NOT_FOUND,
44
            'The document with id "{{ documentId }}" is invalid or could not be found.',
45
            [
46
                'documentId' => $documentId,
47
            ],
48
            $e
49
        );
50
    }
51
52
    public static function generationError(?string $message = null, ?\Throwable $e = null): self
53
    {
54
        return new self(
55
            Response::HTTP_NOT_FOUND,
56
            self::GENERATION_ERROR,
57
            sprintf('Unable to generate document. %s', $message),
58
            [
59
                '$message' => $message,
60
            ],
61
            $e
62
        );
63
    }
64
}
65