GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TraceProcessor   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 9
c 1
b 0
f 0
dl 0
loc 25
ccs 11
cts 12
cp 0.9167
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
B __invoke() 0 18 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WyriHaximus\Monolog\Processors;
6
7
use Monolog\LogRecord;
8
use Monolog\Processor\ProcessorInterface;
9
use Throwable;
10
11
use function array_key_exists;
12
use function debug_backtrace;
13
14
use const DEBUG_BACKTRACE_IGNORE_ARGS;
15
16
final class TraceProcessor implements ProcessorInterface
17 5
{
18
    /** @phpstan-ignore-next-line */
19 5
    public function __construct(private bool $always = false)
20 5
    {
21
    }
22
23
    public function __invoke(LogRecord $record): LogRecord
24
    {
25
        if (array_key_exists('exception', $record->context) && $record->context['exception'] instanceof Throwable) {
26 5
            $record->extra['trace'] = $record->context['exception']->getTrace();
27
            foreach ($record->extra['trace'] as $index => $line) {
28 5
                if (! array_key_exists('args', $line)) {
29 2
                    continue;
30 2
                }
31 2
32
                unset($record->extra['trace'][$index]['args']);
33
            }
34
        }
35 2
36
        if ($this->always && ! array_key_exists('trace', $record->extra)) {
37
            $record->extra['trace'] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
38
        }
39 5
40 1
        return $record;
41
    }
42
}
43