MockFactory   A
last analyzed

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
declare(strict_types=1);
4
5
namespace Http\HttplugBundle\ClientFactory;
6
7
use Http\Client\HttpClient;
8
use Http\Mock\Client;
9
10
/**
11
 * @author Gary PEGEOT <[email protected]>
12
 */
13
final class MockFactory implements ClientFactory
14
{
15
    /**
16
     * @var HttpClient
17
     */
18
    private $client;
19
20
    /**
21
     * Set the client instance that this factory should return.
22
     *
23
     * Note that this can be any client, not only a mock client.
24
     */
25 1
    public function setClient(HttpClient $client)
26
    {
27 1
        $this->client = $client;
28 1
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function createClient(array $config = [])
34
    {
35 1
        if (!class_exists(Client::class)) {
36
            throw new \LogicException('To use the mock adapter you need to install the "php-http/mock-client" package.');
37
        }
38
39 1
        if (!$this->client) {
40 1
            $this->client = new Client();
41
        }
42
43 1
        return $this->client;
44
    }
45
}
46