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.

ToContextProcessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 5
c 1
b 0
f 0
dl 0
loc 22
ccs 8
cts 9
cp 0.8889
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A __invoke() 0 11 3
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
10
use function array_key_exists;
11
12
final class ToContextProcessor implements ProcessorInterface
13
{
14
    /**
15 3
     * @param array<string> $keys
16
     *
17 3
     * @phpstan-ignore-next-line
18 3
     */
19
    public function __construct(private array $keys = ['channel', 'extra', 'datetime'])
20
    {
21
    }
22
23
    public function __invoke(LogRecord $record): LogRecord
24 3
    {
25
        foreach ($this->keys as $key) {
26 3
            if (! array_key_exists($key, $record->toArray())) {
27 3
                continue;
28
            }
29
30 3
            $record = $record->with(context: [$key => $record->toArray()[$key]] + $record->toArray()['context']);
31
        }
32
33 3
        return $record;
34
    }
35
}
36