Completed
Push — master ( 0c3674...5882e5 )
by
unknown
02:42
created

ClientAdapterAware::request()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 3
crap 2.0185
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