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.
Completed
Push — master ( 5f068e...1d0f69 )
by Cees-Jan
04:36
created

Rpc::handle()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2.0263

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 13
cts 16
cp 0.8125
rs 8.9713
c 0
b 0
f 0
cc 2
eloc 14
nc 1
nop 2
crap 2.0263
1
<?php
2
3
namespace WyriHaximus\React\ChildProcess\Messenger\Messages;
4
5
class Rpc implements \JsonSerializable, ActionableMessageInterface
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $target;
11
12
    /**
13
     * @var Payload
14
     */
15
    protected $payload;
16
17
    /**
18
     * @var string
19
     */
20
    protected $uniqid;
21
22
    /**
23
     * @param string  $target
24
     * @param Payload $payload
25
     * @param string  $uniqid
26
     */
27 10
    public function __construct($target, Payload $payload, $uniqid = '')
28
    {
29 10
        $this->target = $target;
30 10
        $this->payload = $payload;
31 10
        $this->uniqid = $uniqid;
32 10
    }
33
34
    /**
35
     * @return Payload
36
     */
37 3
    public function getPayload()
38
    {
39 3
        return $this->payload;
40
    }
41
42
    /**
43
     * @param $uniqid
44
     * @return static
45
     */
46 3
    public function setUniqid($uniqid)
47
    {
48 3
        return new static($this->target, $this->payload, $uniqid);
49
    }
50
51
    /**
52
     * @return string
53
     */
54 9
    public function jsonSerialize()
55
    {
56
        return [
57 9
            'type' => 'rpc',
58 9
            'uniqid' => $this->uniqid,
59 9
            'target' => $this->target,
60 9
            'payload' => $this->payload,
61
        ];
62
    }
63
64
    /**
65
     * @param $bindTo
66
     * @param $source
67
     */
68 3
    public function handle($bindTo, $source)
69
    {
70
        $cb = function ($target, $payload, $uniqid) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $cb. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
71 3
            if (!$this->hasRpc($target)) {
0 ignored issues
show
Bug introduced by
The method hasRpc() does not seem to exist on object<WyriHaximus\React...Messenger\Messages\Rpc>.

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...
72
                $this->write($this->createLine(Factory::rpcError($uniqid, new \Exception('Target doesn\'t exist'))));
0 ignored issues
show
Bug introduced by
The method createLine() does not seem to exist on object<WyriHaximus\React...Messenger\Messages\Rpc>.

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 seem to exist on object<WyriHaximus\React...Messenger\Messages\Rpc>.

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...
73
74
                return;
75
            }
76
77 3
            $this->callRpc($target, $payload)->done(
0 ignored issues
show
Bug introduced by
The method callRpc() does not seem to exist on object<WyriHaximus\React...Messenger\Messages\Rpc>.

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...
78
                function (array $payload) use ($uniqid) {
79 1
                    $this->write($this->createLine(Factory::rpcSuccess($uniqid, $payload)));
0 ignored issues
show
Bug introduced by
The method createLine() does not seem to exist on object<WyriHaximus\React...Messenger\Messages\Rpc>.

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 seem to exist on object<WyriHaximus\React...Messenger\Messages\Rpc>.

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...
80 3
                },
81
                function ($error) use ($uniqid) {
82 2
                    $this->write($this->createLine(Factory::rpcError($uniqid, $error)));
0 ignored issues
show
Bug introduced by
The method createLine() does not seem to exist on object<WyriHaximus\React...Messenger\Messages\Rpc>.

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 seem to exist on object<WyriHaximus\React...Messenger\Messages\Rpc>.

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...
83 3
                },
84 3
                function ($payload) use ($uniqid) {
85
                    $this->write($this->createLine(Factory::rpcNotify($uniqid, $payload)));
0 ignored issues
show
Bug introduced by
The method createLine() does not seem to exist on object<WyriHaximus\React...Messenger\Messages\Rpc>.

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 seem to exist on object<WyriHaximus\React...Messenger\Messages\Rpc>.

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...
86 3
                }
87
            );
88 3
        };
89 3
        $cb = $cb->bindTo($bindTo);
90 3
        $cb($this->target, $this->payload, $this->uniqid);
91 3
    }
92
}
93