Passed
Pull Request — master (#15)
by
unknown
02:21
created

SentryMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 7 2
A __construct() 0 3 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 and console 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
    private HubInterface $hub;
21
22 2
    public function __construct(HubInterface $hub)
23
    {
24 2
        $this->hub = $hub;
25
    }
26
27 2
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
28
    {
29
        try {
30 2
            return $handler->handle($request);
31 1
        } catch (Throwable $e) {
32 1
            $this->hub->captureException($e);
33 1
            throw $e;
34
        }
35
    }
36
}
37