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

GroupExceptionsProcessor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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