Passed
Push — master ( e7d330...e6cdc9 )
by Aleksei
11:08 queued 15s
created

ErrorHandlerInterceptor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 24
c 0
b 0
f 0
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A process() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Queue\Interceptor\Consume;
6
7
use Spiral\Core\CoreInterceptorInterface;
8
use Spiral\Core\CoreInterface;
9
use Spiral\Queue\Exception\StateException;
10
use Spiral\Queue\Failed\FailedJobHandlerInterface;
11
12
final class ErrorHandlerInterceptor implements CoreInterceptorInterface
13
{
14 6
    public function __construct(
15
        private readonly FailedJobHandlerInterface $handler
16
    ) {
17 6
    }
18
19
    /** @psalm-suppress ParamNameMismatch */
20 2
    public function process(string $name, string $action, array $parameters, CoreInterface $core): mixed
21
    {
22
        try {
23 2
            return $core->callAction($name, $action, $parameters);
24 1
        } catch (\Throwable $e) {
25 1
            if (!$e instanceof StateException) {
26 1
                $this->handler->handle(
27 1
                    $parameters['driver'],
28 1
                    $parameters['queue'],
29 1
                    $name,
30 1
                    $parameters['payload'],
31 1
                    $e
32 1
                );
33
            }
34
35 1
            throw $e;
36
        }
37
    }
38
}
39