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 ( 7530d3...8f64b9 )
by Cees-Jan
02:31
created

Factory::create()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 4
nop 2
dl 0
loc 20
ccs 8
cts 8
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ApiClients\Foundation\Transport;
5
6
use GuzzleHttp\Client as GuzzleClient;
7
use GuzzleHttp\HandlerStack;
8
use React\Dns\Resolver\Resolver;
9
use React\EventLoop\Factory as LoopFactory;
10
use React\EventLoop\LoopInterface;
11
use React\HttpClient\Client as HttpClient;
12
use React\HttpClient\Factory as HttpClientFactory;
13
use React\Dns\Resolver\Factory as ResolverFactory;
14
use WyriHaximus\React\GuzzlePsr7\HttpClientAdapter;
15
16
class Factory
17
{
18
    /**
19
     * @param LoopInterface|null $loop
20
     * @param array $options
21
     * @return Client
22
     */
23 2
    public static function create(LoopInterface $loop = null, array $options = []): Client
24
    {
25 2
        if (!($loop instanceof LoopInterface)) {
26 1
            $loop = LoopFactory::create();
27
        }
28
29 2
        if (!isset($options['dns'])) {
30 2
            $options['dns'] = '8.8.8.8';
31
        }
32
33 2
        $resolver = (new ResolverFactory())->createCached($options['dns'], $loop);
34 2
        $httpClient = (new HttpClientFactory())->create($loop, $resolver);
35
36 2
        return self::createFromReactHttpClient(
37
            $httpClient,
38
            $resolver,
39
            $loop,
40
            $options
41
        );
42
    }
43
44
    /**
45
     * @param HttpClient $httpClient
46
     * @param Resolver $resolver
47
     * @param LoopInterface|null $loop
48
     * @param array $options
49
     * @return Client
50
     */
51 2
    public static function createFromReactHttpClient(
52
        HttpClient $httpClient,
53
        Resolver $resolver,
54
        LoopInterface $loop = null,
55
        array $options = []
56
    ): Client {
57 2
        return new Client(
58
            $loop,
0 ignored issues
show
Bug introduced by
It seems like $loop defined by parameter $loop on line 54 can be null; however, ApiClients\Foundation\Tr...t\Client::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
59 2
            new GuzzleClient(
60
                [
61 2
                    'handler' => HandlerStack::create(
62 2
                        new HttpClientAdapter(
63
                            $loop,
0 ignored issues
show
Bug introduced by
It seems like $loop defined by parameter $loop on line 54 can be null; however, WyriHaximus\React\Guzzle...tAdapter::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
64
                            $httpClient,
65
                            $resolver
66
                        )
67
                    ),
68
                ]
69
            ),
70
            $options
71
        );
72
    }
73
}
74