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

Process::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 7.608

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 21
ccs 3
cts 15
cp 0.2
rs 9.3142
c 1
b 0
f 0
cc 3
eloc 15
nc 3
nop 2
crap 7.608
1
<?php
2
3
namespace WyriHaximus\React\ChildProcess\Messenger;
4
5
use React\EventLoop\LoopInterface;
6
use WyriHaximus\React\ChildProcess\Messenger\Factory as MessengerFactory;
7
use WyriHaximus\React\ChildProcess\Messenger\Messages\Factory as MessagesFactory;
8
use WyriHaximus\React\ChildProcess\Messenger\Messages\Payload;
9
10
final class Process
11
{
12
    /**
13
     * @var LoopInterface
14
     */
15
    protected $loop;
16
17
    /**
18
     * @var Messenger
19
     */
20
    protected $messenger;
21
22
    /**
23
     * Process constructor.
24
     * @param LoopInterface $loop
25
     * @param Messenger     $messenger
26
     */
27 1
    protected function __construct(LoopInterface $loop, Messenger $messenger)
28
    {
29 1
        $this->loop = $loop;
30 1
        $this->messenger = $messenger;
31 1
        $this->messenger->registerRpc(
32 1
            MessengerFactory::PROCESS_REGISTER,
33
            function (Payload $payload) {
34
                if (!is_subclass_of($payload['className'], 'WyriHaximus\React\ChildProcess\Messenger\ChildInterface')) {
35
                    throw new \Exception('Given class doesn\'t implement ChildInterface');
36
                }
37
38
                $this->registerClass($payload['className']);
39
                $this->deregisterRpc();
40
41
                return \React\Promise\resolve([]);
42 1
            }
43
        );
44 1
    }
45
46
    /**
47
     * @param  LoopInterface $loop
48
     * @param  Messenger     $messenger
49
     * @return Process
50
     */
51 1
    public static function create(LoopInterface $loop, Messenger $messenger)
52
    {
53
        $reject = function ($exeption) use ($messenger, $loop) {
54
            $messenger->error(MessagesFactory::error([
55
                'message' => $exeption->getMessage(),
56
                'code' => $exeption->getCode(),
57
                'line' => $exeption->getLine(),
58
                'file' => $exeption->getFile(),
59
            ]));
60
            $loop->addTimer(1, function () use ($loop) {
61
                $loop->stop();
62
            });
63 1
        };
64
        try {
65 1
            return new Process($loop, $messenger);
66
        } catch (\Exception $exeption) {
67
            $reject($exeption);
68
        } catch (\Throwable $exeption) {
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
69
            $reject($exeption);
70
        }
71
    }
72
73
    /**
74
     * @param string $className
75
     */
76
    protected function registerClass($className)
77
    {
78
        call_user_func_array([
79
            $className,
80
            'create',
81
        ], [
82
            $this->messenger,
83
            $this->loop,
84
        ]);
85
    }
86
87
    protected function deregisterRpc()
88
    {
89
        $this->loop->futureTick(function () {
90
            $this->messenger->deregisterRpc(MessengerFactory::PROCESS_REGISTER);
91
        });
92
    }
93
}
94