clientException()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Flipbox\OAuth2\Client\Provider\Exception;
4
5
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
6
use Psr\Http\Message\ResponseInterface;
7
8
class HubSpotIdentityProviderException extends IdentityProviderException
9
{
10
    /**
11
     * Creates client exception from response.
12
     *
13
     * @param  ResponseInterface $response
14
     * @param  string $data Parsed response data
15
     *
16
     * @return IdentityProviderException
17
     */
18 3
    public static function clientException(ResponseInterface $response, $data)
19
    {
20 3
        return static::fromResponse(
21 1
            $response,
22 3
            isset($data['message']) ? $data['message'] : $response->getReasonPhrase()
23 1
        );
24
    }
25
26
    /**
27
     * Creates oauth exception from response.
28
     *
29
     * @param  ResponseInterface $response
30
     * @param  string $data Parsed response data
31
     *
32
     * @return IdentityProviderException
33
     */
34 3
    public static function oauthException(ResponseInterface $response, $data)
35
    {
36 3
        return static::fromResponse(
37 1
            $response,
38 3
            isset($data['error']) ? $data['error'] : $response->getReasonPhrase()
39 1
        );
40
    }
41
42
    /**
43
     * Creates identity exception from response.
44
     *
45
     * @param  ResponseInterface $response
46
     * @param  string $message
47
     *
48
     * @return IdentityProviderException
49
     */
50 6
    protected static function fromResponse(ResponseInterface $response, $message = null)
51
    {
52 6
        return new static($message, $response->getStatusCode(), (string) $response->getBody());
53
    }
54
}
55