Skip to content

Commit 29756f7

Browse files
committed
phpstan to level 5
1 parent 9aba4bc commit 29756f7

11 files changed

Lines changed: 36 additions & 37 deletions

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
parameters:
22
paths:
33
- src
4-
level: 4
4+
level: 5

src/Renderers/PngRenderer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function useGd()
4747

4848
public function render(Barcode $barcode, int $widthFactor = 2, int $height = 30): string
4949
{
50-
$width = round($barcode->getWidth() * $widthFactor);
50+
$width = (int)round($barcode->getWidth() * $widthFactor);
5151

5252
if ($this->useImagick) {
5353
$imagickBarsShape = new ImagickDraw();
@@ -61,11 +61,11 @@ public function render(Barcode $barcode, int $widthFactor = 2, int $height = 30)
6161
$positionHorizontal = 0;
6262
/** @var BarcodeBar $bar */
6363
foreach ($barcode->getBars() as $bar) {
64-
$barWidth = round(($bar->getWidth() * $widthFactor), 3);
64+
$barWidth = (int)round(($bar->getWidth() * $widthFactor));
6565

6666
if ($bar->isBar() && $barWidth > 0) {
67-
$y = round(($bar->getPositionVertical() * $height / $barcode->getHeight()), 3);
68-
$barHeight = round(($bar->getHeight() * $height / $barcode->getHeight()), 3);
67+
$y = (int)round(($bar->getPositionVertical() * $height / $barcode->getHeight()));
68+
$barHeight = (int)round(($bar->getHeight() * $height / $barcode->getHeight()));
6969

7070
// draw a vertical bar
7171
if ($this->useImagick) {

src/Types/TypeITF14.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function getBarcode(string $code): Barcode
6060
}
6161

6262
foreach (str_split($pmixed) as $width) {
63-
$barcode->addBar(new BarcodeBar($width, 1, $drawBar));
63+
$barcode->addBar(new BarcodeBar(intval($width), 1, $drawBar));
6464
$drawBar = ! $drawBar;
6565
}
6666
}
@@ -73,7 +73,7 @@ private function getChecksum(string $code): string
7373
$total = 0;
7474

7575
for ($charIndex = 0; $charIndex <= (strlen($code) - 1); $charIndex++) {
76-
$integerOfChar = intval($code . substr($charIndex, 1));
76+
$integerOfChar = intval($code . substr(strval($charIndex), 1));
7777
$total += $integerOfChar * (($charIndex === 0 || $charIndex % 2 === 0) ? 3 : 1);
7878
}
7979

src/Types/TypeIntelligentMailBarcode.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ public function getBarcode(string $code): Barcode
333333
throw new BarcodeException('Routing code unknown');
334334
}
335335

336-
$binary_code = bcmul($binary_code, 10);
336+
$binary_code = bcmul($binary_code, strval(10));
337337
$binary_code = bcadd($binary_code, $tracking_number[0]);
338-
$binary_code = bcmul($binary_code, 5);
338+
$binary_code = bcmul($binary_code, strval(5));
339339
$binary_code = bcadd($binary_code, $tracking_number[1]);
340340
$binary_code .= substr($tracking_number, 2, 18);
341341

@@ -360,11 +360,11 @@ public function getBarcode(string $code): Barcode
360360
// convert binary data to codewords
361361
$codewords = [];
362362
$data = $this->hex_to_dec($binary_code_102bit);
363-
$codewords[0] = bcmod($data, 636) * 2;
364-
$data = bcdiv($data, 636);
363+
$codewords[0] = bcmod($data, strval(636)) * 2;
364+
$data = bcdiv($data, strval(636));
365365
for ($i = 1; $i < 9; ++$i) {
366-
$codewords[$i] = bcmod($data, 1365);
367-
$data = bcdiv($data, 1365);
366+
$codewords[$i] = bcmod($data, strval(1365));
367+
$data = bcdiv($data, strval(1365));
368368
}
369369
$codewords[9] = $data;
370370
if (($fcs >> 10) == 1) {
@@ -440,7 +440,7 @@ protected function dec_to_hex($number)
440440
$hex = [];
441441

442442
while ($number > 0) {
443-
array_push($hex, strtoupper(dechex(bcmod($number, '16'))));
443+
$hex[] = strtoupper(dechex(intval(bcmod(strval($number), '16'))));
444444
$number = bcdiv($number, '16', 0);
445445
}
446446
$hex = array_reverse($hex);
@@ -501,8 +501,8 @@ protected function hex_to_dec($hex)
501501
$bitval = 1;
502502
$len = strlen($hex);
503503
for ($pos = ($len - 1); $pos >= 0; --$pos) {
504-
$dec = bcadd($dec, bcmul(hexdec($hex[$pos]), $bitval));
505-
$bitval = bcmul($bitval, 16);
504+
$dec = bcadd($dec, bcmul(strval(hexdec($hex[$pos])), strval($bitval)));
505+
$bitval = bcmul($bitval, '16');
506506
}
507507

508508
return $dec;

src/Types/TypeInterleaved25Checksum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getBarcode(string $code): Barcode
6262
} else {
6363
$t = false; // space
6464
}
65-
$w = $seq[$j];
65+
$w = intval($seq[$j]);
6666
$barcode->addBar(new BarcodeBar($w, 1, $t));
6767
}
6868
}

