Source   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 44
ccs 5
cts 5
cp 1
rs 10
c 6
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A matches() 0 3 1
A setClient() 0 5 1
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