ClientAdapterAware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 88.89%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A request() 0 11 2
A setClientAdapter() 0 4 1
1
<?php
2
namespace Aeq\Hal\Client;
3
4
use Aeq\Hal\Client\Event\PostClientRequestEvent;
5
use Aeq\Hal\Event\EventingAware;
6
use Aeq\Hal\Exception\InvalidResponseException;
7
use Psr\Http\Message\ResponseInterface;
8
9
trait ClientAdapterAware
10
{
11
    use EventingAware;
12
13
    /**
14
     * @var ClientAdapterInterface
15
     */
16
    private $clientAdapter;
17
18
    /**
19
     * @param string $method
20
     * @param string $uri
21
     * @param array $options
22
     * @return ResponseInterface
23
     * @throws InvalidResponseException
24
     */
25 4
    public function request($method, $uri = null, array $options = [])
26
    {
27 4
        if ($this->clientAdapter instanceof ClientAdapterInterface) {
28 4
            $response = $this->clientAdapter->request($method, $uri, $options);
29
30 4
            $this->triggerEvent(new PostClientRequestEvent($response));
31
32 4
            return $response;
33
        }
34
        throw new \LogicException(sprintf('no client adapter set for "%s"', __CLASS__), 1460021696);
35
    }
36
37
    /**
38
     * @param ClientAdapterInterface $clientAdapter
39
     */
40 6
    public function setClientAdapter($clientAdapter)
41
    {
42 6
        $this->clientAdapter = $clientAdapter;
43 6
    }
44
}
45