Completed
Push — master ( d5ec7d...209632 )
by David
02:50 queued 12s
created

HttpMethodsClient   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 93.55%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 82
ccs 29
cts 31
cp 0.9355
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A get() 0 4 1
A head() 0 4 1
A trace() 0 4 1
A post() 0 4 1
A put() 0 4 1
A patch() 0 4 1
A delete() 0 4 1
A options() 0 4 1
A send() 0 9 1
A sendRequest() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\Client\Common;
6
7
use Http\Message\RequestFactory;
8
use Psr\Http\Client\ClientInterface;
9
use Psr\Http\Message\RequestFactoryInterface;
10
use Psr\Http\Message\RequestInterface;
11
use Psr\Http\Message\ResponseInterface;
12
13
final class HttpMethodsClient implements HttpMethodsClientInterface
14
{
15
    /**
16
     * @var ClientInterface
17
     */
18
    private $httpClient;
19
20
    /**
21
     * @var RequestFactory|RequestFactoryInterface
22
     */
23
    private $requestFactory;
24
25
    /**
26
     * @param RequestFactory|RequestFactoryInterface
27
     */
28 8
    public function __construct(ClientInterface $httpClient, $requestFactory)
29
    {
30 8
        if (!$requestFactory instanceof RequestFactory && !$requestFactory instanceof RequestFactoryInterface) {
31
            throw new \TypeError(
32
                sprintf('%s::__construct(): Argument #2 ($requestFactory) must be of type %s|%s, %s given', self::class, RequestFactory::class, RequestFactoryInterface::class, get_debug_type($requestFactory))
0 ignored issues
show
Unused Code introduced by
The call to TypeError::__construct() has too many arguments starting with sprintf('%s::__construct..._type($requestFactory)).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
33
            );
34
        }
35
36 8
        $this->httpClient = $httpClient;
37 8
        $this->requestFactory = $requestFactory;
38 8
    }
39
40 1
    public function get($uri, array $headers = []): ResponseInterface
41
    {
42 1
        return $this->send('GET', $uri, $headers, null);
43
    }
44
45 1
    public function head($uri, array $headers = []): ResponseInterface
46
    {
47 1
        return $this->send('HEAD', $uri, $headers, null);
48
    }
49
50 1
    public function trace($uri, array $headers = []): ResponseInterface
51
    {
52 1
        return $this->send('TRACE', $uri, $headers, null);
53
    }
54
55 1
    public function post($uri, array $headers = [], $body = null): ResponseInterface
56
    {
57 1
        return $this->send('POST', $uri, $headers, $body);
58
    }
59
60 1
    public function put($uri, array $headers = [], $body = null): ResponseInterface
61
    {
62 1
        return $this->send('PUT', $uri, $headers, $body);
63
    }
64
65 1
    public function patch($uri, array $headers = [], $body = null): ResponseInterface
66
    {
67 1
        return $this->send('PATCH', $uri, $headers, $body);
68
    }
69
70 1
    public function delete($uri, array $headers = [], $body = null): ResponseInterface
71
    {
72 1
        return $this->send('DELETE', $uri, $headers, $body);
73
    }
74
75 1
    public function options($uri, array $headers = [], $body = null): ResponseInterface
76
    {
77 1
        return $this->send('OPTIONS', $uri, $headers, $body);
78
    }
79
80 8
    public function send(string $method, $uri, array $headers = [], $body = null): ResponseInterface
81
    {
82 8
        return $this->sendRequest($this->requestFactory->createRequest(
83 8
            $method,
84 8
            $uri,
85 8
            $headers,
0 ignored issues
show
Unused Code introduced by
The call to RequestFactoryInterface::createRequest() has too many arguments starting with $headers.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
86 8
            $body
87
        ));
88
    }
89
90 8
    public function sendRequest(RequestInterface $request): ResponseInterface
91
    {
92 8
        return $this->httpClient->sendRequest($request);
93
    }
94
}
95