Completed
Push — master ( 571af6...74c049 )
by Pol
01:47
created

AbstractClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
cbo 2
dl 0
loc 63
rs 10
ccs 12
cts 12
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A withHttpClient() 0 7 1
A getHttpClient() 0 4 1
A getMessageFactory() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\Yaroc\Http;
6
7
use Http\Client\HttpClient;
8
use Http\Discovery\HttpClientDiscovery;
9
use Http\Discovery\MessageFactoryDiscovery;
10
use Http\Message\MessageFactory;
11
12
/**
13
 * Class AbstractClient.
14
 */
15
abstract class AbstractClient
16
{
17
    /**
18
     * The HTTP client.
19
     *
20
     * @var \Http\Client\HttpClient
21
     */
22
    private $httpClient;
23
24
    /**
25
     * The HTTP message factory.
26
     *
27
     * @var \Http\Message\MessageFactory|null
28
     */
29
    private $messageFactory;
30
31
    /**
32
     * AbstractClient constructor.
33
     *
34
     * @param \Http\Client\HttpClient $client
0 ignored issues
show
Documentation introduced by
Should the type for parameter $client not be null|HttpClient?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
35
     * @param \Http\Message\MessageFactory|null $messageFactory
36
     *
37
     * @SuppressWarnings(PHPMD.StaticAccess)
38
     */
39 9
    public function __construct(HttpClient $client = null, MessageFactory $messageFactory = null)
40
    {
41 9
        $this->httpClient = $client ?? HttpClientDiscovery::find();
42 9
        $this->messageFactory = $messageFactory ?? MessageFactoryDiscovery::find();
43 9
    }
44
45
    /**
46
     * @param \Http\Client\HttpClient $httpClient
47
     *
48
     * @return \drupol\Yaroc\Http\AbstractClient
49
     */
50 4
    public function withHttpClient(HttpClient $httpClient) :AbstractClient
51
    {
52 4
        $clone = clone $this;
53 4
        $clone->httpClient = $httpClient;
54
55 4
        return $clone;
56
    }
57
58
    /**
59
     * Returns the HTTP adapter.
60
     *
61
     * @return HttpClient
62
     */
63 4
    public function getHttpClient(): HttpClient
64
    {
65 4
        return $this->httpClient;
66
    }
67
68
    /**
69
     * Get the message factory.
70
     *
71
     * @return MessageFactory
72
     */
73 4
    public function getMessageFactory(): MessageFactory
74
    {
75 4
        return $this->messageFactory;
76
    }
77
}
78