Completed
Push — develop ( 995160...ead6f7 )
by Fabian
01:28
created

BinaryResponse::parseResponseData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cakasim\Payone\Sdk\Api\Message;
6
7
use Psr\Http\Message\StreamInterface;
8
9
/**
10
 * The BinaryResponse class represents a special form of API response. For some API requests,
11
 * the response does not consist of parameters, but raw binary data. This class provides access
12
 * to the raw body stream. Please note that serialization of the binary data is not supported.
13
 *
14
 * @author Fabian Böttcher <[email protected]>
15
 * @since 0.1.0
16
 */
17
class BinaryResponse implements ResponseInterface
18
{
19
    /**
20
     * @var StreamInterface|null
21
     */
22
    protected $data = null;
23
24
    /**
25
     * Returns the raw data.
26
     *
27
     * @return StreamInterface|null The raw data as stream or null if no data is available.
28
     */
29
    public function getData(): ?StreamInterface
30
    {
31
        return $this->data;
32
    }
33
34
    /**
35
     * @inheritDoc
36
     */
37
    public function parseResponseData($data): void
38
    {
39
        if ($data instanceof StreamInterface) {
40
            $this->data = $data;
41
        } else {
42
            throw new \RuntimeException(sprintf("Cannot parse response data of type '%s'.", gettype($data)));
43
        }
44
    }
45
46
    /**
47
     * @inheritDoc
48
     */
49
    public function serialize(): string
50
    {
51
        return \serialize(null);
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57
    public function unserialize($serialized): void
58
    {
59
        $this->data = \unserialize($serialized);
60
    }
61
}
62