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 ( a48478...b6370b )
by Cees-Jan
02:40
created

ChildProcess::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 1
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace WyriHaximus\React\ChildProcess\PSR3;
4
5
use InvalidArgumentException;
6
use Psr\Log\LoggerInterface;
7
use React\EventLoop\LoopInterface;
8
use React\Promise\PromiseInterface;
9
use Throwable;
10
use WyriHaximus\React\ChildProcess\Messenger\ChildInterface;
11
use WyriHaximus\React\ChildProcess\Messenger\Messages\Payload;
12
use WyriHaximus\React\ChildProcess\Messenger\Messenger;
13
use function React\Promise\reject;
14
use function React\Promise\resolve;
15
16
final class ChildProcess implements ChildInterface
17
{
18
    /**
19
     * @var LoggerInterface
20
     */
21
    private $logger;
22
23
    public static function create(Messenger $messenger, LoopInterface $loop)
24
    {
25
        new static($messenger, $loop);
26
    }
27
28
    protected function __construct(Messenger $messenger, LoopInterface $loop)
0 ignored issues
show
Unused Code introduced by
The parameter $loop is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30 9
        $messenger->registerRpc('logger.setup', function (Payload $payload) {
31 9
            return $this->setup($payload);
32 9
        });
33 9
        $messenger->registerRpc('logger.log', function (Payload $payload) {
34 2
            return $this->log($payload);
35 9
        });
36 9
    }
37
38
    private function setup(Payload $payload): PromiseInterface
39
    {
40
        try {
41 9
            $this->logger = $payload['factory']();
42 9
            if (!($this->logger instanceof LoggerInterface)) {
43 7
                throw new InvalidArgumentException('Passed logger isn\'t a PSR-3 logger');
44
            }
45 2
            return resolve([
46 2
                'success' => true,
47
            ]);
48 7
        } catch (Throwable $throwable) {
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
49 7
            return reject($throwable);
50
        }
51
    }
52
53 2
    private function log(Payload $payload): PromiseInterface
54
    {
55
        try {
56 2
            $this->logger->log(
57 2
                $payload['level'],
58 2
                $payload['message'],
59 2
                $payload['context']
60
            );
61 1
            return resolve([
62 1
                'success' => true,
63
            ]);
64 1
        } catch (Throwable $throwable) {
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
65 1
            return reject($throwable);
66
        }
67
    }
68
}
69