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.

Factory::message()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WyriHaximus\React\ChildProcess\Messenger\Messages;
6
7
use Doctrine\Inflector\InflectorFactory;
8
use Exception;
9
use Throwable;
10
11
use function Safe\json_decode;
12
13
final class Factory
14
{
15
    /**
16
     * @param array<mixed> $lineOptions
17
     */
18 11
    public static function fromLine(string $line, array $lineOptions): ActionableMessageInterface
19
    {
20 11
        $line   = json_decode($line, true);
21 11
        $method = InflectorFactory::create()->build()->camelize($line['type']);
22 11
        if ($method === 'secure') {
23 10
            return static::secureFromLine($line, $lineOptions);
24
        }
25
26 1
        if ($method === 'message') {
27
            return static::messageFromLine($line);
28
        }
29
30
        if ($method === 'error') {
31
            return static::errorFromLine($line);
32
        }
33
34 2
        if ($method === 'rpc') {
35
            return static::rpcFromLine($line);
36 2
        }
37
38
        if ($method === 'rpcError') {
39
            return static::rpcErrorFromLine($line);
40
        }
41
42
        if ($method === 'rpcSuccess') {
43
            return static::rpcSuccessFromLine($line);
44 2
        }
45
46 2
        /** @phpstan-ignore-next-line */
47
        throw new Exception('Unknown message type: ' . $line['type']);
48
    }
49
50
    /**
51
     * @param array<mixed> $payload
52
     */
53
    public static function message(array $payload = []): Message
54
    {
55
        return new Message(new Payload($payload));
56 6
    }
57
58 6
    public static function error(Throwable $payload): Error
59
    {
60
        return new Error($payload);
61
    }
62
63
    /**
64
     * @param array<mixed> $payload
65
     * @param mixed        $uniqid
66
     */
67
    public static function rpc(string $target, array $payload = [], $uniqid = ''): Rpc
68 3
    {
69
        return new Rpc($target, new Payload($payload), $uniqid);
70 3
    }
71
72
    public static function rpcError(string $uniqid, Throwable $et): RpcError
73
    {
74
        return new RpcError($uniqid, $et);
75
    }
76
77
    /**
78
     * @param array<mixed> $payload
79 3
     */
80
    public static function rpcSuccess(string $uniqid, array $payload = []): RpcSuccess
81 3
    {
82
        return new RpcSuccess($uniqid, new Payload($payload));
83
    }
84
85
    /**
86
     * @param array<mixed> $line
87
     * @param array<mixed> $lineOptions
88
     */
89
    private static function secureFromLine(array $line, array $lineOptions): ActionableMessageInterface
90 1
    {
91
        return SecureLine::fromLine($line, $lineOptions);
92 1
    }
93
94
    /**
95
     * @param array<mixed> $line
96
     */
97
    private static function messageFromLine(array $line): Message
98
    {
99
        return static::message($line['payload']);
100
    }
101
102
    /**
103 1
     * @param array<mixed> $line
104
     */
105 1
    private static function errorFromLine(array $line): Error
106
    {
107
        return static::error(LineDecoder::decode($line['payload'])['throwable']);
108
    }
109
110
    /**
111
     * @param array<mixed> $line
112
     */
113 1
    private static function rpcFromLine(array $line): Rpc
114
    {
115 1
        return static::rpc($line['target'], $line['payload'], $line['uniqid']);
116
    }
117
118
    /**
119
     * @param array<mixed> $line
120
     */
121
    private static function rpcErrorFromLine(array $line): RpcError
122
    {
123 1
        return static::rpcError($line['uniqid'], LineDecoder::decode($line['payload'])['throwable']);
124
    }
125 1
126
    /**
127
     * @param  array<mixed> $line
128
     */
129
    private static function rpcSuccessFromLine(array $line): RpcSuccess
130
    {
131
        return static::rpcSuccess($line['uniqid'], $line['payload']);
132
    }
133
}
134