Completed
Push — master ( c67749...e01f26 )
by Alex
01:55
created

StackExchangeException::errorResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 2
crap 2
1
<?php
2
3
namespace AlexMasterov\OAuth2\Client\Provider\Exception;
4
5
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
6
use Psr\Http\Message\ResponseInterface;
7
8
class StackExchangeException extends IdentityProviderException
9
{
10
    /**
11
     * @param ResponseInterface $response
12
     * @param string|array $data
13
     *
14
     * @return static
15
     */
16 1
    public static function errorResponse(ResponseInterface $response, $data)
17
    {
18 1
        $message = $data['error']['type'];
19
20 1
        if (!empty($data['error']['message'])) {
21 1
            $message .= ': '.$data['error']['message'];
22
        }
23
24 1
        $code = $response->getStatusCode();
25 1
        $body = (string) $response->getBody();
26
27 1
        return new static($message, $code, $body);
28
    }
29
}
30