| Conditions | 3 |
| Paths | 3 |
| Total Lines | 19 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 3.054 |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | 1 | public function parsePayload(StreamInterface $stream): array |
|
| 23 | { |
||
| 24 | 1 | if ($stream->getSize() < 12) { |
|
| 25 | throw new \Exception("Malformed data (size too small)"); |
||
| 26 | } |
||
| 27 | |||
| 28 | 1 | $stream = $this->stream->hex2bin($stream); |
|
| 29 | |||
| 30 | 1 | list ($type) = array_values(unpack('n', $stream->read(2))); |
|
| 31 | 1 | $stream->seek(2); |
|
| 32 | |||
| 33 | 1 | list ($size) = array_values(unpack('N', $stream->read(4))); |
|
| 34 | 1 | $stream->seek(6); |
|
| 35 | |||
| 36 | 1 | if ($size > ($stream->getSize() - 6)) { |
|
| 37 | throw new \Exception("Malformed data (sent more than size)"); |
||
| 38 | } |
||
| 39 | |||
| 40 | 1 | return [$type, $this->stream->createStream($stream->read($size))]; |
|
| 41 | } |
||
| 56 |