WindowUpdateFrame::getWindowIncrement()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
namespace Hyphper\Frame;
4
5
use Hyphper\Frame\Exception\InvalidFrameException;
6
7
/**
8
 * The WINDOW_UPDATE frame is used to implement flow control.
9
 * Flow control operates at two levels: on each individual stream and on the
10
 * entire connection.
11
 *
12
 * Both types of flow control are hop by hop; that is, only between the two
13
 * endpoints. Intermediaries do not forward WINDOW_UPDATE frames between
14
 * dependent connections. However, throttling of data transfer by any receiver
15
 * can indirectly cause the propagation of flow control information toward the
16
 * original sender.
17
 *
18
 * @package Hyphper\Frame
19
 */
20
class WindowUpdateFrame extends \Hyphper\Frame
21
{
22
    protected $defined_flags = [];
23
    protected $type = 0x08;
24
    protected $stream_association = self::EITHER_STREAM;
25
    protected $window_increment;
26
27
    /**
28
     * WindowUpdateFrame constructor.
29
     *
30
     * @param array $options
31
     */
32 4
    public function __construct(array $options = [])
33
    {
34 4
        parent::__construct($options);
35
36 4
        $this->window_increment = $options['window_increment'] ?? 0;
37 4
    }
38
39
    /**
40
     * @return string
41
     */
42 1
    public function serializeBody(): string
43
    {
44 1
        return pack('N', $this->window_increment & 0x7FFFFFFF);
45
    }
46
47
    /**
48
     * Given the body of a frame, parses it into frame data. This populates
49
     * the non-header parts of the frame: that is, it does not populate the
50
     * stream ID or flags.
51
     *
52
     *
53
     * @param string $data
54
     *
55
     * @return void
56
     */
57 2
    public function parseBody(string $data)
58
    {
59 2
        if (!$unpack = @unpack('Nwindow_increment', $data)) {
60 1
            throw new InvalidFrameException('Invalid WINDOW_UPDATE body');
61
        }
62
63 1
        $this->window_increment = $unpack['window_increment'];
64 1
        $this->body_len = strlen($data);
65 1
    }
66
67
    /**
68
     * @param int|mixed $window_increment
69
     *
70
     * @return WindowUpdateFrame
71
     */
72 1
    public function setWindowIncrement($window_increment)
73
    {
74 1
        $this->window_increment = $window_increment;
75
76 1
        return $this;
77
    }
78
79
    /**
80
     * @return int|mixed
81
     */
82 1
    public function getWindowIncrement()
83
    {
84 1
        return $this->window_increment;
85
    }
86
}
87