Passed
Pull Request — master (#42)
by Stéphane
01:56
created

ReactFactory::buildHttpClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Http\Adapter\React;
4
5
use React\EventLoop\LoopInterface;
6
use React\EventLoop\Factory as EventLoopFactory;
7
use React\Http\Browser;
8
use React\Socket\ConnectorInterface;
9
10
/**
11
 * Factory wrapper for React instances.
12
 *
13
 * @author Stéphane Hulard <[email protected]>
14
 */
15
class ReactFactory
16
{
17
    /**
18
     * Build a react Event Loop.
19
     *
20
     * @return LoopInterface
21
     */
22 110
    public static function buildEventLoop()
23
    {
24 110
        return EventLoopFactory::create();
25
    }
26
27
    /**
28
     * Build a React Http Client.
29
     *
30
     * @param LoopInterface $loop
31
     * @param ConnectorInterface|null $connector Only pass this argument if you need to customize DNS
32
     *                                           behaviour.
33
     */
34 106
    public static function buildHttpClient(
35
        LoopInterface $loop,
36
        ConnectorInterface $connector = null
37
    ): Browser {
38 106
        return (new Browser($loop, $connector))
39 106
            ->withRejectErrorResponse(false)
40 106
            ->withFollowRedirects(false);
41
    }
42
}
43