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 ( 1c2b2d...9313fa )
by Cees-Jan
01:42
created

Process::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3.0213

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
ccs 13
cts 15
cp 0.8667
rs 9.3142
cc 3
eloc 15
nc 3
nop 2
crap 3.0213
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
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 2
    protected function __construct(LoopInterface $loop, Messenger $messenger)
28
    {
29 2
        $this->loop = $loop;
30 2
        $this->messenger = $messenger;
31 2
        $this->messenger->registerRpc(
32 2
            MessengerFactory::PROCESS_REGISTER,
33
            function (Payload $payload) {
34 2
                if (!is_subclass_of($payload['className'], 'WyriHaximus\React\ChildProcess\Messenger\ChildInterface')) {
35 1
                    throw new \Exception('Given class doesn\'t implement ChildInterface');
36
                }
37
38 1
                $this->registerClass($payload['className']);
39 1
                $this->deregisterRpc();
40
41 1
                return \React\Promise\resolve([]);
42 2
            }
43
        );
44 1
    }
45
46
    /**
47
     * @param  LoopInterface $loop
48
     * @param  Messenger     $messenger
49
     * @return Process
50
     */
51 2
    public static function create(LoopInterface $loop, Messenger $messenger)
52
    {
53
        $reject = function ($exeption) use ($messenger, $loop) {
54 1
            $messenger->error(MessagesFactory::error([
55 1
                'message' => $exeption->getMessage(),
56 1
                'code' => $exeption->getCode(),
57 1
                'line' => $exeption->getLine(),
58 1
                'file' => $exeption->getFile(),
59
            ]));
60
            $loop->addTimer(1, function () use ($loop) {
61 1
                $loop->stop();
62 1
            });
63 2
        };
64
        try {
65 2
            return new Process($loop, $messenger);
66 1
        } catch (\Exception $exeption) {
67 1
            $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 1
    }
72
73
    /**
74
     * @param string $className
75
     */
76 1
    protected function registerClass($className)
77
    {
78 1
        call_user_func_array([
79 1
            $className,
80 1
            'create',
81
        ], [
82 1
            $this->messenger,
83 1
            $this->loop,
84
        ]);
85 1
    }
86
87
    protected function deregisterRpc()
88
    {
89 1
        $this->loop->futureTick(function () {
90 1
            $this->messenger->deregisterRpc(MessengerFactory::PROCESS_REGISTER);
91 1
        });
92 1
    }
93
}
94