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 null|string|BufferInterface $input |
||
30 | */ |
||
31 | 164 | public function __construct($input = null) |
|
49 | |||
50 | /** |
||
51 | * Get the position pointer of the parser - ie, how many bytes from 0 |
||
52 | * |
||
53 | * @return int |
||
54 | */ |
||
55 | 148 | public function getPosition(): int |
|
59 | |||
60 | /** |
||
61 | * Get the total size of the parser |
||
62 | * |
||
63 | * @return int |
||
64 | */ |
||
65 | 16 | public function getSize() |
|
69 | |||
70 | /** |
||
71 | * Parse $bytes bytes from the string, and return the obtained buffer |
||
72 | * |
||
73 | * @param int $numBytes |
||
74 | * @param bool $flipBytes |
||
75 | * @return BufferInterface |
||
76 | * @throws \Exception |
||
77 | */ |
||
78 | 146 | public function readBytes(int $numBytes, bool $flipBytes = false): BufferInterface |
|
98 | |||
99 | /** |
||
100 | * Write $data as $bytes bytes. Can be flipped if needed. |
||
101 | * |
||
102 | * @param integer $numBytes - number of bytes to write |
||
103 | * @param SerializableInterface|BufferInterface|string $data - buffer, serializable or hex |
||
104 | * @param bool $flipBytes |
||
105 | * @return Parser |
||
106 | */ |
||
107 | 10 | public function writeBytes(int $numBytes, $data, bool $flipBytes = false): Parser |
|
125 | |||
126 | /** |
||
127 | * Write $data as $bytes bytes. Can be flipped if needed. |
||
128 | * |
||
129 | * @param integer $numBytes |
||
130 | * @param string $data |
||
131 | * @param bool $flipBytes |
||
132 | * @return Parser |
||
133 | */ |
||
134 | public function writeRawBinary(int $numBytes, string $data, bool $flipBytes = false): Parser |
||
138 | |||
139 | /** |
||
140 | * @param BufferInterface $buffer |
||
141 | * @param bool $flipBytes |
||
142 | * @param int $numBytes |
||
143 | * @return Parser |
||
144 | */ |
||
145 | 10 | public function writeBuffer(int $numBytes, BufferInterface $buffer, bool $flipBytes = false): Parser |
|
156 | |||
157 | /** |
||
158 | * @param BufferInterface $buffer |
||
159 | * @param bool $flipBytes |
||
160 | * @return Parser |
||
161 | */ |
||
162 | 10 | public function appendBuffer(BufferInterface $buffer, bool $flipBytes = false): Parser |
|
167 | |||
168 | /** |
||
169 | * @param string $binary |
||
170 | * @param bool $flipBytes |
||
171 | * @return Parser |
||
172 | */ |
||
173 | 10 | public function appendBinary(string $binary, bool $flipBytes = false): Parser |
|
183 | |||
184 | /** |
||
185 | * Take an array containing serializable objects. |
||
186 | * @param SerializableInterface[]|BufferInterface[] $serializable |
||
187 | * @return Parser |
||
188 | */ |
||
189 | 2 | public function writeArray(array $serializable): Parser |
|
209 | |||
210 | /** |
||
211 | * Return the string as a buffer |
||
212 | * |
||
213 | * @return BufferInterface |
||
214 | */ |
||
215 | 16 | public function getBuffer(): BufferInterface |
|
219 | } |
||
220 |
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.