src/Types/TypeKix.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313
class TypeKix extends TypeRms4cc
1414
{
15-
protected $kix = true;
15+
protected bool $kix = true;
1616
}

src/Types/TypePharmacode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public function getBarcode(string $code): Barcode
3131
$seq = substr($seq, 0, -2);
3232
$seq = strrev($seq);
3333

34-
return BinarySequenceConverter::convert($code, $seq);
34+
return BinarySequenceConverter::convert(strval($code), $seq);
3535
}
3636
}

src/Types/TypePharmacodeTwoCode.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Picqer\Barcode\Barcode;
1111
use Picqer\Barcode\BarcodeBar;
12-
use Picqer\Barcode\Exceptions\BarcodeException;
1312
use Picqer\Barcode\Exceptions\InvalidCharacterException;
1413
use Picqer\Barcode\Exceptions\InvalidLengthException;
1514

@@ -46,7 +45,7 @@ public function getBarcode(string $code): Barcode
4645

4746
$seq = strrev($seq);
4847

49-
$barcode = new Barcode($code);
48+
$barcode = new Barcode(strval($code));
5049

5150
for ($i = 0; $i < strlen($seq); ++$i) {
5251
switch ($seq[$i]) {
@@ -69,9 +68,9 @@ public function getBarcode(string $code): Barcode
6968
throw new InvalidCharacterException('Could not find bar for char.');
7069
}
7170

72-
$barcode->addBar(new BarcodeBar(1, $h, 1, $p));
71+
$barcode->addBar(new BarcodeBar(1, $h, true, $p));
7372
if ($i < (strlen($seq) - 1)) {
74-
$barcode->addBar(new BarcodeBar(1, 2, 0, 0));
73+
$barcode->addBar(new BarcodeBar(1, 2, false, 0));
7574
}
7675
}
7776

src/Types/TypePostnet.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,20 @@ public function getBarcode(string $code): Barcode
4949
$len = strlen($code);
5050

5151
// start bar
52-
$barcode->addBar(new BarcodeBar(1, 2, 1));
53-
$barcode->addBar(new BarcodeBar(1, 2, 0));
52+
$barcode->addBar(new BarcodeBar(1, 2, true));
53+
$barcode->addBar(new BarcodeBar(1, 2, false));
5454

5555
for ($i = 0; $i < $len; ++$i) {
5656
for ($j = 0; $j < 5; ++$j) {
5757
$h = $this->barlen[$code[$i]][$j];
58-
$p = floor(1 / $h);
59-
$barcode->addBar(new BarcodeBar(1, $h, 1, $p));
60-
$barcode->addBar(new BarcodeBar(1, 2, 0));
58+
$p = (int)floor(1 / $h);
59+
$barcode->addBar(new BarcodeBar(1, (int)$h, true, $p));
60+
$barcode->addBar(new BarcodeBar(1, 2, false));
6161
}
6262
}
6363

6464
// end bar
65-
$barcode->addBar(new BarcodeBar(1, 2, 1));
65+
$barcode->addBar(new BarcodeBar(1, 2, true));
6666

6767
return $barcode;
6868
}

src/Types/TypeRms4cc.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class TypeRms4cc implements TypeInterface
1717
{
18-
protected $kix = false;
18+
protected bool $kix = false;
1919

2020
public function getBarcode(string $code): Barcode
2121
{
@@ -122,8 +122,8 @@ public function getBarcode(string $code): Barcode
122122
++$len;
123123

124124
// start bar
125-
$barcode->addBar(new BarcodeBar(1, 2, 1));
126-
$barcode->addBar(new BarcodeBar(1, 2, 0));
125+
$barcode->addBar(new BarcodeBar(1, 2, true));
126+
$barcode->addBar(new BarcodeBar(1, 2, false));
127127
}
128128

129129
for ($i = 0; $i < $len; ++$i) {
@@ -150,14 +150,14 @@ public function getBarcode(string $code): Barcode
150150
break;
151151
}
152152

153-
$barcode->addBar(new BarcodeBar(1, $h, 1, $p));
154-
$barcode->addBar(new BarcodeBar(1, 2, 0));
153+
$barcode->addBar(new BarcodeBar(1, $h, true, $p));
154+
$barcode->addBar(new BarcodeBar(1, 2, false));
155155
}
156156
}
157157

158158
if (! $this->kix) {
159159
// stop bar
160-
$barcode->addBar(new BarcodeBar(1, 3, 1));
160+
$barcode->addBar(new BarcodeBar(1, 3, true));
161161
}
162162

163163
return $barcode;

0 commit comments

Comments
 (0)