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

Client   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

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
    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