32
32
33
33
final class BitArray
34
34
{
35
- private $ bits ;
36
- private $ size ;
35
+ /**
36
+ * @var mixed[]|mixed|int[]|null
37
+ */
38
+ private $ bits ;
39
+ /**
40
+ * @var mixed|null
41
+ */
42
+ private $ size ;
37
43
38
44
39
45
public function __construct ($ bits = [], $ size = 0 )
@@ -43,7 +49,7 @@ public function __construct($bits = [], $size = 0)
43
49
$ this ->bits = [];
44
50
} elseif ($ bits && !$ size ) {
45
51
$ this ->size = $ bits ;
46
- $ this ->bits = $ this -> makeArray ($ bits );
52
+ $ this ->bits = self :: makeArray ($ bits );
47
53
} else {
48
54
$ this ->bits = $ bits ;
49
55
$ this ->size = $ size ;
@@ -70,7 +76,7 @@ public function getSizeInBytes()
70
76
*
71
77
* @param bit $i to set
72
78
*/
73
- public function set ($ i )
79
+ public function set ($ i ): void
74
80
{
75
81
$ this ->bits [(int )($ i / 32 )] |= 1 << ($ i & 0x1F );
76
82
$ this ->bits [(int )($ i / 32 )] = ($ this ->bits [(int )($ i / 32 )]);
@@ -81,7 +87,7 @@ public function set($i)
81
87
*
82
88
* @param bit $i to set
83
89
*/
84
- public function flip ($ i )
90
+ public function flip ($ i ): void
85
91
{
86
92
$ this ->bits [(int )($ i / 32 )] ^= 1 << ($ i & 0x1F );
87
93
$ this ->bits [(int )($ i / 32 )] = ($ this ->bits [(int )($ i / 32 )]);
@@ -104,7 +110,7 @@ public function getNextSet($from)
104
110
// mask off lesser bits first
105
111
$ currentBits &= ~((1 << ($ from & 0x1F )) - 1 );
106
112
while ($ currentBits == 0 ) {
107
- if (++$ bitsOffset == count ($ this ->bits )) {
113
+ if (++$ bitsOffset == ( is_countable ( $ this -> bits ) ? count ($ this ->bits ) : 0 )) {
108
114
return $ this ->size ;
109
115
}
110
116
$ currentBits = $ this ->bits [$ bitsOffset ];
@@ -130,7 +136,7 @@ public function getNextUnset($from)
130
136
// mask off lesser bits first
131
137
$ currentBits &= ~((1 << ($ from & 0x1F )) - 1 );
132
138
while ($ currentBits == 0 ) {
133
- if (++$ bitsOffset == count ($ this ->bits )) {
139
+ if (++$ bitsOffset == ( is_countable ( $ this -> bits ) ? count ($ this ->bits ) : 0 )) {
134
140
return $ this ->size ;
135
141
}
136
142
$ currentBits = (~$ this ->bits [$ bitsOffset ]);
@@ -147,7 +153,7 @@ public function getNextUnset($from)
147
153
* @param the $newBits new value of the next 32 bits. Note again that the least-significant bit
148
154
* corresponds to bit i, the next-least-significant to i+1, and so on.
149
155
*/
150
- public function setBulk ($ i , $ newBits )
156
+ public function setBulk ($ i , $ newBits ): void
151
157
{
152
158
$ this ->bits [(int )($ i / 32 )] = $ newBits ;
153
159
}
@@ -188,9 +194,9 @@ public function setRange($start, $end)
188
194
/**
189
195
* Clears all bits (sets to false).
190
196
*/
191
- public function clear ()
197
+ public function clear (): void
192
198
{
193
- $ max = count ($ this ->bits );
199
+ $ max = is_countable ( $ this -> bits ) ? count ($ this ->bits ) : 0 ;
194
200
for ($ i = 0 ; $ i < $ max ; $ i ++) {
195
201
$ this ->bits [$ i ] = 0 ;
196
202
}
@@ -259,16 +265,16 @@ public function appendBits($value, $numBits)
259
265
}
260
266
}
261
267
262
- private function ensureCapacity ($ size )
268
+ private function ensureCapacity ($ size ): void
263
269
{
264
- if ($ size > count ($ this ->bits ) * 32 ) {
265
- $ newBits = $ this -> makeArray ($ size );
266
- $ newBits = arraycopy ($ this ->bits , 0 , $ newBits , 0 , count ($ this ->bits ));
270
+ if ($ size > ( is_countable ( $ this -> bits ) ? count ($ this ->bits ) : 0 ) * 32 ) {
271
+ $ newBits = self :: makeArray ($ size );
272
+ $ newBits = arraycopy ($ this ->bits , 0 , $ newBits , 0 , is_countable ( $ this -> bits ) ? count ($ this ->bits ) : 0 );
267
273
$ this ->bits = $ newBits ;
268
274
}
269
275
}
270
276
271
- public function appendBit ($ bit )
277
+ public function appendBit ($ bit ): void
272
278
{
273
279
$ this ->ensureCapacity ($ this ->size + 1 );
274
280
if ($ bit ) {
@@ -277,7 +283,7 @@ public function appendBit($bit)
277
283
$ this ->size ++;
278
284
}
279
285
280
- public function appendBitArray ($ other )
286
+ public function appendBitArray ($ other ): void
281
287
{
282
288
$ otherSize = $ other ->size ;
283
289
$ this ->ensureCapacity ($ this ->size + $ otherSize );
@@ -288,10 +294,10 @@ public function appendBitArray($other)
288
294
289
295
public function _xor ($ other )
290
296
{
291
- if (count ($ this ->bits ) !== count ($ other ->bits )) {
297
+ if (( is_countable ( $ this -> bits ) ? count ($ this ->bits ) : 0 ) !== ( is_countable ( $ other -> bits ) ? count ($ other ->bits ) : 0 )) {
292
298
throw new \InvalidArgumentException ("Sizes don't match " );
293
299
}
294
- $ count = count ($ this ->bits );
300
+ $ count = is_countable ( $ this -> bits ) ? count ($ this ->bits ) : 0 ;
295
301
for ($ i = 0 ; $ i < $ count ; $ i ++) {
296
302
// The last byte could be incomplete (i.e. not have 8 bits in
297
303
// it) but there is no problem since 0 XOR 0 == 0.
@@ -307,7 +313,7 @@ public function _xor($other)
307
313
* @param position $offset in array to start writing
308
314
* @param how $numBytes many bytes to write
309
315
*/
310
- public function toBytes ($ bitOffset , &$ array , $ offset , $ numBytes )
316
+ public function toBytes ($ bitOffset , &$ array , $ offset , $ numBytes ): void
311
317
{
312
318
for ($ i = 0 ; $ i < $ numBytes ; $ i ++) {
313
319
$ theByte = 0 ;
@@ -345,7 +351,7 @@ public function getBitArray()
345
351
/**
346
352
* Reverses all bits in the array.
347
353
*/
348
- public function reverse ()
354
+ public function reverse (): void
349
355
{
350
356
$ newBits = [];
351
357
// reverse all int's first
@@ -412,7 +418,7 @@ public function toString()
412
418
return (string )$ result ;
413
419
}
414
420
415
- public function _clone ()
421
+ public function _clone (): \ Zxing \ Common \ BitArray
416
422
{
417
423
return new BitArray ($ this ->bits , $ this ->size );
418
424
}
0 commit comments