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::encode()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 28
rs 9.7
ccs 0
cts 11
cp 0
cc 4
nc 4
nop 1
crap 20
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