| Total Complexity | 8 |
| Total Lines | 75 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class Byte extends AbstractDataType |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @throws EndOfFileReachedException |
||
| 16 | * |
||
| 17 | * @return array |
||
| 18 | */ |
||
| 19 | public function read(): array |
||
| 20 | { |
||
| 21 | $this->assertNotEndOfFile(); |
||
| 22 | |||
| 23 | return [$this->getByte($this->offset++)]; |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param int $length |
||
| 28 | * |
||
| 29 | * @throws EndOfFileReachedException |
||
| 30 | * |
||
| 31 | * @return array |
||
| 32 | */ |
||
| 33 | public function readArray(int $length): array |
||
| 34 | { |
||
| 35 | $buffer = []; |
||
| 36 | |||
| 37 | for ($iterator = 0; $iterator < $length; ++$iterator) { |
||
| 38 | $this->assertNotEndOfFile(); |
||
| 39 | |||
| 40 | $buffer[] = $this->getByte($this->offset++); |
||
| 41 | } |
||
| 42 | |||
| 43 | return $buffer; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param int $data |
||
| 48 | * |
||
| 49 | * @throws EndOfFileReachedException |
||
| 50 | */ |
||
| 51 | public function write(int $data): void |
||
| 52 | { |
||
| 53 | $this->assertNotEndOfFile(); |
||
| 54 | $this->setByte($this->offset++, $data); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param array $data |
||
| 59 | * |
||
| 60 | * @throws EndOfFileReachedException |
||
| 61 | */ |
||
| 62 | public function writeArray(array $data): void |
||
| 63 | { |
||
| 64 | $dataLength = count($data); |
||
| 65 | $startBytePosition = $this->offset; |
||
| 66 | |||
| 67 | for ($i = $startBytePosition; $i <= $startBytePosition - 1 + $dataLength; ++$i) { |
||
| 68 | $this->assertNotEndOfFile(); |
||
| 69 | $this->setByte($this->offset++, $data[$i - $startBytePosition]); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @return string |
||
| 75 | */ |
||
| 76 | public function newContent(): string |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return int |
||
| 83 | */ |
||
| 84 | public function newOffset(): int |
||
| 87 | } |
||
| 88 | } |
||
| 89 |