Passed
Push — master ( e9806b...56ffd0 )
by Luke
09:13
created

HttpClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 3
cbo 3
dl 0
loc 74
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A sendRequest() 0 3 1
A createRequest() 0 5 1
A createUri() 0 3 1
1
<?php
2
3
/**
4
 * Moodle component manager.
5
 *
6
 * @author Luke Carrier <[email protected]>
7
 * @copyright 2016 Luke Carrier
8
 * @license GPL-3.0+
9
 */
10
11
namespace ComponentManager;
12
13
use Http\Client\HttpClient as HttplugClient;
14
use Http\Message\MessageFactory;
15
use Http\Message\UriFactory;
16
use Psr\Http\Message\RequestInterface;
17
use Psr\Http\Message\ResponseInterface;
18
use Psr\Http\Message\StreamInterface;
19
use Psr\Http\Message\UriInterface;
20
21
/**
22
 * Slightly sweeter HTTPlug.
23
 */
24
class HttpClient {
25
    /**
26
     * HTTP client.
27
     *
28
     * @var HttplugClient
29
     */
30
    protected $client;
31
32
    /**
33
     * HTTP message factory.
34
     *
35
     * @var MessageFactory
36
     */
37
    protected $messageFactory;
38
39
    /**
40
     * HTTP URI factory.
41
     *
42
     * @var UriFactory
43
     */
44
    protected $uriFactory;
45
46
    /**
47
     * HttpClient constructor.
48
     *
49
     * @param HttplugClient $client
50
     * @param MessageFactory $messageFactory
51
     * @param UriFactory $uriFactory
52
     */
53
    public function __construct(HttplugClient $client, MessageFactory $messageFactory, UriFactory $uriFactory) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 112 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
54
        $this->client = $client;
55
        $this->messageFactory = $messageFactory;
56
        $this->uriFactory = $uriFactory;
57
    }
58
59
    /**
60
     * Send request.
61
     *
62
     * @param RequestInterface $request
63
     *
64
     * @return ResponseInterface
65
     */
66
    public function sendRequest(RequestInterface $request) {
67
        return $this->client->sendRequest($request);
68
    }
69
70
    /**
71
     * Create a request.
72
     *
73
     * @param string                               $method
74
     * @param UriInterface|string                  $uri
75
     * @param mixed[]                              $headers
76
     * @param resource|string|StreamInterface|null $body
77
     * @param string                               $protocolVersion
78
     *
79
     * @return RequestInterface
80
     */
81
    public function createRequest($method, $uri, $headers=[], $body=null,
82
                                  $protocolVersion='1.1') {
83
        return $this->messageFactory->createRequest(
84
                $method, $uri, $headers, $body, $protocolVersion);
85
    }
86
87
    /**
88
     * Create a URI.
89
     *
90
     * @param URIInterface|string $uri
91
     *
92
     * @return UriInterface
93
     */
94
    public function createUri($uri) {
95
        return $this->uriFactory->createUri($uri);
96
    }
97
}
98