| Conditions | 1 |
| Paths | 1 |
| Total Lines | 19 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 9 | public function decodeFrame(string $data): Frame |
||
| 10 | { |
||
| 11 | \assert( |
||
| 12 | \strlen($data) === Frame::WIRE_SIZE, |
||
| 13 | new \Error("Frame data length expected to be " . Frame::WIRE_SIZE . " bytes, got " . \strlen($data) . " bytes") |
||
| 14 | ); |
||
| 15 | |||
| 16 | $parts = \unpack('vsize/vprotocol/Vsource', $data); |
||
| 17 | |||
| 18 | $size = $parts['size']; |
||
| 19 | $source = $parts['source']; |
||
| 20 | |||
| 21 | $origin = ($parts['protocol'] & 0xC000) >> 14; |
||
| 22 | $isTagged = (bool)($parts['protocol'] & 0x2000); |
||
| 23 | $isAddressable = (bool)($parts['protocol'] & 0x1000); |
||
| 24 | $protocol = ($parts['protocol'] & 0x0FFF); |
||
| 25 | |||
| 26 | return new Frame($size, $origin, $isTagged, $isAddressable, $protocol, $source); |
||
| 27 | } |
||
| 28 | } |
||
| 29 |