3333final class BitArray
3434{
3535 /**
36- * @var mixed[]|mixed| int[]|null
36+ * @var mixed[]|int[]|null
3737 */
3838 private $ bits ;
3939 /**
@@ -56,7 +56,10 @@ public function __construct($bits = [], $size = 0)
5656 }
5757 }
5858
59- private static function makeArray ($ size )
59+ /**
60+ * @psalm-return array<empty, empty>
61+ */
62+ private static function makeArray ($ size ): array
6063 {
6164 return [];
6265 }
@@ -74,7 +77,7 @@ public function getSizeInBytes()
7477 /**
7578 * Sets bit i.
7679 *
77- * @param bit $i to set
80+ * @param int $i bit to set
7881 */
7982 public function set ($ i ): void
8083 {
@@ -85,7 +88,7 @@ public function set($i): void
8588 /**
8689 * Flips bit i.
8790 *
88- * @param bit $i to set
91+ * @param int $i bit to set
8992 */
9093 public function flip ($ i ): void
9194 {
@@ -94,9 +97,9 @@ public function flip($i): void
9497 }
9598
9699 /**
97- * @param first $from bit to check
100+ * @param int $from first bit to check
98101 *
99- * @return index of first bit that is set, starting from the given index, or size if none are set
102+ * @return int index of first bit that is set, starting from the given index, or size if none are set
100103 * at or beyond this given index
101104 * @see #getNextUnset(int)
102105 */
@@ -121,9 +124,9 @@ public function getNextSet($from)
121124 }
122125
123126 /**
124- * @param index $from to start looking for unset bit
127+ * @param int $from index to start looking for unset bit
125128 *
126- * @return index of next unset bit, or {@code size} if none are unset until the end
129+ * @return int index of next unset bit, or {@code size} if none are unset until the end
127130 * @see #getNextSet(int)
128131 */
129132 public function getNextUnset ($ from )
@@ -149,8 +152,8 @@ public function getNextUnset($from)
149152 /**
150153 * Sets a block of 32 bits, starting at bit i.
151154 *
152- * @param first $i bit to set
153- * @param the $newBits new value of the next 32 bits. Note again that the least-significant bit
155+ * @param int $i first bit to set
156+ * @param int $newBits the new value of the next 32 bits. Note again that the least-significant bit
154157 * corresponds to bit i, the next-least-significant to i+1, and so on.
155158 */
156159 public function setBulk ($ i , $ newBits ): void
@@ -161,8 +164,10 @@ public function setBulk($i, $newBits): void
161164 /**
162165 * Sets a range of bits.
163166 *
164- * @param start $start of range, inclusive.
165- * @param end $end of range, exclusive
167+ * @param int $start start of range, inclusive.
168+ * @param int $end end of range, exclusive
169+ *
170+ * @return void
166171 */
167172 public function setRange ($ start , $ end )
168173 {
@@ -205,12 +210,13 @@ public function clear(): void
205210 /**
206211 * Efficient method to check if a range of bits is set, or not set.
207212 *
208- * @param start $ start of range, inclusive.
209- * @param end $end of range, exclusive
210- * @param if $value true, checks that bits in range are set, otherwise checks that they are not set
213+ * @param int $start start of range, inclusive.
214+ * @param int $ end end of range, exclusive
215+ * @param bool $value if true, checks that bits in range are set, otherwise checks that they are not set
211216 *
212- * @return true iff all bits are set or not set in range, according to value argument
213- * @throws InvalidArgumentException if end is less than or equal to start
217+ * @return bool iff all bits are set or not set in range, according to value argument
218+ *
219+ * @throws \InvalidArgumentException if end is less than or equal to start
214220 */
215221 public function isRange ($ start , $ end , $ value ): bool
216222 {
@@ -251,10 +257,10 @@ public function isRange($start, $end, $value): bool
251257 * least-significant. For example, appending 6 bits from 0x000001E will append the bits
252258 * 0, 1, 1, 1, 1, 0 in that order.
253259 *
254- * @param $value {@code int} containing bits to append
255- * @param bits $numBits from value to append
260+ * @param int $value {@code int} containing bits to append
261+ * @param int $numBits bits from value to append
256262 */
257- public function appendBits ($ value , $ numBits )
263+ public function appendBits ($ value , $ numBits ): void
258264 {
259265 if ($ numBits < 0 || $ numBits > 32 ) {
260266 throw new \InvalidArgumentException ("Num bits must be between 0 and 32 " );
@@ -274,7 +280,7 @@ private function ensureCapacity($size): void
274280 }
275281 }
276282
277- public function appendBit ($ bit ): void
283+ public function appendBit (bool $ bit ): void
278284 {
279285 $ this ->ensureCapacity ($ this ->size + 1 );
280286 if ($ bit ) {
@@ -292,7 +298,7 @@ public function appendBitArray($other): void
292298 }
293299 }
294300
295- public function _xor ($ other )
301+ public function _xor ($ other ): void
296302 {
297303 if ((is_countable ($ this ->bits ) ? count ($ this ->bits ) : 0 ) !== (is_countable ($ other ->bits ) ? count ($ other ->bits ) : 0 )) {
298304 throw new \InvalidArgumentException ("Sizes don't match " );
@@ -307,11 +313,11 @@ public function _xor($other)
307313
308314 /**
309315 *
310- * @param first $bitOffset bit to start writing
316+ * @param int $bitOffset first bit to start writing
311317 * @param array $array to write into. Bytes are written most-significant byte first. This is the opposite
312318 * of the internal representation, which is exposed by {@link #getBitArray()}
313- * @param position $offset in array to start writing
314- * @param how $numBytes many bytes to write
319+ * @param int $offset position in array to start writing
320+ * @param int $numBytes how many bytes to write
315321 */
316322 public function toBytes ($ bitOffset , array &$ array , $ offset , $ numBytes ): void
317323 {
@@ -329,21 +335,23 @@ public function toBytes($bitOffset, array &$array, $offset, $numBytes): void
329335
330336 /**
331337 * @param $i ; bit to get
338+ * @param float|int first $i
332339 *
333- * @return true iff bit i is set
340+ * @return bool iff bit i is set
334341 */
335- public function get ($ i ): bool
342+ public function get (int | float $ i ): bool
336343 {
337344 $ key = (int )($ i / 32 );
338345
339346 return ($ this ->bits [$ key ] & (1 << ($ i & 0x1F ))) != 0 ;
340347 }
341348
342349 /**
343- * @return array underlying array of ints. The first element holds the first 32 bits, and the least
344- * significant bit is bit 0.
350+ * @return (int|mixed)[]|null underlying array of ints. The first element holds the first 32 bits, and the least significant bit is bit 0.
351+ *
352+ * @psalm-return array<int|mixed>|null
345353 */
346- public function getBitArray ()
354+ public function getBitArray (): array | null
347355 {
348356 return $ this ->bits ;
349357 }
@@ -405,7 +413,7 @@ public function hashCode()
405413 return 31 * $ this ->size + hashCode ($ this ->bits );
406414 }
407415
408- public function toString ()
416+ public function toString (): string
409417 {
410418 $ result = '' ;
411419 for ($ i = 0 ; $ i < $ this ->size ; $ i ++) {
0 commit comments