Passed
Push — master ( 7ef1e6...041b4f )
by Songda
02:07 queued 15s
created

ArrayDirection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Direction;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Yansongda\Pay\Contract\PackerInterface;
9
use Yansongda\Pay\Contract\ParserInterface;
10
use Yansongda\Pay\Exception\Exception;
11
use Yansongda\Pay\Exception\InvalidResponseException;
12
13
class ArrayDirection implements ParserInterface
14
{
15
    /**
16
     * @throws InvalidResponseException
17
     */
18
    public function parse(PackerInterface $packer, ?ResponseInterface $response): array
19
    {
20
        if (is_null($response)) {
21
            throw new InvalidResponseException(Exception::RESPONSE_NONE);
22
        }
23
24
        $body = (string) $response->getBody();
25
26
        if (!is_null($result = $packer->unpack($body))) {
27
            return $result;
28
        }
29
30
        throw new InvalidResponseException(Exception::UNPACK_RESPONSE_ERROR, 'Unpack Response Error', ['body' => $body, 'response' => $response]);
31
    }
32
}
33