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

ErrorHandlerInterceptor::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 16
c 0
b 0
f 0
ccs 12
cts 12
cp 1
rs 9.9
cc 3
nc 3
nop 4
crap 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