1 | <?php |
||
9 | class Parser |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | private $string = ''; |
||
15 | |||
16 | /** |
||
17 | * @var int |
||
18 | */ |
||
19 | private $size = 0; |
||
20 | |||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | private $position = 0; |
||
25 | |||
26 | /** |
||
27 | * Instantiate class, optionally taking Buffer or HEX. |
||
28 | * |
||
29 | * @param BufferInterface $input |
||
30 | */ |
||
31 | 164 | public function __construct(BufferInterface $input = null) |
|
38 | |||
39 | /** |
||
40 | * Get the position pointer of the parser - ie, how many bytes from 0 |
||
41 | * |
||
42 | * @return int |
||
43 | */ |
||
44 | 148 | public function getPosition(): int |
|
48 | |||
49 | /** |
||
50 | * Get the total size of the parser |
||
51 | * |
||
52 | * @return int |
||
53 | */ |
||
54 | 16 | public function getSize() |
|
58 | |||
59 | /** |
||
60 | * Parse $bytes bytes from the string, and return the obtained buffer |
||
61 | * |
||
62 | * @param int $numBytes |
||
63 | * @param bool $flipBytes |
||
64 | * @return BufferInterface |
||
65 | * @throws \Exception |
||
66 | */ |
||
67 | 146 | public function readBytes(int $numBytes, bool $flipBytes = false): BufferInterface |
|
87 | |||
88 | /** |
||
89 | * Write $data as $bytes bytes. Can be flipped if needed. |
||
90 | * |
||
91 | * @param integer $numBytes - number of bytes to write |
||
92 | * @param SerializableInterface|BufferInterface|string $data - buffer, serializable or hex |
||
93 | * @param bool $flipBytes |
||
94 | * @return Parser |
||
95 | */ |
||
96 | 10 | public function writeBytes(int $numBytes, $data, bool $flipBytes = false): Parser |
|
114 | |||
115 | /** |
||
116 | * Write $data as $bytes bytes. Can be flipped if needed. |
||
117 | * |
||
118 | * @param integer $numBytes |
||
119 | * @param string $data |
||
120 | * @param bool $flipBytes |
||
121 | * @return Parser |
||
122 | */ |
||
123 | public function writeRawBinary(int $numBytes, string $data, bool $flipBytes = false): Parser |
||
127 | |||
128 | /** |
||
129 | * @param BufferInterface $buffer |
||
130 | * @param bool $flipBytes |
||
131 | * @param int $numBytes |
||
132 | * @return Parser |
||
133 | */ |
||
134 | 10 | public function writeBuffer(int $numBytes, BufferInterface $buffer, bool $flipBytes = false): Parser |
|
145 | |||
146 | /** |
||
147 | * @param BufferInterface $buffer |
||
148 | * @param bool $flipBytes |
||
149 | * @return Parser |
||
150 | */ |
||
151 | 10 | public function appendBuffer(BufferInterface $buffer, bool $flipBytes = false): Parser |
|
156 | |||
157 | /** |
||
158 | * @param string $binary |
||
159 | * @param bool $flipBytes |
||
160 | * @return Parser |
||
161 | */ |
||
162 | 10 | public function appendBinary(string $binary, bool $flipBytes = false): Parser |
|
172 | |||
173 | /** |
||
174 | * Take an array containing serializable objects. |
||
175 | * @param SerializableInterface[]|BufferInterface[] $serializable |
||
176 | * @return Parser |
||
177 | */ |
||
178 | 2 | public function writeArray(array $serializable): Parser |
|
198 | |||
199 | /** |
||
200 | * Return the string as a buffer |
||
201 | * |
||
202 | * @return BufferInterface |
||
203 | */ |
||
204 | 16 | public function getBuffer(): BufferInterface |
|
208 | } |
||
209 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.