Passed
Branch master (c65ffc)
by Dāvis
03:08
created

CustomIdentityProviderException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A clientException() 0 3 2
A fromResponse() 0 3 1
A oauthException() 0 3 2
1
<?php
2
3
namespace Sludio\HelperBundle\Oauth\Exception;
4
5
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
6
use Psr\Http\Message\ResponseInterface;
7
8
class CustomIdentityProviderException extends IdentityProviderException
9
{
10
    public static function clientException(ResponseInterface $response, $data)
11
    {
12
        return static::fromResponse($response, isset($data['message']) ? $data['message'] : $response->getReasonPhrase());
13
    }
14
15
    public static function oauthException(ResponseInterface $response, $data)
16
    {
17
        return static::fromResponse($response, isset($data['error']) ? $data['error'] : $response->getReasonPhrase());
18
    }
19
20
    protected static function fromResponse(ResponseInterface $response, $message = null)
21
    {
22
        return new static($message, $response->getStatusCode(), (string)$response->getBody());
23
    }
24
}
25