Completed
Push — master ( b587fb...d05392 )
by David
20:34
created

MockFactory::createClient()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 5
cts 6
cp 0.8333
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3.0416
1
<?php
2
3
namespace Http\HttplugBundle\ClientFactory;
4
5
use Http\Client\HttpClient;
6
use Http\Mock\Client;
7
8
/**
9
 * @author Gary PEGEOT <[email protected]>
10
 */
11
final class MockFactory implements ClientFactory
12
{
13
    /**
14
     * @var HttpClient
15
     */
16
    private $client;
17
18
    /**
19
     * Set the client instance that this factory should return.
20
     *
21
     * Note that this can be any client, not only a mock client.
22
     */
23 1
    public function setClient(HttpClient $client)
24
    {
25 1
        $this->client = $client;
26 1
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    public function createClient(array $config = [])
32
    {
33 1
        if (!class_exists(Client::class)) {
34
            throw new \LogicException('To use the mock adapter you need to install the "php-http/mock-client" package.');
35
        }
36
37 1
        if (!$this->client) {
38 1
            $this->client = new Client();
39
        }
40
41 1
        return $this->client;
42
    }
43
}
44