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
03:45
created

RequestFactory::extractConnector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 2
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 1
    public function create(RequestInterface $request, array $options, HttpClient $httpClient, LoopInterface $loop)
40
    {
41 1
        $sender = $this->createSender($options, $httpClient, $loop);
42 1
        return (new Browser($loop, $sender))
43 1
            ->withOptions($this->convertOptions($options))
44 1
            ->send($request);
45
    }
46
47 1
    protected function createSender(array $options, HttpClient $httpClient, LoopInterface $loop)
48
    {
49 1
        if (isset($options['proxy'])) {
50
            $connector = $this->extractConnector($httpClient);
51
            $resolver = $this->extractResolver($connector);
52
            $socks = new SocksClient($options['proxy'], $loop, $connector, $resolver);
53
            return Sender::createFromLoopConnectors($loop, $socks->createConnector());
54
        }
55
56 1
        return new Sender($httpClient);
57
    }
58
59 1
    protected function convertOptions(array $options)
60
    {
61 1
        return $options;
62
    }
63
64
    protected function extractConnector(HttpClient $httpClient)
65
    {
66
        $reflection = new ReflectionObject($httpClient);
67
        $property = $reflection->getProperty('connector');
68
        $property->setAccessible(true);
69
        return $property->getValue($httpClient);
70
    }
71
72
    protected function extractResolver(ConnectorInterface $connector)
73
    {
74 View Code Duplication
        if ($connector instanceof Connector) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
            $reflection = new ReflectionObject($connector);
76
            $property = $reflection->getProperty('resolver');
77
            $property->setAccessible(true);
78
            return $property->getValue($connector);
79
        }
80
81 View Code Duplication
        if ($connector instanceof DnsConnector) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
            $reflection = new ReflectionObject($connector);
83
            $property = $reflection->getProperty('resolver');
84
            $property->setAccessible(true);
85
            return $property->getValue($connector);
86
        }
87
88
        return null;
89
    }
90
}
91