Passed
Push — master ( f2b4f1...f4fa9e )
by Dispositif
03:37
created

GuzzleClientAdapter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
dl 0
loc 16
rs 10
c 1
b 0
f 1
cc 1
nc 1
nop 1
1
<?php
2
/*
3
 * This file is part of dispositif/wikibot application (@github)
4
 * 2019-2023 © Philippe M./Irønie  <[email protected]>
5
 * For the full copyright and MIT license information, view the license file.
6
 */
7
8
declare(strict_types=1);
9
10
namespace App\Infrastructure;
11
12
use App\Application\InfrastructurePorts\HttpClientInterface;
13
use GuzzleHttp\Client;
14
use Psr\Http\Message\ResponseInterface;
15
use Psr\Http\Message\UriInterface;
16
17
class GuzzleClientAdapter implements HttpClientInterface
18
{
19
    protected Client $client;
20
21
    public function __construct(array $options = [])
22
    {
23
        // https://docs.guzzlephp.org/en/6.5/request-options.html
24
        $this->client = new Client(
25
            [
26
                'timeout' => 20,
27
                'allow_redirects' => true,
28
//                or replace "true" with: [
29
//                    'max'             => 5,
30
//                    'strict'          => false,
31
//                    'referer'         => false,
32
//                    'protocols'       => ['http', 'https'],
33
//                    'track_redirects' => false
34
//                ]
35
                'headers' => ['User-Agent' => getenv('USER_AGENT')],
36
                'verify' => false, // CURLOPT_SSL_VERIFYHOST
37
//                    'http_errors' => false, // no Exception on 4xx 5xx
38
                //                'proxy'           => '192.192.192.192:10',
39
            ]
40
        );
41
    }
42
43
    public function get(string|UriInterface $uri, array $options = []): ResponseInterface
44
    {
45
        return $this->client->get($uri, $options);
46
    }
47
48
    public function request($method, $uri, array $options = []): ResponseInterface
49
    {
50
        return $this->client->request($method, $uri, $options);
51
    }
52
}