SinaWeiboIdentityProviderException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

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
 * Created by PhpStorm.
4
 * User: xiabin
5
 * Date: 16/6/24
6
 * Time: 下午7:12
7
 */
8
namespace Xiabin\OAuth2\Client\Provider\Exception;
9
10
use Psr\Http\Message\ResponseInterface;
11
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
12
13
class SinaWeiboIdentityProviderException extends IdentityProviderException
14
{
15
    /**
16
     * Creates client exception from response.
17
     *
18
     * @param  ResponseInterface $response
19
     * @param  string $data Parsed response data
20
     *
21
     * @return IdentityProviderException
22
     */
23 3
    public static function clientException(ResponseInterface $response, $data)
24
    {
25 3
        return static::fromResponse(
26 2
            $response,
27 3
            isset($data['message']) ? $data['message'] : $response->getReasonPhrase()
28 2
        );
29
    }
30
31
    /**
32
     * Creates oauth exception from response.
33
     *
34
     * @param  ResponseInterface $response
35
     * @param  string $data Parsed response data
36
     *
37
     * @return IdentityProviderException
38
     */
39 3
    public static function oauthException(ResponseInterface $response, $data)
40
    {
41 3
        return static::fromResponse(
42 2
            $response,
43 3
            isset($data['error']) ? $data['error'] : $response->getReasonPhrase()
44 2
        );
45
    }
46
47
    /**
48
     * Creates identity exception from response.
49
     *
50
     * @param  ResponseInterface $response
51
     * @param  string $message
52
     *
53
     * @return IdentityProviderException
54
     */
55 6
    protected static function fromResponse(ResponseInterface $response, $message = null)
56
    {
57 6
        return new static($message, $response->getStatusCode(), (string)$response->getBody());
58
    }
59
}
60