GuzzleClient   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 16
c 0
b 0
f 0
dl 0
loc 32
ccs 0
cts 14
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A defaultOptions() 0 16 2
A sendRequest() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\SharedKernel\Infrastructure\HttpClient;
6
7
use GuzzleHttp\Client;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\Client was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use GuzzleHttp\HandlerStack;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\HandlerStack was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Psr\Http\Client\ClientInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Client\ClientInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Psr\Http\Message\RequestInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\RequestInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Psr\Http\Message\ResponseInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\ResponseInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
final class GuzzleClient implements ClientInterface
14
{
15
    private Client $client;
16
    private array $middleware;
17
18
    public function __construct(Client $client, array $middleware = [])
19
    {
20
        $this->client = $client;
21
        $this->middleware = $middleware;
22
    }
23
24
    public function sendRequest(RequestInterface $request): ResponseInterface
25
    {
26
        return $this->client->send($request, $this->defaultOptions($request->getHeaders()));
27
    }
28
29
    private function defaultOptions(array $headers): array
30
    {
31
        $handlerStack = HandlerStack::create();
32
        foreach ($this->middleware as $middleware) {
33
            $handlerStack->push($middleware);
34
        }
35
36
        return [
37
            'verify' => false,
38
            'http_errors' => false,
39
            'handler' => $handlerStack,
40
            'headers' => array_merge(
41
                [
42
                    'Content-Type' => 'application/json',
43
                ],
44
                $headers
45
            ),
46
        ];
47
    }
48
}
49