Test Failed
Pull Request — master (#17)
by
unknown
03:56
created

Client::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace vfalies\tmdb\lib\Guzzle;
4
5
use vfalies\tmdb\Interfaces\HttpRequestInterface;
6
use GuzzleHttp\Exception\RequestException;
7
use vfalies\tmdb\Exceptions\NotFoundException;
8
use vfalies\tmdb\Exceptions\ServerErrorException;
9
use vfalies\tmdb\Exceptions\HttpErrorException;
10
11
class Client implements HttpRequestInterface
12
{
13
14
    /**
15
     * @var \GuzzleHttp\ClientInterface
16
     */
17
    protected $guzzleClient;
18
19
    /**
20
     * @param \GuzzleHttp\ClientInterface $guzzleClient
21
     */
22
    public function __construct(\GuzzleHttp\ClientInterface $guzzleClient)
23
    {
24
        $this->guzzleClient = $guzzleClient;
25
    }
26
27
    /**
28
     * @param  string                               $url
29
     */
30
    public function getResponse($url)
31
    {
32
        try {
33
            return $this->guzzleClient->request('GET', $url);
34
        } catch (RequestException $e) {
35
            if (is_null($e->getResponse())) {
36
                throw new HttpErrorException;
37
            }
38
            switch ((int) $e->getResponse()->getStatusCode()) {
39
                case 404:
40
                    throw new NotFoundException($e->getMessage());
41
                default:
42
                    throw new ServerErrorException($e->getMessage());
43
            }
44
        }
45
    }
46
}
47