GumroadIdentityProviderException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 44
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A clientException() 0 7 2
A oauthException() 0 7 2
A fromResponse() 0 4 1
1
<?php
2
3
/*
4
 * Gumroad OAuth2 Provider
5
 * (c) alofoxx
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Alofoxx\OAuth2\Client\Provider\Exception;
12
13
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
14
use Psr\Http\Message\ResponseInterface;
15
16
/**
17
 * GumroadIdentityProviderException.
18
 *
19
 * @author alofoxx <[email protected]>
20
 */
21
class GumroadIdentityProviderException extends IdentityProviderException
22
{
23
    /**
24
     * Creates client exception from response.
25
     *
26
     * @param ResponseInterface $response Response received from upstream
27
     * @param mixed $data Parsed response data
28
     * @return IdentityProviderException
29
     */
30 3
    public static function clientException(ResponseInterface $response, $data)
31
    {
32 3
        return static::fromResponse(
33 3
            $response,
34 3
            isset($data['message']) ? $data['message'] : $response->getReasonPhrase()
35
        );
36
    }
37
38
    /**
39
     * Creates oauth exception from response.
40
     *
41
     * @param ResponseInterface $response Response received from upstream
42
     * @param string $data                Parsed response data
43
     * @return IdentityProviderException
44
     */
45 3
    public static function oauthException(ResponseInterface $response, $data)
46
    {
47 3
        return static::fromResponse(
48 3
            $response,
49 3
            isset($data['error']) ? $data['error'] : $response->getReasonPhrase()
50
        );
51
    }
52
53
    /**
54
     * Creates identity exception from response.
55
     *
56
     * @param ResponseInterface $response Response received from upstream
57
     * @param string|null $message        Parsed message
58
     * @return IdentityProviderException
59
     */
60 6
    protected static function fromResponse(ResponseInterface $response, $message = null)
61
    {
62 6
        return new static($message, $response->getStatusCode(), (string) $response->getBody());
63
    }
64
}
65