Passed
Push — master ( fb6040...1f20c0 )
by
unknown
02:28
created

SentryMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 13
ccs 6
cts 6
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 7 2
A __construct() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Sentry;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Server\MiddlewareInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
use Sentry\State\HubInterface;
12
use Throwable;
13
14
/**
15
 * Catches web application exceptions and forwards them to Sentry.
16
 * In order to catch all exceptions, add it right after `ErrorCatcher` in the main middleware set.
17
 */
18
final class SentryMiddleware implements MiddlewareInterface
19
{
20 3
    public function __construct(private HubInterface $hub)
21
    {
22
    }
23
24 3
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
25
    {
26
        try {
27 3
            return $handler->handle($request);
28 2
        } catch (Throwable $e) {
29 2
            $this->hub->captureException($e);
30 2
            throw $e;
31
        }
32
    }
33
}
34