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.

Rpc::handle()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 35
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2.0219

Importance

Changes 6
Bugs 0 Features 1
Metric Value
eloc 11
c 6
b 0
f 1
dl 0
loc 35
rs 9.9
ccs 14
cts 17
cp 0.8235
cc 2
nc 1
nop 2
crap 2.0219
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WyriHaximus\React\ChildProcess\Messenger\Messages;
6
7
use Closure;
8
use Exception;
9
use JsonSerializable;
10
use Throwable;
11
12
use function sprintf;
13
14
final class Rpc implements JsonSerializable, ActionableMessageInterface
15
{
16
    protected string $target;
17
18
    protected Payload $payload;
19
20
    protected string $uniqid;
21
22
    /** @phpstan-ignore-next-line  */
23
    public function __construct(string $target, Payload $payload, string $uniqid = '') /** @phpstan-ignore-line  */
24
    {
25
        $this->target  = $target;
26
        $this->payload = $payload;
27 10
        $this->uniqid  = $uniqid;
28
    }
29 10
30 10
    public function getPayload(): Payload
31 10
    {
32 10
        return $this->payload;
33
    }
34
35
    public function setUniqid(string $uniqid): self
36
    {
37 3
        return new self($this->target, $this->payload, $uniqid);
38
    }
39 3
40
    /**
41
     * @return array<string,string|mixed>
42
     */
43
    public function jsonSerialize(): array
44
    {
45
        return [
46 3
            'type' => 'rpc',
47
            'uniqid' => $this->uniqid,
48 3
            'target' => $this->target,
49
            'payload' => $this->payload,
50
        ];
51
    }
52
53
    public function handle(object $bindTo, string $source): void
54 9
    {
55
        $cb = Closure::fromCallable(function (string $target, Payload $payload, string $uniqid): void {
56
            /**
57 9
             * @psalm-suppress UndefinedMethod
58 9
             */
59 9
            if (! $this->hasRpc($target)) { /** @phpstan-ignore-line  */
0 ignored issues
show
Bug introduced by
The method hasRpc() does not exist on WyriHaximus\React\ChildP...\Messenger\Messages\Rpc. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
            if (! $this->/** @scrutinizer ignore-call */ hasRpc($target)) { /** @phpstan-ignore-line  */

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60 9
                $this->write($this->createLine(Factory::rpcError($uniqid, new Exception(sprintf('Rpc target <%s> doesn\'t exist', $target))))); /** @phpstan-ignore-line  */
0 ignored issues
show
Bug introduced by
The method createLine() does not exist on WyriHaximus\React\ChildP...\Messenger\Messages\Rpc. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
                $this->write($this->/** @scrutinizer ignore-call */ createLine(Factory::rpcError($uniqid, new Exception(sprintf('Rpc target <%s> doesn\'t exist', $target))))); /** @phpstan-ignore-line  */

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method write() does not exist on WyriHaximus\React\ChildP...\Messenger\Messages\Rpc. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
                $this->/** @scrutinizer ignore-call */ 
61
                       write($this->createLine(Factory::rpcError($uniqid, new Exception(sprintf('Rpc target <%s> doesn\'t exist', $target))))); /** @phpstan-ignore-line  */

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
62
                return;
63
            }
64
65
            /**
66
             * @psalm-suppress UndefinedMethod
67
             */
68 3
            $this->callRpc($target, $payload)->done( /** @phpstan-ignore-line  */
0 ignored issues
show
Bug introduced by
The method callRpc() does not exist on WyriHaximus\React\ChildP...\Messenger\Messages\Rpc. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
            $this->/** @scrutinizer ignore-call */ 
69
                   callRpc($target, $payload)->done( /** @phpstan-ignore-line  */

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
                function (array $payload) use ($uniqid): void {
70
                    /**
71 3
                     * @psalm-suppress UndefinedMethod
72
                     */
73
                    $this->write($this->createLine(Factory::rpcSuccess($uniqid, $payload))); /** @phpstan-ignore-line  */
74
                },
75
                function (Throwable $error) use ($uniqid): void {
76
                    /**
77 3
                     * @psalm-suppress UndefinedMethod
78
                     */
79 1
                    $this->write($this->createLine(Factory::rpcError($uniqid, $error))); /** @phpstan-ignore-line  */
80 3
                }
81
            );
82 2
        });
83 3
        $cb = $cb->bindTo($bindTo);
84 3
        /**
85
         * @psalm-suppress PossiblyInvalidFunctionCall
86 3
         */
87
        $cb($this->target, $this->payload, $this->uniqid);
88 3
    }
89
}
90