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.

LineEncoder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 31.25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 23
c 1
b 0
f 0
dl 0
loc 42
rs 10
ccs 5
cts 16
cp 0.3125

1 Method

Rating   Name   Duplication   Size   Complexity  
A encode() 0 28 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WyriHaximus\React\ChildProcess\Messenger\Messages;
6
7
use Cake\Utility\Hash;
8
use Throwable;
9
10
use function WyriHaximus\throwable_encode;
11
12
final class LineEncoder
13
{
14
    public const META_KEY       = 'a';
15
    public const TYPE_KEY       = 'b';
16
    public const VALUE_KEY      = 'c';
17
    public const THROWABLES_KEY = 'd';
18 2
    public const TYPE_THROWABLE = 'e';
19
    public const TYPE_ARRAY     = 'f';
20 2
21
    /**
22 2
     * @param array<mixed>|Throwable $line
23 2
     *
24
     * @return array<mixed>
25 2
     */
26
    public static function encode($line): array
27
    {
28
        if ($line instanceof Throwable) {
29
            return [
30
                self::META_KEY => [
31
                    self::TYPE_KEY => self::TYPE_THROWABLE,
32
                ],
33
                self::VALUE_KEY => throwable_encode($line),
34
            ];
35
        }
36
37
        $throwables = [];
38
        $line       = Hash::flatten($line);
39
        foreach ($line as $key => $value) {
40
            if (! ($value instanceof Throwable)) {
41
                continue;
42
            }
43
44
            $throwables[] = $key;
45
            $line[$key]   = throwable_encode($value);
46
        }
47
48
        return [
49
            self::META_KEY => [
50
                self::TYPE_KEY => self::TYPE_ARRAY,
51
                self::THROWABLES_KEY => $throwables,
52
            ],
53
            self::VALUE_KEY => $line,
54
        ];
55
    }
56
}
57