Completed
Pull Request — master (#2)
by Pol
02:04
created

AbstractClient::getMessageFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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
    public function __construct(HttpClient $client = null, MessageFactory $messageFactory = null)
38
    {
39
        $this->httpClient = $client ?? HttpClientDiscovery::find();
40
        $this->messageFactory = $messageFactory ?? MessageFactoryDiscovery::find();
41
    }
42
43
    /**
44
     * @param \Http\Client\HttpClient $httpClient
45
     *
46
     * @return \drupol\Yaroc\Http\AbstractClient
47
     */
48
    public function withHttpClient(HttpClient $httpClient) :AbstractClient
49
    {
50
        $clone = clone $this;
51
        $clone->httpClient = $httpClient;
52
53
        return $clone;
54
    }
55
56
    /**
57
     * Returns the HTTP adapter.
58
     *
59
     * @return HttpClient
60
     */
61
    public function getHttpClient(): HttpClient
62
    {
63
        return $this->httpClient;
64
    }
65
66
    /**
67
     * Get the message factory.
68
     *
69
     * @return MessageFactory
70
     */
71
    public function getMessageFactory(): MessageFactory
72
    {
73
        return $this->messageFactory;
74
    }
75
}
76