Completed
Branch develop (bc30b7)
by Alexandre
01:48
created

JiraIdentityProviderException::fromResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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