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
Pull Request — master (#2)
by Cees-Jan
29:14 queued 19:05
created

Factory::createFromGuzzleClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 4
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Foundation\Transport;
4
5
use ApiClients\Foundation\Events\CommandLocatorEvent;
6
use ApiClients\Foundation\Events\ServiceLocatorEvent;
7
use Clue\React\Buzz\Browser;
8
use Clue\React\Buzz\Io\Sender;
9
use Interop\Container\ContainerInterface;
10
use League\Event\EmitterInterface;
11
use React\Dns\Resolver\Factory as ResolverFactory;
12
use React\Dns\Resolver\Resolver;
13
use React\EventLoop\LoopInterface;
14
use React\HttpClient\Client as HttpClient;
15
use React\HttpClient\Factory as HttpClientFactory;
16
17
class Factory
18
{
19
    /**
20
     * @param ContainerInterface $container
21
     * @param LoopInterface|null $loop
22
     * @param array $options
23
     * @return Client
24
     */
25
    public static function create(
26
        ContainerInterface $container,
27
        LoopInterface $loop,
28
        array $options = []
29
    ): Client {
30
        $container->get(EmitterInterface::class)->
31
            addListener(CommandLocatorEvent::NAME, function (CommandLocatorEvent $event) {
32
                $event->add(
33
                    __DIR__ . DIRECTORY_SEPARATOR . 'CommandBus' . DIRECTORY_SEPARATOR,
34
                    __NAMESPACE__ . '\CommandBus'
35
                );
36
            })
37
        ;
38
39
        $container->get(EmitterInterface::class)->
40
            addListener(ServiceLocatorEvent::NAME, function (ServiceLocatorEvent $event) {
41
                $event->add(
42
                    __DIR__ . DIRECTORY_SEPARATOR . 'Service' . DIRECTORY_SEPARATOR,
43
                    __NAMESPACE__ . '\Service'
44
                );
45
            })
46
        ;
47
48
        if (!isset($options[Options::DNS])) {
49
            $options[Options::DNS] = '8.8.8.8';
50
        }
51
52
        $resolver = (new ResolverFactory())->createCached($options[Options::DNS], $loop);
53
        $httpClient = (new HttpClientFactory())->create($loop, $resolver);
54
55
        return self::createFromReactHttpClient(
56
            $container,
57
            $httpClient,
58
            $resolver,
59
            $loop,
60
            $options
61
        );
62
    }
63
64
    /**
65
     * @param ContainerInterface $container
66
     * @param HttpClient $httpClient
67
     * @param Resolver $resolver
68
     * @param LoopInterface|null $loop
69
     * @param array $options
70
     * @return Client
71
     */
72
    public static function createFromReactHttpClient(
73
        ContainerInterface $container,
74
        HttpClient $httpClient,
0 ignored issues
show
Unused Code introduced by
The parameter $httpClient 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...
75
        Resolver $resolver,
76
        LoopInterface $loop,
77
        array $options = []
78
    ): Client {
79
        return self::createFromBuzz(
80
            $container,
81
            $loop,
82
            (new Browser($loop, Sender::createFromLoopDns($loop, $resolver)))->withOptions([
83
                'streaming' => true,
84
            ]),
85
            $options
86
        );
87
    }
88
89
    /**
90
     * @param ContainerInterface $container
91
     * @param LoopInterface $loop
92
     * @param Browser $buzz
93
     * @param array $options
94
     * @return Client
95
     */
96
    public static function createFromBuzz(
97
        ContainerInterface $container,
98
        LoopInterface $loop,
99
        Browser $buzz,
100
        array $options = []
101
    ): Client {
102
        return new Client(
103
            $loop,
104
            $container,
105
            $buzz,
106
            $options
107
        );
108
    }
109
}
110