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

ErrorHandlerInterceptor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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