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

ShippingMethodPriceExceptionHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 15
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A matchException() 0 7 2
A getPriority() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Shipping\Aggregate\ShippingMethodPrice;
4
5
use Shopware\Core\Checkout\Shipping\ShippingException;
6
use Shopware\Core\Framework\DataAbstractionLayer\Dbal\ExceptionHandlerInterface;
7
use Shopware\Core\Framework\Log\Package;
8
9
#[Package('checkout')]
10
class ShippingMethodPriceExceptionHandler implements ExceptionHandlerInterface
11
{
12
    public function getPriority(): int
13
    {
14
        return ExceptionHandlerInterface::PRIORITY_DEFAULT;
15
    }
16
17
    public function matchException(\Exception $e): ?\Exception
18
    {
19
        if (\preg_match('/SQLSTATE\[23000\]:.*1062 Duplicate.*shipping_method_price.uniq.shipping_method_quantity_start\'/', $e->getMessage())) {
20
            return ShippingException::duplicateShippingMethodPrice($e);
21
        }
22
23
        return null;
24
    }
25
}
26