PagSeguroException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 34
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A createMessage() 0 15 3
1
<?php
2
namespace PHPSC\PagSeguro\Client;
3
4
use Psr\Http\Message\ResponseInterface;
5
6
class PagSeguroException extends \RuntimeException
7
{
8
    /**
9
     * @param ResponseInterface $response
10
     * @param \Exception|null   $cause
11
     *
12
     * @return PagSeguroException
13
     */
14 2
    public static function create(ResponseInterface $response, \Exception $cause = null)
15
    {
16 2
        return new static(static::createMessage($response), null, $cause);
17
    }
18
19
    /**
20
     * @param ResponseInterface $response
21
     *
22
     * @return string
23
     */
24 2
    protected static function createMessage(ResponseInterface $response)
25
    {
26 2
        if ($response->getStatusCode() !== 400) {
27 1
            return  '[' . $response->getStatusCode() . '] A HTTP error has occurred: ' . $response->getBody();
28
        }
29
30 1
        $message = 'Some errors occurred:';
31 1
        $content = new \SimpleXMLElement($response->getBody()->getContents());
32
33 1
        foreach ($content->error as $error) {
34 1
            $message .= PHP_EOL . '[' . (string) $error->code . '] ' . (string) $error->message;
35
        }
36
37 1
        return $message;
38
    }
39
}
40