oauthException()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

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