Source::matches()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
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 GuzzleHttp\Client;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10
11
/**
12
 * The abstract implementation of a source.
13
 */
14
abstract class Source
15
{
16
    /**
17
     * The HTTP client.
18
     */
19
    protected Client $client;
20
21
    /**
22
     * Retrieve the HTTP request.
23
     */
24
    abstract public function request(): RequestInterface;
25
26
    /**
27
     * Retrieve the HTTP response.
28
     *
29
     * @return ResponseInterface
30
     */
31
    abstract public function response(): ResponseInterface;
32
33
    /**
34
     * Instantiate the class.
35
     */
36 50
    final public function __construct(
37
        protected readonly mixed $source,
38 50
    ) {}
39
40
    /**
41
     * Determine whether this class can handle the source.
42
     *
43
     * @codeCoverageIgnore
44
     */
45
    public function matches(): bool
46
    {
47
        return true;
48
    }
49
50
    /**
51
     * Set the HTTP client.
52
     */
53 50
    public function setClient(Client $client): static
54
    {
55 50
        $this->client ??= $client;
56
57 50
        return $this;
58
    }
59
}
60