Completed
Push — master ( 2fc2a6...0c8b94 )
by Steven
02:30
created

GithubIdentityProviderException::oauthException()   A

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