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
02:42
created

RequestFactory::getProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 1
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\HttpProxy\ProxyConnector as HttpProxyClient;
16
use Clue\React\Socks\Client as SocksProxyClient;
17
use Psr\Http\Message\RequestInterface;
18
use React\Dns\Resolver\Resolver;
19
use React\EventLoop\LoopInterface;
20
use React\HttpClient\Client as HttpClient;
21
use ReflectionObject;
22
23
/**
24
 * Class RequestFactory
25
 *
26
 * @package WyriHaximus\React\Guzzle\HttpClient
27
 */
28
class RequestFactory
29
{
30
    /**
31
     *
32
     * @param RequestInterface $request
33
     * @param array $options
34
     * @param $resolver Resolver
35
     * @param HttpClient $httpClient
36
     * @param LoopInterface $loop
37
     * @return \React\Promise\Promise
38
     */
39
    public function create(
40
        RequestInterface $request,
41
        array $options,
42
        Resolver $resolver,
43
        HttpClient $httpClient,
44
        LoopInterface $loop
45
    ) {
46 3
        return \WyriHaximus\React\futurePromise($loop)->then(function () use (
47 3
            $request,
48 3
            $options,
49 3
            $resolver,
50 3
            $httpClient,
51 3
            $loop
52
        ) {
53 3
            $sender = $this->createSender($options, $resolver, $httpClient, $loop);
54 3
            return (new Browser($loop, $sender))
55 3
                ->withOptions($this->convertOptions($options))
56 3
                ->send($request);
57 3
        });
58
    }
59
60
    /**
61
     * @param array $options
62
     * @param HttpClient $httpClient
63
     * @param LoopInterface $loop
64
     * @return Sender
65
     */
66 3
    protected function createSender(array $options, Resolver $resolver, HttpClient $httpClient, LoopInterface $loop)
67
    {
68 3
        $connector = $this->getProperty($httpClient, 'connector');
69
70 3
        if (isset($options['proxy'])) {
71 2
            switch (parse_url($options['proxy'], PHP_URL_SCHEME)) {
72 2
                case 'http':
73 1
                    $connector = new HttpProxyClient($options['proxy'], $connector);
74 1
                    break;
75 1
                case 'socks':
76 1
                    $connector = (new SocksProxyClient(
77 1
                        $options['proxy'],
78 1
                        $loop,
79 1
                        $connector,
80 1
                        $resolver
81 1
                    ))->createConnector();
82 1
                    break;
83 2
            }
84 2
        }
85
86 3
        return Sender::createFromLoopConnectors($loop, $connector);
87
    }
88
89
    /**
90
     * @param array $options
91
     * @return array
92
     */
93 3
    protected function convertOptions(array $options)
94
    {
95 3
        return $options;
96
    }
97
98
    /**
99
     * @param object $object
100
     * @param string $desiredProperty
101
     * @return mixed
102
     */
103 3
    protected function getProperty($object, $desiredProperty)
104
    {
105 3
        $reflection = new ReflectionObject($object);
106 3
        $property = $reflection->getProperty($desiredProperty);
107 3
        $property->setAccessible(true);
108 3
        return $property->getValue($object);
109
    }
110
}
111