Skip to content

Commit 37269d3

Browse files
committed
Run rector (& do some minor manual adjustments) to improve PHP 8.1 compatibility
1 parent 67bae89 commit 37269d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+595
-647
lines changed

lib/Binarizer.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@
3030
*/
3131
abstract class Binarizer
3232
{
33-
private $source;
34-
35-
protected function __construct($source)
36-
{
37-
$this->source = $source;
38-
}
33+
protected function __construct(private $source)
34+
{
35+
}
3936

4037
/**
4138
* @return LuminanceSource

lib/BinaryBitmap.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
*/
2828
final class BinaryBitmap
2929
{
30-
private $binarizer;
31-
private $matrix;
30+
private readonly \Zxing\Binarizer $binarizer;
31+
private ?\Zxing\Common\BitMatrix $matrix = null;
3232

3333
public function __construct(Binarizer $binarizer)
3434
{
@@ -90,7 +90,7 @@ public function isCropSupported()
9090
*
9191
* @return BinaryBitmap A cropped version of this object.
9292
*/
93-
public function crop($left, $top, $width, $height)
93+
public function crop($left, $top, $width, $height): \Zxing\BinaryBitmap
9494
{
9595
$newSource = $this->binarizer->getLuminanceSource()->crop($left, $top, $width, $height);
9696

@@ -111,7 +111,7 @@ public function isRotateSupported()
111111
*
112112
* @return BinaryBitmap A rotated version of this object.
113113
*/
114-
public function rotateCounterClockwise()
114+
public function rotateCounterClockwise(): \Zxing\BinaryBitmap
115115
{
116116
$newSource = $this->binarizer->getLuminanceSource()->rotateCounterClockwise();
117117

@@ -124,7 +124,7 @@ public function rotateCounterClockwise()
124124
*
125125
* @return BinaryBitmap A rotated version of this object.
126126
*/
127-
public function rotateCounterClockwise45()
127+
public function rotateCounterClockwise45(): \Zxing\BinaryBitmap
128128
{
129129
$newSource = $this->binarizer->getLuminanceSource()->rotateCounterClockwise45();
130130

@@ -135,7 +135,7 @@ public function toString()
135135
{
136136
try {
137137
return $this->getBlackMatrix()->toString();
138-
} catch (NotFoundException $e) {
138+
} catch (NotFoundException) {
139139
}
140140

141141
return '';

lib/ChecksumException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
final class ChecksumException extends ReaderException
2727
{
28-
private static $instance;
28+
private static ?\Zxing\ChecksumException $instance = null;
2929

3030
public static function getChecksumInstance($cause = null)
3131
{

lib/Common/AbstractEnum.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* A general enum implementation until we got SplEnum.
99
*/
10-
final class AbstractEnum
10+
final class AbstractEnum implements \Stringable
1111
{
1212
/**
1313
* Default value.
@@ -20,27 +20,20 @@ final class AbstractEnum
2020
*/
2121
private $value;
2222
/**
23-
* Cache of constants.
24-
*
25-
* @var array
26-
*/
27-
private $constants;
28-
/**
29-
* Whether to handle values strict or not.
30-
*
31-
* @var boolean
32-
*/
33-
private $strict;
23+
* Cache of constants.
24+
*
25+
* @var array<string, mixed>|null
26+
*/
27+
private ?array $constants = null;
3428

3529
/**
3630
* Creates a new enum.
3731
*
3832
* @param mixed $initialValue
3933
* @param boolean $strict
4034
*/
41-
public function __construct($initialValue = null, $strict = false)
35+
public function __construct($initialValue = null, private $strict = false)
4236
{
43-
$this->strict = $strict;
4437
$this->change($initialValue);
4538
}
4639

@@ -54,7 +47,7 @@ public function __construct($initialValue = null, $strict = false)
5447
public function change($value)
5548
{
5649
if (!in_array($value, $this->getConstList(), $this->strict)) {
57-
throw new \UnexpectedValueException('Value not a const in enum ' . get_class($this));
50+
throw new \UnexpectedValueException('Value not a const in enum ' . $this::class);
5851
}
5952
$this->value = $value;
6053
}
@@ -96,7 +89,7 @@ public function get()
9689
*
9790
* @return string
9891
*/
99-
public function __toString()
92+
public function __toString(): string
10093
{
10194
return (string)array_search($this->value, $this->getConstList());
10295
}

lib/Common/BitArray.php

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@
3232

3333
final class BitArray
3434
{
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;
3743

3844

3945
public function __construct($bits = [], $size = 0)
@@ -43,7 +49,7 @@ public function __construct($bits = [], $size = 0)
4349
$this->bits = [];
4450
} elseif ($bits && !$size) {
4551
$this->size = $bits;
46-
$this->bits = $this->makeArray($bits);
52+
$this->bits = self::makeArray($bits);
4753
} else {
4854
$this->bits = $bits;
4955
$this->size = $size;
@@ -70,7 +76,7 @@ public function getSizeInBytes()
7076
*
7177
* @param bit $i to set
7278
*/
73-
public function set($i)
79+
public function set($i): void
7480
{
7581
$this->bits[(int)($i / 32)] |= 1 << ($i & 0x1F);
7682
$this->bits[(int)($i / 32)] = ($this->bits[(int)($i / 32)]);
@@ -81,7 +87,7 @@ public function set($i)
8187
*
8288
* @param bit $i to set
8389
*/
84-
public function flip($i)
90+
public function flip($i): void
8591
{
8692
$this->bits[(int)($i / 32)] ^= 1 << ($i & 0x1F);
8793
$this->bits[(int)($i / 32)] = ($this->bits[(int)($i / 32)]);
@@ -104,7 +110,7 @@ public function getNextSet($from)
104110
// mask off lesser bits first
105111
$currentBits &= ~((1 << ($from & 0x1F)) - 1);
106112
while ($currentBits == 0) {
107-
if (++$bitsOffset == count($this->bits)) {
113+
if (++$bitsOffset == (is_countable($this->bits) ? count($this->bits) : 0)) {
108114
return $this->size;
109115
}
110116
$currentBits = $this->bits[$bitsOffset];
@@ -130,7 +136,7 @@ public function getNextUnset($from)
130136
// mask off lesser bits first
131137
$currentBits &= ~((1 << ($from & 0x1F)) - 1);
132138
while ($currentBits == 0) {
133-
if (++$bitsOffset == count($this->bits)) {
139+
if (++$bitsOffset == (is_countable($this->bits) ? count($this->bits) : 0)) {
134140
return $this->size;
135141
}
136142
$currentBits = (~$this->bits[$bitsOffset]);
@@ -147,7 +153,7 @@ public function getNextUnset($from)
147153
* @param the $newBits new value of the next 32 bits. Note again that the least-significant bit
148154
* corresponds to bit i, the next-least-significant to i+1, and so on.
149155
*/
150-
public function setBulk($i, $newBits)
156+
public function setBulk($i, $newBits): void
151157
{
152158
$this->bits[(int)($i / 32)] = $newBits;
153159
}
@@ -188,9 +194,9 @@ public function setRange($start, $end)
188194
/**
189195
* Clears all bits (sets to false).
190196
*/
191-
public function clear()
197+
public function clear(): void
192198
{
193-
$max = count($this->bits);
199+
$max = is_countable($this->bits) ? count($this->bits) : 0;
194200
for ($i = 0; $i < $max; $i++) {
195201
$this->bits[$i] = 0;
196202
}
@@ -259,16 +265,16 @@ public function appendBits($value, $numBits)
259265
}
260266
}
261267

262-
private function ensureCapacity($size)
268+
private function ensureCapacity($size): void
263269
{
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);
267273
$this->bits = $newBits;
268274
}
269275
}
270276

271-
public function appendBit($bit)
277+
public function appendBit($bit): void
272278
{
273279
$this->ensureCapacity($this->size + 1);
274280
if ($bit) {
@@ -277,7 +283,7 @@ public function appendBit($bit)
277283
$this->size++;
278284
}
279285

280-
public function appendBitArray($other)
286+
public function appendBitArray($other): void
281287
{
282288
$otherSize = $other->size;
283289
$this->ensureCapacity($this->size + $otherSize);
@@ -288,10 +294,10 @@ public function appendBitArray($other)
288294

289295
public function _xor($other)
290296
{
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)) {
292298
throw new \InvalidArgumentException("Sizes don't match");
293299
}
294-
$count = count($this->bits);
300+
$count = is_countable($this->bits) ? count($this->bits) : 0;
295301
for ($i = 0; $i < $count; $i++) {
296302
// The last byte could be incomplete (i.e. not have 8 bits in
297303
// it) but there is no problem since 0 XOR 0 == 0.
@@ -307,7 +313,7 @@ public function _xor($other)
307313
* @param position $offset in array to start writing
308314
* @param how $numBytes many bytes to write
309315
*/
310-
public function toBytes($bitOffset, &$array, $offset, $numBytes)
316+
public function toBytes($bitOffset, &$array, $offset, $numBytes): void
311317
{
312318
for ($i = 0; $i < $numBytes; $i++) {
313319
$theByte = 0;
@@ -345,7 +351,7 @@ public function getBitArray()
345351
/**
346352
* Reverses all bits in the array.
347353
*/
348-
public function reverse()
354+
public function reverse(): void
349355
{
350356
$newBits = [];
351357
// reverse all int's first
@@ -412,7 +418,7 @@ public function toString()
412418
return (string)$result;
413419
}
414420

415-
public function _clone()
421+
public function _clone(): \Zxing\Common\BitArray
416422
{
417423
return new BitArray($this->bits, $this->size);
418424
}

0 commit comments

Comments
 (0)