Passed
Push — trunk ( ccf801...a9c55d )
by Christian
09:47 queued 12s
created

ThemeExceptionHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A matchException() 0 10 2
A getPriority() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Storefront\Theme\DataAbstractionLayer;
4
5
use Shopware\Core\Framework\DataAbstractionLayer\Dbal\ExceptionHandlerInterface;
6
use Shopware\Core\Framework\Log\Package;
7
use Shopware\Storefront\Theme\Exception\ThemeException;
8
9
/**
10
 * @internal
11
 */
12
#[Package('storefront')]
13
class ThemeExceptionHandler implements ExceptionHandlerInterface
14
{
15
    public function getPriority(): int
16
    {
17
        return ExceptionHandlerInterface::PRIORITY_DEFAULT;
18
    }
19
20
    public function matchException(\Exception $e): ?\Exception
21
    {
22
        if (preg_match(
23
            '/SQLSTATE\[23000]: Integrity constraint violation: 1451.*CONSTRAINT `fk.theme_media.media_id` FOREIGN KEY \(`media_id`\) REFERENCES `media` \(`id`\)/',
24
            $e->getMessage(),
25
        )) {
26
            return ThemeException::themeMediaStillInUse();
27
        }
28
29
        return null;
30
    }
31
}
32