SentryErrorListener   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 34
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 9 1
A __construct() 0 3 1
1
<?php
2
3
namespace Dasao\SentryLogger\Listener;
4
5
use Dasao\SentryLogger\Log\SentryLoggerInterface;
6
use Exception;
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Throwable;
10
11
/**
12
 * Class SentryErrorListener
13
 *
14
 * PHP Version 7
15
 *
16
 * @category  PHP
17
 * @package   Dasao\SentryLogger\Listener
18
 * @author    Dasao <[email protected]>
19
 * @copyright 2014-2017 Dasao
20
 * @license   Proprietary http://www.das-ao.com
21
 */
22
class SentryErrorListener
23
{
24
    /** @var SentryLoggerInterface */
25
    protected $sentryLogger;
26
27
    /**
28
     * SentryErrorListener constructor.
29
     *
30
     * @param SentryLoggerInterface $sentryLogger
31
     */
32
    public function __construct(SentryLoggerInterface $sentryLogger)
33
    {
34
        $this->sentryLogger = $sentryLogger;
35
    }
36
37
    /**
38
     * Invoke the listener.
39
     *
40
     *
41
     * @param Throwable|Exception    $error    The error.
42
     * @param ServerRequestInterface $request  The request.
43
     * @param ResponseInterface      $response The response.
44
     *
45
     * @return void
46
     */
47
    public function __invoke($error, ServerRequestInterface $request, ResponseInterface $response)
48
    {
49
        $context = [
50
            'method'     => $request->getMethod(),
51
            'statusCode' => $response->getStatusCode(),
52
            'uri'        => (string)$request->getUri(),
53
        ];
54
55
        $this->sentryLogger->exception($error, $context);
56
    }
57
58
}
59