ContinuationFrame::parseBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
namespace Hyphper\Frame;
4
5
/**
6
 * The CONTINUATION frame is used to continue a sequence of header block
7
 * fragments. Any number of CONTINUATION frames can be sent on an existing
8
 * stream, as long as the preceding frame on the same stream is one of
9
 * HEADERS, PUSH_PROMISE or CONTINUATION without the END_HEADERS flag set.
10
 * Much like the HEADERS frame, hyper treats this as an opaque data frame with
11
 * different flags and a different type.
12
 *
13
 * @package Hyphper\Frame
14
 */
15
class ContinuationFrame extends \Hyphper\Frame
16
{
17
    protected $defined_flags = [Flag::END_HEADERS];
18
    protected $type = 0x09;
19
    protected $stream_association = self::HAS_STREAM;
20
    protected $data;
21
22
    /**
23
     * ContinuationFrame constructor.
24
     *
25
     * @param array $options
26
     */
27 3
    public function __construct(array $options = [])
28
    {
29 3
        parent::__construct($options);
30
31 3
        $this->data = $options['data'] ?? '';
32 3
    }
33
34
    /**
35
     * @return string
36
     */
37 1
    public function serializeBody(): string
38
    {
39 1
        return $this->data;
40
    }
41
42
    /**
43
     * Given the body of a frame, parses it into frame data. This populates
44
     * the non-header parts of the frame: that is, it does not populate the
45
     * stream ID or flags.
46
     *
47
     *
48
     * @param string $data
49
     *
50
     * @return void
51
     */
52 1
    public function parseBody(string $data)
53
    {
54 1
        $this->data = $data;
55 1
        $this->body_len = strlen($data);
56 1
    }
57
58
    /**
59
     * @param mixed|string $data
60
     *
61
     * @return ContinuationFrame
62
     */
63 1
    public function setData($data)
64
    {
65 1
        $this->data = $data;
66
67 1
        return $this;
68
    }
69
70
    /**
71
     * @return mixed|string
72
     */
73 1
    public function getData()
74
    {
75 1
        return $this->data;
76
    }
77
}
78