Guzzle5Factory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\HttplugBundle\ClientFactory;
6
7
use GuzzleHttp\Client;
8
use Http\Adapter\Guzzle5\Client as Adapter;
9
use Http\Message\MessageFactory;
10
11
/**
12
 * @author Tobias Nyholm <[email protected]>
13
 */
14
class Guzzle5Factory implements ClientFactory
15
{
16
    /**
17
     * @var MessageFactory
18
     */
19
    private $messageFactory;
20
21
    public function __construct(MessageFactory $messageFactory)
22
    {
23
        $this->messageFactory = $messageFactory;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function createClient(array $config = [])
30
    {
31
        if (!class_exists('Http\Adapter\Guzzle5\Client')) {
32
            throw new \LogicException('To use the Guzzle5 adapter you need to install the "php-http/guzzle5-adapter" package.');
33
        }
34
35
        $client = new Client($config);
36
37
        return new Adapter($client, $this->messageFactory);
38
    }
39
}
40