diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 0405354..0a16ff9 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,4 +1,4 @@ parameters: paths: - src - level: 4 + level: 5 diff --git a/src/Renderers/PngRenderer.php b/src/Renderers/PngRenderer.php index 2009635..59c8269 100644 --- a/src/Renderers/PngRenderer.php +++ b/src/Renderers/PngRenderer.php @@ -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(); @@ -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) { diff --git a/src/Types/TypeITF14.php b/src/Types/TypeITF14.php index 50f7b2e..7740efa 100644 --- a/src/Types/TypeITF14.php +++ b/src/Types/TypeITF14.php @@ -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; } } @@ -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); } diff --git a/src/Types/TypeIntelligentMailBarcode.php b/src/Types/TypeIntelligentMailBarcode.php index 7d74829..9160e14 100644 --- a/src/Types/TypeIntelligentMailBarcode.php +++ b/src/Types/TypeIntelligentMailBarcode.php @@ -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); @@ -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) { @@ -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); @@ -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; diff --git a/src/Types/TypeInterleaved25Checksum.php b/src/Types/TypeInterleaved25Checksum.php index 0cb9aa6..5871e9b 100644 --- a/src/Types/TypeInterleaved25Checksum.php +++ b/src/Types/TypeInterleaved25Checksum.php @@ -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)); } } diff --git a/src/Types/TypeKix.php b/src/Types/TypeKix.php index 08595a5..de20cf8 100644 --- a/src/Types/TypeKix.php +++ b/src/Types/TypeKix.php @@ -12,5 +12,5 @@ class TypeKix extends TypeRms4cc { - protected $kix = true; + protected bool $kix = true; } diff --git a/src/Types/TypePharmacode.php b/src/Types/TypePharmacode.php index 66a628b..80b3aee 100644 --- a/src/Types/TypePharmacode.php +++ b/src/Types/TypePharmacode.php @@ -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); } } diff --git a/src/Types/TypePharmacodeTwoCode.php b/src/Types/TypePharmacodeTwoCode.php index cde23c0..41de30f 100644 --- a/src/Types/TypePharmacodeTwoCode.php +++ b/src/Types/TypePharmacodeTwoCode.php @@ -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; @@ -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]) { @@ -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)); } } diff --git a/src/Types/TypePostnet.php b/src/Types/TypePostnet.php index a43d093..2d136b3 100644 --- a/src/Types/TypePostnet.php +++ b/src/Types/TypePostnet.php @@ -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; } diff --git a/src/Types/TypeRms4cc.php b/src/Types/TypeRms4cc.php index 8dac3b4..684a624 100644 --- a/src/Types/TypeRms4cc.php +++ b/src/Types/TypeRms4cc.php @@ -15,7 +15,7 @@ class TypeRms4cc implements TypeInterface { - protected $kix = false; + protected bool $kix = false; public function getBarcode(string $code): Barcode { @@ -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) { @@ -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; diff --git a/src/Types/TypeTelepen.php b/src/Types/TypeTelepen.php index 6ec1158..378e342 100644 --- a/src/Types/TypeTelepen.php +++ b/src/Types/TypeTelepen.php @@ -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 } @@ -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;