Completed
Push — master ( f034b1...756441 )
by David
08:54
created

MockFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 31
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\Mock\Client;
6
7
/**
8
 * @author Gary PEGEOT <[email protected]>
9
 */
10
class MockFactory implements ClientFactory
11
{
12
    /**
13
     * @var Client
14
     */
15
    private $client;
16
17
    /**
18
     * @param Client $client
19
     */
20
    public function setClient(Client $client)
21
    {
22
        $this->client = $client;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function createClient(array $config = [])
29
    {
30
        if (!class_exists(Client::class)) {
31
            throw new \LogicException('To use the mock adapter you need to install the "php-http/mock-client" package.');
32
        }
33
34
        if (!$this->client) {
35
            $this->client = new Client();
36
        }
37
38
        return $this->client;
39
    }
40
}
41