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.

ChildProcess   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 55
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A setup() 0 15 3
A create() 0 4 1
A log() 0 16 2
1
<?php declare(strict_types=1);
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 function React\Promise\reject;
10
use function React\Promise\resolve;
11
use Throwable;
12
use WyriHaximus\React\ChildProcess\Messenger\ChildInterface;
13
use WyriHaximus\React\ChildProcess\Messenger\Messages\Payload;
14
use WyriHaximus\React\ChildProcess\Messenger\Messenger;
15
16
final class ChildProcess implements ChildInterface
17
{
18
    /**
19
     * @var LoggerInterface
20
     */
21
    private $logger;
22
23 9
    private 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...
24
    {
25
        $messenger->registerRpc('logger.setup', function (Payload $payload) {
26 9
            return $this->setup($payload);
27 9
        });
28
        $messenger->registerRpc('logger.log', function (Payload $payload) {
29 2
            return $this->log($payload);
30 9
        });
31 9
    }
32
33 9
    private function setup(Payload $payload): PromiseInterface
34
    {
35
        try {
36 9
            $this->logger = $payload['factory']();
37 9
            if (!($this->logger instanceof LoggerInterface)) {
38 7
                throw new InvalidArgumentException('Passed logger isn\'t a PSR-3 logger');
39
            }
40
41 2
            return resolve([
42 2
                'success' => true,
43
            ]);
44 7
        } catch (Throwable $throwable) {
45 7
            return reject($throwable);
46
        }
47
    }
48
49 9
    public static function create(Messenger $messenger, LoopInterface $loop): void
50
    {
51 9
        new static($messenger, $loop);
52 9
    }
53
54 2
    private function log(Payload $payload): PromiseInterface
55
    {
56
        try {
57 2
            $this->logger->log(
58 2
                $payload['level'],
59 2
                $payload['message'],
60 2
                $payload['context']
61
            );
62
63 1
            return resolve([
64 1
                'success' => true,
65
            ]);
66 1
        } catch (Throwable $throwable) {
67 1
            return reject($throwable);
68
        }
69
    }
70
}
71