Skip to content

Commit

Permalink
phpstan to level 5
Browse files Browse the repository at this point in the history
  • Loading branch information
casperbakker committed Mar 31, 2024
1 parent 9aba4bc commit 29756f7
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 37 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
parameters:
paths:
- src
level: 4
level: 5
8 changes: 4 additions & 4 deletions src/Renderers/PngRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function useGd()

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

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

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

// draw a vertical bar
if ($this->useImagick) {
Expand Down
4 changes: 2 additions & 2 deletions src/Types/TypeITF14.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getBarcode(string $code): Barcode
}

foreach (str_split($pmixed) as $width) {
$barcode->addBar(new BarcodeBar($width, 1, $drawBar));
$barcode->addBar(new BarcodeBar(intval($width), 1, $drawBar));
$drawBar = ! $drawBar;
}
}
Expand All @@ -73,7 +73,7 @@ private function getChecksum(string $code): string
$total = 0;

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

Expand Down
18 changes: 9 additions & 9 deletions src/Types/TypeIntelligentMailBarcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ public function getBarcode(string $code): Barcode
throw new BarcodeException('Routing code unknown');
}

$binary_code = bcmul($binary_code, 10);
$binary_code = bcmul($binary_code, strval(10));
$binary_code = bcadd($binary_code, $tracking_number[0]);
$binary_code = bcmul($binary_code, 5);
$binary_code = bcmul($binary_code, strval(5));
$binary_code = bcadd($binary_code, $tracking_number[1]);
$binary_code .= substr($tracking_number, 2, 18);

Expand All @@ -360,11 +360,11 @@ public function getBarcode(string $code): Barcode
// convert binary data to codewords
$codewords = [];
$data = $this->hex_to_dec($binary_code_102bit);
$codewords[0] = bcmod($data, 636) * 2;
$data = bcdiv($data, 636);
$codewords[0] = bcmod($data, strval(636)) * 2;
$data = bcdiv($data, strval(636));
for ($i = 1; $i < 9; ++$i) {
$codewords[$i] = bcmod($data, 1365);
$data = bcdiv($data, 1365);
$codewords[$i] = bcmod($data, strval(1365));
$data = bcdiv($data, strval(1365));
}
$codewords[9] = $data;
if (($fcs >> 10) == 1) {
Expand Down Expand Up @@ -440,7 +440,7 @@ protected function dec_to_hex($number)
$hex = [];

while ($number > 0) {
array_push($hex, strtoupper(dechex(bcmod($number, '16'))));
$hex[] = strtoupper(dechex(intval(bcmod(strval($number), '16'))));
$number = bcdiv($number, '16', 0);
}
$hex = array_reverse($hex);
Expand Down Expand Up @@ -501,8 +501,8 @@ protected function hex_to_dec($hex)
$bitval = 1;
$len = strlen($hex);
for ($pos = ($len - 1); $pos >= 0; --$pos) {
$dec = bcadd($dec, bcmul(hexdec($hex[$pos]), $bitval));
$bitval = bcmul($bitval, 16);
$dec = bcadd($dec, bcmul(strval(hexdec($hex[$pos])), strval($bitval)));
$bitval = bcmul($bitval, '16');
}

return $dec;
Expand Down
2 changes: 1 addition & 1 deletion src/Types/TypeInterleaved25Checksum.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getBarcode(string $code): Barcode
} else {
$t = false; // space
}
$w = $seq[$j];
$w = intval($seq[$j]);
$barcode->addBar(new BarcodeBar($w, 1, $t));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Types/TypeKix.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

class TypeKix extends TypeRms4cc
{
protected $kix = true;
protected bool $kix = true;
}
2 changes: 1 addition & 1 deletion src/Types/TypePharmacode.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public function getBarcode(string $code): Barcode
$seq = substr($seq, 0, -2);
$seq = strrev($seq);

return BinarySequenceConverter::convert($code, $seq);
return BinarySequenceConverter::convert(strval($code), $seq);
}
}
7 changes: 3 additions & 4 deletions src/Types/TypePharmacodeTwoCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use Picqer\Barcode\Barcode;
use Picqer\Barcode\BarcodeBar;
use Picqer\Barcode\Exceptions\BarcodeException;
use Picqer\Barcode\Exceptions\InvalidCharacterException;
use Picqer\Barcode\Exceptions\InvalidLengthException;

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

$seq = strrev($seq);

$barcode = new Barcode($code);
$barcode = new Barcode(strval($code));

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

$barcode->addBar(new BarcodeBar(1, $h, 1, $p));
$barcode->addBar(new BarcodeBar(1, $h, true, $p));
if ($i < (strlen($seq) - 1)) {
$barcode->addBar(new BarcodeBar(1, 2, 0, 0));
$barcode->addBar(new BarcodeBar(1, 2, false, 0));
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/Types/TypePostnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ public function getBarcode(string $code): Barcode
$len = strlen($code);

// start bar
$barcode->addBar(new BarcodeBar(1, 2, 1));
$barcode->addBar(new BarcodeBar(1, 2, 0));
$barcode->addBar(new BarcodeBar(1, 2, true));
$barcode->addBar(new BarcodeBar(1, 2, false));

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

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

return $barcode;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Types/TypeRms4cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class TypeRms4cc implements TypeInterface
{
protected $kix = false;
protected bool $kix = false;

public function getBarcode(string $code): Barcode
{
Expand Down Expand Up @@ -122,8 +122,8 @@ public function getBarcode(string $code): Barcode
++$len;

// start bar
$barcode->addBar(new BarcodeBar(1, 2, 1));
$barcode->addBar(new BarcodeBar(1, 2, 0));
$barcode->addBar(new BarcodeBar(1, 2, true));
$barcode->addBar(new BarcodeBar(1, 2, false));
}

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

$barcode->addBar(new BarcodeBar(1, $h, 1, $p));
$barcode->addBar(new BarcodeBar(1, 2, 0));
$barcode->addBar(new BarcodeBar(1, $h, true, $p));
$barcode->addBar(new BarcodeBar(1, 2, false));
}
}

if (! $this->kix) {
// stop bar
$barcode->addBar(new BarcodeBar(1, 3, 1));
$barcode->addBar(new BarcodeBar(1, 3, true));
}

return $barcode;
Expand Down
4 changes: 2 additions & 2 deletions src/Types/TypeTelepen.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getBarcode(string $code): Barcode
$drawBar = true;
for ($i = 0; $i < strlen($encoded); ++$i) {
$barWidth = $encoded[$i];
$barcode->addBar(new BarcodeBar($barWidth, 250, $drawBar));
$barcode->addBar(new BarcodeBar(intval($barWidth), 250, $drawBar));
$drawBar = !$drawBar; //flip to other colour
}

Expand Down Expand Up @@ -101,7 +101,7 @@ protected function encodeAlpha($code) : string
$check_digit = 0;
}

$dest .= $this->telepen_lookup_table[ord($check_digit)];
$dest .= $this->telepen_lookup_table[ord(strval($check_digit))];
$dest .= $this->telepen_lookup_table[ord(self::TELEPEN_STOP_CHAR)]; // Stop

return $dest;
Expand Down

0 comments on commit 29756f7

Please sign in to comment.