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::__invoke()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 7.0671

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 18
ccs 8
cts 9
cp 0.8889
rs 8.8333
cc 7
nc 4
nop 1
crap 7.0671
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