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

LaravelClientResponse::matches()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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