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

SocketFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
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 22
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\Client\HttpClient;
9
use Http\Client\Socket\Client;
10
use Http\Message\MessageFactory;
11
use LogicException;
12
13
class SocketFactory implements ClientFactory
14
{
15
    /** @var MessageFactory */
16
    private $messageFactory;
17
18 1
    public function __construct(MessageFactory $messageFactory)
19
    {
20 1
        $this->messageFactory = $messageFactory;
21 1
    }
22
23
    /**
24
     * @param array<string, mixed> $config
25
     *
26
     * @return HttpClient
27
     */
28 1
    public function createClient(array $config = []): HttpClient
29
    {
30 1
        if (! class_exists(Client::class)) {
31
            throw new LogicException('To use the Socket client you need to install the "php-http/socket-client" package.');
32
        }
33
34 1
        return new Client($this->messageFactory, $config);
35
    }
36
}
37