Test Failed
Pull Request — master (#3)
by
unknown
18:49
created

GroupExceptionsProcessor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 29
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 19 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paysera\LoggingExtraBundle\Service\Processor;
6
7
use Monolog\Processor\ProcessorInterface;
8
use Sentry\SentryBundle\SentryBundle;
9
use Sentry\State\Scope;
10
11
/**
12
 * @php-cs-fixer-ignore Paysera/php_basic_code_style_chained_method_calls
13
 */
14
class GroupExceptionsProcessor implements ProcessorInterface
15
{
16
    private $exceptionsClassesToGroup;
17
18
    public function __construct(array $exceptionsClassesToGroup)
19
    {
20
        $this->exceptionsClassesToGroup = array_flip($exceptionsClassesToGroup);
21
    }
22
23
    public function __invoke(array $record)
24
    {
25
        if (!isset($record['context']['exception'])) {
26
            return $record;
27
        }
28
29
        $exception = $record['context']['exception'];
30
        $exceptionClass = get_class($exception);
31
32
        if (isset($this->exceptionsClassesToGroup[$exceptionClass])) {
33
            SentryBundle::getCurrentHub()
34
                ->configureScope(function (Scope $scope) use ($exceptionClass) {
35
                    $scope->setFingerprint([$exceptionClass]);
36
                })
37
            ;
38
        }
39
40
        return $record;
41
    }
42
}
43