1 | <?php |
||
11 | class Parser |
||
12 | { |
||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | private $string; |
||
17 | |||
18 | /** |
||
19 | * @var \Mdanter\Ecc\Math\GmpMathInterface |
||
20 | */ |
||
21 | private $math; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | private $size = 0; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | private $position = 0; |
||
32 | |||
33 | /** |
||
34 | * Instantiate class, optionally taking Buffer or HEX. |
||
35 | * |
||
36 | * @param null|string|BufferInterface $input |
||
37 | * @param GmpMathInterface|null $math |
||
38 | */ |
||
39 | public function __construct($input = null, GmpMathInterface $math = null) |
||
59 | |||
60 | /** |
||
61 | * Get the position pointer of the parser - ie, how many bytes from 0 |
||
62 | * |
||
63 | * @return int |
||
64 | */ |
||
65 | public function getPosition(): int |
||
69 | |||
70 | /** |
||
71 | * Get the total size of the parser |
||
72 | * |
||
73 | * @return int |
||
74 | */ |
||
75 | public function getSize() |
||
79 | |||
80 | /** |
||
81 | * Parse $bytes bytes from the string, and return the obtained buffer |
||
82 | * |
||
83 | * @param int $numBytes |
||
84 | * @param bool $flipBytes |
||
85 | * @return BufferInterface |
||
86 | * @throws \Exception |
||
87 | */ |
||
88 | public function readBytes(int $numBytes, bool $flipBytes = false): BufferInterface |
||
107 | |||
108 | /** |
||
109 | * Write $data as $bytes bytes. Can be flipped if needed. |
||
110 | * |
||
111 | * @param integer $numBytes - number of bytes to write |
||
112 | * @param SerializableInterface|BufferInterface|string $data - buffer, serializable or hex |
||
113 | * @param bool $flipBytes |
||
114 | * @return Parser |
||
115 | */ |
||
116 | public function writeBytes(int $numBytes, $data, bool $flipBytes = false): Parser |
||
134 | |||
135 | /** |
||
136 | * Write $data as $bytes bytes. Can be flipped if needed. |
||
137 | * |
||
138 | * @param integer $numBytes |
||
139 | * @param string $data |
||
140 | * @param bool $flipBytes |
||
141 | * @return Parser |
||
142 | */ |
||
143 | public function writeRawBinary(int $numBytes, string $data, bool $flipBytes = false): Parser |
||
147 | |||
148 | /** |
||
149 | * @param BufferInterface $buffer |
||
150 | * @param bool $flipBytes |
||
151 | * @param int $numBytes |
||
152 | * @return Parser |
||
153 | */ |
||
154 | public function writeBuffer(int $numBytes, BufferInterface $buffer, bool $flipBytes = false): Parser |
||
165 | |||
166 | /** |
||
167 | * @param BufferInterface $buffer |
||
168 | * @param bool $flipBytes |
||
169 | * @return Parser |
||
170 | */ |
||
171 | public function appendBuffer(BufferInterface $buffer, bool $flipBytes = false): Parser |
||
176 | |||
177 | /** |
||
178 | * @param string $binary |
||
179 | * @param bool $flipBytes |
||
180 | * @return Parser |
||
181 | */ |
||
182 | public function appendBinary(string $binary, bool $flipBytes = false): Parser |
||
192 | |||
193 | /** |
||
194 | * Take an array containing serializable objects. |
||
195 | * @param SerializableInterface[]|BufferInterface[] $serializable |
||
196 | * @return Parser |
||
197 | */ |
||
198 | public function writeArray(array $serializable): Parser |
||
218 | |||
219 | /** |
||
220 | * Return the string as a buffer |
||
221 | * |
||
222 | * @return BufferInterface |
||
223 | */ |
||
224 | public function getBuffer(): BufferInterface |
||
228 | } |
||
229 |
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.