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 (#6)
by Cees-Jan
05:30
created

RequestFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.2963

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 2
cts 6
cp 0.3333
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 4
crap 1.2963
1
<?php
2
3
/**
4
 * This file is part of ReactGuzzleRing.
5
 *
6
 ** (c) 2014 Cees-Jan Kiewiet
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace WyriHaximus\React\Guzzle\HttpClient;
12
13
use Clue\React\Buzz\Browser;
14
use Clue\React\Buzz\Io\Sender;
15
use Clue\React\Socks\Client as SocksClient;
16
use Psr\Http\Message\RequestInterface;
17
use React\EventLoop\LoopInterface;
18
use React\HttpClient\Client as HttpClient;
19
use React\SocketClient\Connector;
20
use React\SocketClient\ConnectorInterface;
21
use React\SocketClient\DnsConnector;
22
use ReflectionObject;
23
24
/**
25
 * Class RequestFactory
26
 *
27
 * @package WyriHaximus\React\Guzzle\HttpClient
28
 */
29
class RequestFactory
30
{
31
    /**
32
     *
33
     * @param RequestInterface $request
34
     * @param array $options
35
     * @param HttpClient $httpClient
36
     * @param LoopInterface $loop
37
     * @return \React\Promise\Promise
38
     */
39
    public function create(RequestInterface $request, array $options, HttpClient $httpClient, LoopInterface $loop)
40
    {
41 1
        return \WyriHaximus\React\futurePromise($loop)->then(function () use ($request, $options, $httpClient, $loop) {
42
            $sender = $this->createSender($options, $httpClient, $loop);
43
            return (new Browser($loop, $sender))
44
                ->withOptions($this->convertOptions($options))
45
                ->send($request);
46 1
        });
47
    }
48
49
    protected function createSender(array $options, HttpClient $httpClient, LoopInterface $loop)
50
    {
51
        $connector = $this->extractConnector($httpClient);
52
53
        if (isset($options['proxy'])) {
54
            $resolver = $this->extractResolver($connector);
55
            $connector = (new SocksClient($options['proxy'], $loop, $connector, $resolver))->createConnector();
56
        }
57
58
        return Sender::createFromLoopConnectors($loop, $connector);
59
    }
60
61
    protected function convertOptions(array $options)
62
    {
63
        return $options;
64
    }
65
66
    protected function extractConnector(HttpClient $httpClient)
67
    {
68
        $reflection = new ReflectionObject($httpClient);
69
        $property = $reflection->getProperty('connector');
70
        $property->setAccessible(true);
71
        return $property->getValue($httpClient);
72
    }
73
74
    protected function extractResolver(ConnectorInterface $connector)
75
    {
76
        if ($connector instanceof Connector || $connector instanceof DnsConnector) {
77
            $reflection = new ReflectionObject($connector);
78
            $property = $reflection->getProperty('resolver');
79
            $property->setAccessible(true);
80
            return $property->getValue($connector);
81
        }
82
83
        return null;
84
    }
85
}
86