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 ( 86a0a5...f6adab )
by Brent
13s
created

ParentRuntime   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 20 2
A createChildProcess() 0 17 2
1
<?php
2
3
namespace Spatie\Async\Runtime;
4
5
use Spatie\Async\ParallelProcess;
6
use function Opis\Closure\serialize;
7
use Opis\Closure\SerializableClosure;
8
use Symfony\Component\Process\Process;
9
10
class ParentRuntime
11
{
12
    /** @var bool */
13
    protected static $isInitialised = false;
14
15
    /** @var string */
16
    protected static $autoloader;
17
18
    /** @var string */
19
    protected static $childProcessScript;
20
21
    public static function init(string $autoloader = null)
22
    {
23
        if (! $autoloader) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $autoloader of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
24
            $existingAutoloaderFiles = array_filter([
25
                __DIR__.'/../../../../autoload.php',
26
                __DIR__.'/../../../autoload.php',
27
                __DIR__.'/../../vendor/autoload.php',
28
                __DIR__.'/../../../vendor/autoload.php',
29
            ], function (string $path) {
30
                return file_exists($path);
31
            });
32
33
            $autoloader = reset($existingAutoloaderFiles);
34
        }
35
36
        self::$autoloader = $autoloader;
37
        self::$childProcessScript = __DIR__.'/ChildRuntime.php';
38
39
        self::$isInitialised = true;
40
    }
41
42
    public static function createChildProcess(callable $callable): ParallelProcess
43
    {
44
        if (! self::$isInitialised) {
45
            self::init();
46
        }
47
48
        $closure = new SerializableClosure($callable);
0 ignored issues
show
Documentation introduced by
$callable is of type callable, but the function expects a object<Closure>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
50
        $process = new Process(implode(' ', [
51
            'exec php',
52
            self::$childProcessScript,
53
            self::$autoloader,
54
            base64_encode(serialize($closure)),
55
        ]));
56
57
        return ParallelProcess::create($process);
58
    }
59
}
60