Conditions | 2 |
Paths | 2 |
Total Lines | 20 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
16 | 19 | public function decodeFrame(string $data, int $offset = 0): Frame |
|
17 | { |
||
18 | 19 | if ((\strlen($data) - $offset) < Frame::WIRE_SIZE) { |
|
19 | 2 | throw new InsufficientDataException( |
|
20 | 2 | "Frame requires " . Frame::WIRE_SIZE . " bytes, got " . (\strlen($data) - $offset) . " bytes" |
|
21 | ); |
||
22 | } |
||
23 | |||
24 | [ |
||
25 | 17 | 'size' => $size, |
|
26 | 17 | 'protocol' => $protocol, |
|
27 | 17 | 'source' => $source, |
|
28 | 17 | ] = \unpack('vsize/vprotocol/Vsource', $data, $offset); |
|
29 | |||
30 | 17 | $origin = ($protocol & 0xC000) >> 14; |
|
31 | 17 | $isTagged = (bool)($protocol & 0x2000); |
|
32 | 17 | $isAddressable = (bool)($protocol & 0x1000); |
|
33 | 17 | $protocol = ($protocol & 0x0FFF); |
|
34 | |||
35 | 17 | return new Frame($size, $origin, $isTagged, $isAddressable, $protocol, $source); |
|
36 | } |
||
38 |