Passed
Push — master ( f80fe6...515bb9 )
by Andrea Marco
03:46 queued 16s
created

LaravelClientResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 27
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A request() 0 4 2
A matches() 0 3 1
A response() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cerbero\LazyJsonPages\Sources;
6
7
use Cerbero\LazyJsonPages\Exceptions\RequestNotSentException;
8
use Illuminate\Http\Client\Response;
9
use Psr\Http\Message\RequestInterface;
10
use Psr\Http\Message\ResponseInterface;
11
12
/**
13
 * The Laravel HTTP client source.
14
 *
15
 * @property-read Response $source
16
 */
17
class LaravelClientResponse extends Source
18
{
19
    /**
20
     * Determine whether this class can handle the source.
21
     */
22 6
    public function matches(): bool
23
    {
24 6
        return $this->source instanceof Response;
25
    }
26
27
    /**
28
     * Retrieve the HTTP request.
29
     */
30 2
    public function request(): RequestInterface
31
    {
32 2
        return $this->source->transferStats?->getRequest()
33 2
            ?: throw new RequestNotSentException();
34
    }
35
36
    /**
37
     * Retrieve the HTTP response.
38
     *
39
     * @return ResponseInterface
40
     */
41 1
    public function response(): ResponseInterface
42
    {
43 1
        return $this->source->toPsrResponse();
44
    }
45
}
46