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

MockFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 33
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setClient() 0 4 1
A createClient() 0 12 3
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