Passed
Push — trunk ( 0cbe36...2f2498 )
by Christian
12:47 queued 13s
created

ShippingException::duplicateShippingMethodPrice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Shipping;
4
5
use Shopware\Core\Checkout\Shipping\Exception\ShippingMethodNotFoundException;
6
use Shopware\Core\Framework\Feature;
7
use Shopware\Core\Framework\HttpException;
8
use Shopware\Core\Framework\Log\Package;
9
use Symfony\Component\HttpFoundation\Response;
10
11
#[Package('checkout')]
12
class ShippingException extends HttpException
13
{
14
    final public const SHIPPING_METHOD_NOT_FOUND = 'CHECKOUT__SHIPPING_METHOD_NOT_FOUND';
15
16
    final public const SHIPPING_METHOD_DUPLICATE_PRICE = 'CHECKOUT__DUPLICATE_SHIPPING_METHOD_PRICE';
17
18
    public static function shippingMethodNotFound(string $id, ?\Throwable $e = null): self
19
    {
20
        if (!Feature::isActive('v6.6.0.0')) {
21
            return new ShippingMethodNotFoundException($id, $e);
22
        }
23
24
        return new self(
25
            Response::HTTP_BAD_REQUEST,
26
            self::SHIPPING_METHOD_NOT_FOUND,
27
            'Shipping method with id "{{ shippingMethodId }}" not found.',
28
            ['shippingMethodId' => $id],
29
            $e
30
        );
31
    }
32
33
    public static function duplicateShippingMethodPrice(?\Throwable $e = null): self
34
    {
35
        return new self(
36
            Response::HTTP_BAD_REQUEST,
37
            self::SHIPPING_METHOD_DUPLICATE_PRICE,
38
            'Shipping method price quantity already exists.',
39
            [],
40
            $e
41
        );
42
    }
43
}
44