Completed
Push — master ( e74d7a...0f4fe2 )
by Tobias
04:18
created

HttpClientException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 46
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A badRequest() 0 4 1
A unauthorized() 0 4 1
A requestFailed() 0 4 1
A notFound() 0 4 1
A getResponse() 0 4 1
1
<?php
2
3
/*
4
 * Copyright (C) 2013-2016 Mailgun
5
 *
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace Mailgun\Exception;
11
12
use Mailgun\Exception;
13
use Psr\Http\Message\ResponseInterface;
14
15
/**
16
 * @author Tobias Nyholm <[email protected]>
17
 */
18
final class HttpClientException extends \RuntimeException implements Exception
19
{
20
    /**
21
     * @var ResponseInterface|null
22
     */
23
    private $response;
24
25
    /**
26
     * @param string                 $message
27
     * @param int                    $code
28
     * @param ResponseInterface|null $response
29
     */
30
    public function __construct($message, $code, ResponseInterface $response = null)
31
    {
32
        parent::__construct($message, $code);
33
        $this->response = $response;
34
    }
35
36
    public static function badRequest(ResponseInterface $response = null)
37
    {
38
        return new self('The parameters passed to the API were invalid. Check your inputs!', 400, $response);
39
    }
40
41
    public static function unauthorized(ResponseInterface $response = null)
42
    {
43
        return new self('Your credentials are incorrect.', 401, $response);
44
    }
45
46
    public static function requestFailed(ResponseInterface $response = null)
47
    {
48
        return new self('Parameters were valid but request failed. Try again.', 402, $response);
49
    }
50
51
    public static function notFound(ResponseInterface $response = null)
52
    {
53
        return new self('The endpoint you tried to access does not exist. Check your URL.', 404, $response);
54
    }
55
56
    /**
57
     * @return ResponseInterface
58
     */
59
    public function getResponse()
60
    {
61
        return $this->response;
62
    }
63
}
64