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

ErrorHandlerInterceptor::intercept()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 17
ccs 0
cts 13
cp 0
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 12
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