Passed
Pull Request — master (#1)
by Thomas Mauro
02:21
created

ReactFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 25
ccs 6
cts 7
cp 0.8571
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createClient() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\HTTPlugModule\ClientFactory;
6
7
use function class_exists;
8
use Http\Adapter\React\Client;
9
use Http\Client\HttpClient;
10
use Http\Message\MessageFactory;
11
use LogicException;
12
13
class ReactFactory implements ClientFactory
14
{
15
    /** @var MessageFactory */
16
    private $messageFactory;
17
18
    /**
19
     * @param MessageFactory $messageFactory
20
     */
21 1
    public function __construct(MessageFactory $messageFactory)
22
    {
23 1
        $this->messageFactory = $messageFactory;
24 1
    }
25
26
    /**
27
     * @param array<string, mixed> $config
28
     *
29
     * @return HttpClient
30
     */
31 1
    public function createClient(array $config = []): HttpClient
32
    {
33 1
        if (! class_exists('Http\Adapter\React\Client')) {
34
            throw new LogicException('To use the React adapter you need to install the "php-http/react-adapter" package.');
35
        }
36
37 1
        return new Client($this->messageFactory);
38
    }
39
}
40