ClientAdapterAware::setClientAdapter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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