Passed
Push — master ( 9f17d2...e5ff49 )
by
unknown
03:30
created

Client::getResponse()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.2
cc 4
eloc 11
nc 4
nop 1
crap 4
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 135
    public function __construct(\GuzzleHttp\ClientInterface $guzzleClient)
23
    {
24 135
        $this->guzzleClient = $guzzleClient;
25 135
    }
26
27
    /**
28
     * @param  string                               $url
29
     */
30 4
    public function getResponse($url)
31
    {
32
        try {
33 4
            return $this->guzzleClient->request('GET', $url);
34 3
        } catch (RequestException $e) {
35 3
            if (is_null($e->getResponse())) {
36 1
                throw new HttpErrorException;
37
            }
38 2
            switch ((int) $e->getResponse()->getStatusCode()) {
39 2
                case 404:
40 1
                    throw new NotFoundException($e->getMessage());
41
                default:
42 1
                    throw new ServerErrorException($e->getMessage());
43
            }
44
        }
45
    }
46
}
47