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.

OutstandingCalls::getCall()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
ccs 1
cts 1
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WyriHaximus\React\ChildProcess\Messenger;
6
7
use Closure;
8
9
use function array_key_exists;
10
use function array_values;
11
use function bin2hex;
12
use function microtime;
13
use function random_bytes;
14
15
final class OutstandingCalls
16 3
{
17
    /** @var array<OutstandingCall> */
18 3
    protected array $calls = [];
19
20 3
    public function newCall(Closure $canceller): OutstandingCall
21 1
    {
22 3
        $uniqid = $this->getNewUniqid();
23
24 3
        $this->calls[$uniqid] = new OutstandingCall($uniqid, $canceller, function (OutstandingCall $call): void {
25
            unset($this->calls[$call->getUniqid()]);
26
        });
27
28
        return $this->calls[$uniqid];
29
    }
30
31
    public function getCall(string $uniqid): OutstandingCall
32 2
    {
33
        return $this->calls[$uniqid];
34 2
    }
35
36
    /**
37
     * @return array<OutstandingCall>
38
     */
39
    public function getCalls(): array
40 2
    {
41
        return array_values($this->calls);
42 2
    }
43
44
    private function getNewUniqid(): string
45
    {
46
        do {
47
            $uniqid = (string) microtime(true) . '.' . bin2hex(random_bytes(4));
48 3
        } while (array_key_exists($uniqid, $this->calls));
49
50
        return $uniqid;
51 3
    }
52
}
53