GuzzleClient::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Acelaya\Website\Feed;
5
6
use GuzzleHttp\Client;
7
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
8
use Zend\Feed\Reader\Http\ClientInterface as FeedReaderHttpClientInterface;
9
use Zend\Feed\Reader\Http\Psr7ResponseDecorator;
10
use Zend\Feed\Reader\Http\ResponseInterface;
11
12
class GuzzleClient implements FeedReaderHttpClientInterface
13
{
14
    /**
15
     * @var GuzzleClientInterface
16
     */
17
    private $client;
18
19
    /**
20
     * @param GuzzleClientInterface|null $client
21
     */
22
    public function __construct(GuzzleClientInterface $client = null)
23
    {
24
        $this->client = $client ?: new Client();
25
    }
26
27
    /**
28
     * Make a GET request to a given URI
29
     *
30
     * @param  string $uri
31
     * @return ResponseInterface
32
     */
33
    public function get($uri)
34
    {
35
        return new Psr7ResponseDecorator(
36
            $this->client->request('GET', $uri)
37
        );
38
    }
39
}
40