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

Client   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 6
dl 0
loc 36
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getResponse() 0 16 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