diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 38cad36..cd4a163 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -23,7 +23,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ["8.0", "8.1", "8.2", "8.3"] + php-version: ["8.1", "8.2", "8.3", "8.4"] experimental: [false] os: [ubuntu-latest] coverage-extension: [xdebug] @@ -50,7 +50,7 @@ jobs: - name: Run all tests run: make qa - name: Send coverage - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v5 with: flags: php-${{ matrix.php-version }}-${{ matrix.os }} name: php-${{ matrix.php-version }}-${{ matrix.os }} diff --git a/Makefile b/Makefile index 239e74c..918b232 100644 --- a/Makefile +++ b/Makefile @@ -169,7 +169,7 @@ endif deps: ensuretarget rm -rf ./vendor/* ($(COMPOSER) install -vvv --no-interaction) - curl --silent --show-error --fail --location --output ./vendor/phpstan.phar https://github.com/phpstan/phpstan/releases/download/1.10.41/phpstan.phar \ + curl --silent --show-error --fail --location --output ./vendor/phpstan.phar https://github.com/phpstan/phpstan/releases/download/2.0.4/phpstan.phar \ && chmod +x ./vendor/phpstan.phar # Generate source code documentation @@ -211,8 +211,8 @@ endif .PHONY: lint lint: ./vendor/bin/phpcs --ignore="./vendor/" --standard=phpcs.xml src test - ./vendor/bin/phpmd src text codesize,unusedcode,naming,design --exclude vendor - ./vendor/bin/phpmd test text unusedcode,naming + ./vendor/bin/phpmd src text codesize,unusedcode,naming,design --exclude */vendor/* + ./vendor/bin/phpmd test text unusedcode,naming,design --exclude */vendor/* php -r 'exit((int)version_compare(PHP_MAJOR_VERSION, "7", ">"));' || ./vendor/phpstan.phar analyse # Run all tests and reports @@ -260,7 +260,7 @@ tag: .PHONY: test test: cp phpunit.xml.dist phpunit.xml - ./vendor/bin/phpunit --migrate-configuration || true + #./vendor/bin/phpunit --migrate-configuration || true XDEBUG_MODE=coverage ./vendor/bin/phpunit --stderr test # Remove all installed files diff --git a/VERSION b/VERSION index 005119b..8e8299d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.4.1 +2.4.2 diff --git a/composer.json b/composer.json index 8cda6d6..280bed8 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,7 @@ } ], "require": { - "php": ">=8.0", + "php": ">=8.1", "ext-bcmath": "*", "ext-date": "*", "ext-gd": "*", @@ -61,10 +61,10 @@ "tecnickcom/tc-lib-color": "^2.2" }, "require-dev": { - "pdepend/pdepend": "2.13.0", - "phpmd/phpmd": "2.13.0", - "phpunit/phpunit": "10.1.2 || 9.6.13", - "squizlabs/php_codesniffer": "3.7.2" + "pdepend/pdepend": "2.16.2", + "phpmd/phpmd": "2.15.0", + "phpunit/phpunit": "11.5.2 || 10.5.40", + "squizlabs/php_codesniffer": "3.11.2" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index bf592ce..86bd47d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,7 +3,7 @@ parameters: paths: - src - test - scanDirectories: + excludePaths: - vendor ignoreErrors: reportUnmatchedIgnoredErrors: false diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a59a4ed..bf99188 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,27 +1,31 @@ + stopOnFailure="false"> ./test - - - src - - + + + src + + + + + + + + - - - + diff --git a/resources/debian/compat b/resources/debian/compat index ec63514..f599e28 100644 --- a/resources/debian/compat +++ b/resources/debian/compat @@ -1 +1 @@ -9 +10 diff --git a/resources/debian/control b/resources/debian/control index 025fbd5..f7c87f6 100644 --- a/resources/debian/control +++ b/resources/debian/control @@ -10,7 +10,7 @@ Vcs-Git: https://github.com/~#VENDOR#~/~#PROJECT#~.git Package: ~#PKGNAME#~ Provides: php-~#PROJECT#~ Architecture: all -Depends: php (>= 8.0.0), php-bcmath, php-date, php-gd, php-tecnickcom-tc-lib-color (<< 3.0.0), php-tecnickcom-tc-lib-color (>= 2.2.6), ${misc:Depends} +Depends: php (>= 8.1.0), php-bcmath, php-date, php-gd, php-tecnickcom-tc-lib-color (<< 3.0.0), php-tecnickcom-tc-lib-color (>= 2.2.7), ${misc:Depends} Description: PHP Barcode library This library includes PHP classes to generate linear and bidimensional barcodes: diff --git a/resources/rpm/rpm.spec b/resources/rpm/rpm.spec index d7d2730..68e0bf2 100644 --- a/resources/rpm/rpm.spec +++ b/resources/rpm/rpm.spec @@ -16,9 +16,9 @@ URL: https://github.com/%{gh_owner}/%{gh_project} BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n) BuildArch: noarch -Requires: php(language) >= 8.0.0 +Requires: php(language) >= 8.1.0 Requires: php-composer(%{c_vendor}/tc-lib-color) < 3.0.0 -Requires: php-composer(%{c_vendor}/tc-lib-color) >= 2.2.6 +Requires: php-composer(%{c_vendor}/tc-lib-color) >= 2.2.7 Requires: php-bcmath Requires: php-date Requires: php-gd diff --git a/src/Type.php b/src/Type.php index deb38f4..6a10d5c 100644 --- a/src/Type.php +++ b/src/Type.php @@ -34,7 +34,7 @@ * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * @link https://github.com/tecnickcom/tc-lib-barcode * - * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) + * @SuppressWarnings("PHPMD.ExcessiveClassComplexity") */ abstract class Type extends \Com\Tecnick\Barcode\Type\Convert implements Model { @@ -85,8 +85,6 @@ protected function setParameters(): void /** * Set the bars array - * - * @throws BarcodeException in case of error */ protected function setBars(): void { @@ -140,7 +138,7 @@ public function setSize( */ protected function setPadding(array $padding): static { - if (! is_array($padding) || (count($padding) != 4)) { + if (count($padding) != 4) { throw new BarcodeException( 'Invalid padding, expecting an array of 4 numbers (top, right, bottom, left)' ); @@ -494,8 +492,8 @@ public function getPngDataImagick(): string */ public function getGd(): \GdImage { - $width = (int) ceil($this->width + $this->padding['L'] + $this->padding['R']); - $height = (int) ceil($this->height + $this->padding['T'] + $this->padding['B']); + $width = max(1, (int) ceil($this->width + $this->padding['L'] + $this->padding['R'])); + $height = max(1, (int) ceil($this->height + $this->padding['T'] + $this->padding['B'])); $img = imagecreate($width, $height); if ($img === false) { throw new BarcodeException('Unable to create GD image'); @@ -506,9 +504,9 @@ public function getGd(): \GdImage $rgbcolor = $bgobj->invertColor()->getNormalizedArray(255); $background_color = imagecolorallocate( $img, - (int) round($rgbcolor['R']), - (int) round($rgbcolor['G']), - (int) round($rgbcolor['B']), + (int) round($rgbcolor['R']), // @phpstan-ignore argument.type + (int) round($rgbcolor['G']), // @phpstan-ignore argument.type + (int) round($rgbcolor['B']), // @phpstan-ignore argument.type ); if ($background_color === false) { throw new BarcodeException('Unable to allocate default GD background color'); @@ -518,9 +516,9 @@ public function getGd(): \GdImage $rgbcolor = $this->bg_color_obj->getNormalizedArray(255); $bg_color = imagecolorallocate( $img, - (int) round($rgbcolor['R']), - (int) round($rgbcolor['G']), - (int) round($rgbcolor['B']), + (int) round($rgbcolor['R']), // @phpstan-ignore argument.type + (int) round($rgbcolor['G']), // @phpstan-ignore argument.type + (int) round($rgbcolor['B']), // @phpstan-ignore argument.type ); if ($bg_color === false) { throw new BarcodeException('Unable to allocate GD background color'); @@ -531,9 +529,9 @@ public function getGd(): \GdImage $rgbcolor = $this->color_obj->getNormalizedArray(255); $bar_color = imagecolorallocate( $img, - (int) round($rgbcolor['R']), - (int) round($rgbcolor['G']), - (int) round($rgbcolor['B']), + (int) round($rgbcolor['R']), // @phpstan-ignore argument.type + (int) round($rgbcolor['G']), // @phpstan-ignore argument.type + (int) round($rgbcolor['B']), // @phpstan-ignore argument.type ); if ($bar_color === false) { throw new BarcodeException('Unable to allocate GD foreground color'); diff --git a/src/Type/Convert.php b/src/Type/Convert.php index 85508ab..617a7c8 100644 --- a/src/Type/Convert.php +++ b/src/Type/Convert.php @@ -79,7 +79,7 @@ abstract class Convert * Array containing the position and dimensions of each barcode bar * (x, y, width, height) * - * @var array, + * @var array */ protected array $bars = []; diff --git a/src/Type/Linear/Codabar.php b/src/Type/Linear/Codabar.php index 5e1c658..9305125 100644 --- a/src/Type/Linear/Codabar.php +++ b/src/Type/Linear/Codabar.php @@ -86,7 +86,7 @@ protected function setBars(): void $this->ncols = 0; $this->nrows = 1; $this->bars = []; - $this::FORMATCode(); + $this->formatCode(); $clen = strlen($this->extcode); for ($chr = 0; $chr < $clen; ++$chr) { $char = $this->extcode[$chr]; diff --git a/src/Type/Linear/CodeNineThree.php b/src/Type/Linear/CodeNineThree.php index e282b18..381967b 100644 --- a/src/Type/Linear/CodeNineThree.php +++ b/src/Type/Linear/CodeNineThree.php @@ -345,14 +345,14 @@ protected function getChecksum(string $code): string * * @throws BarcodeException in case of error * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @SuppressWarnings("PHPMD.ExcessiveMethodLength") */ protected function setBars(): void { $this->ncols = 0; $this->nrows = 1; $this->bars = []; - $this::FORMATCode(); + $this->formatCode(); $clen = strlen($this->extcode); for ($chr = 0; $chr < $clen; ++$chr) { $char = ord($this->extcode[$chr]); diff --git a/src/Type/Linear/CodeOneOne.php b/src/Type/Linear/CodeOneOne.php index 6381807..ce091f3 100644 --- a/src/Type/Linear/CodeOneOne.php +++ b/src/Type/Linear/CodeOneOne.php @@ -131,7 +131,7 @@ protected function setBars(): void $this->ncols = 0; $this->nrows = 1; $this->bars = []; - $this::FORMATCode(); + $this->formatCode(); $clen = strlen($this->extcode); for ($chr = 0; $chr < $clen; ++$chr) { $char = $this->extcode[$chr]; diff --git a/src/Type/Linear/CodeOneTwoEight.php b/src/Type/Linear/CodeOneTwoEight.php index f3896b8..3bfbc42 100644 --- a/src/Type/Linear/CodeOneTwoEight.php +++ b/src/Type/Linear/CodeOneTwoEight.php @@ -88,7 +88,7 @@ protected function processSequenceA( // single character shift $code_data[] = 98; // mark shift - $sequence[$key][3] = true; + $sequence[$key][3] = ''; } elseif (! isset($sequence[($key - 1)][3])) { $code_data[] = 101; } @@ -174,8 +174,6 @@ protected function processSequenceBA( * @param array $code_data Array of codepoints to alter * @param int $key Sequence current key * @param array{string, string, int} $seq Sequence current value - * - * @throws BarcodeException in case of error */ protected function processSequenceBB( array &$sequence, @@ -192,7 +190,7 @@ protected function processSequenceBB( // single character shift $code_data[] = 98; // mark shift - $sequence[$key][3] = true; + $sequence[$key][3] = ''; } elseif (! isset($sequence[($key - 1)][3])) { $code_data[] = 100; } diff --git a/src/Type/Linear/CodeOneTwoEight/Process.php b/src/Type/Linear/CodeOneTwoEight/Process.php index 8fe6001..df96623 100644 --- a/src/Type/Linear/CodeOneTwoEight/Process.php +++ b/src/Type/Linear/CodeOneTwoEight/Process.php @@ -326,7 +326,8 @@ protected function getCodeDataA( if (($char_id >= 241) && ($char_id <= 244)) { $code_data[] = $this::FNC_A[$char_id]; } elseif ($char_id <= 95) { - $code_data[] = strpos($this::KEYS_A, $char); + $cdpos = strpos($this::KEYS_A, $char); + $code_data[] = is_int($cdpos) ? $cdpos : 0; } else { throw new BarcodeException('Invalid character sequence'); } @@ -353,7 +354,8 @@ protected function getCodeDataB( if (($char_id >= 241) && ($char_id <= 244)) { $code_data[] = $this::FNC_B[$char_id]; } elseif (($char_id >= 32) && ($char_id <= 127)) { - $code_data[] = strpos($this::KEYS_B, $char); + $cdpos = strpos($this::KEYS_B, $char); + $code_data[] = is_int($cdpos) ? $cdpos : 0; } else { throw new BarcodeException('Invalid character sequence: ' . $char_id); } diff --git a/src/Type/Linear/CodeThreeNineExtCheck.php b/src/Type/Linear/CodeThreeNineExtCheck.php index f6729db..f2e8861 100644 --- a/src/Type/Linear/CodeThreeNineExtCheck.php +++ b/src/Type/Linear/CodeThreeNineExtCheck.php @@ -342,7 +342,7 @@ protected function setBars(): void $this->ncols = 0; $this->nrows = 1; $this->bars = []; - $this::FORMATCode(); + $this->formatCode(); $clen = strlen($this->extcode); for ($chr = 0; $chr < $clen; ++$chr) { $char = $this->extcode[$chr]; diff --git a/src/Type/Linear/EanEight.php b/src/Type/Linear/EanEight.php index 41797d1..d7fc405 100644 --- a/src/Type/Linear/EanEight.php +++ b/src/Type/Linear/EanEight.php @@ -53,7 +53,7 @@ class EanEight extends \Com\Tecnick\Barcode\Type\Linear\EanOneThree */ protected function setBars(): void { - $this::FORMATCode(); + $this->formatCode(); $seq = '101'; // left guard bar $half_len = (int) ceil($this->code_length / 2); for ($pos = 0; $pos < $half_len; ++$pos) { diff --git a/src/Type/Linear/EanOneThree.php b/src/Type/Linear/EanOneThree.php index 0e01ff3..28b88fa 100644 --- a/src/Type/Linear/EanOneThree.php +++ b/src/Type/Linear/EanOneThree.php @@ -131,7 +131,7 @@ protected function getChecksum(string $code): int $code_len = strlen($code); $sum_a = 0; for ($pos = 1; $pos < $data_len; $pos += 2) { - $sum_a += $code[$pos]; + $sum_a += (int) $code[$pos]; } if ($this->code_length > 12) { @@ -140,7 +140,7 @@ protected function getChecksum(string $code): int $sum_b = 0; for ($pos = 0; $pos < $data_len; $pos += 2) { - $sum_b += ($code[$pos]); + $sum_b += (int) ($code[$pos]); } if ($this->code_length < 13) { @@ -185,7 +185,7 @@ protected function setBars(): void throw new BarcodeException('Input code must be a number'); } - $this::FORMATCode(); + $this->formatCode(); $seq = '101'; // left guard bar $half_len = (int) ceil($this->code_length / 2); $parity = $this::PARITIES[$this->extcode[0]]; diff --git a/src/Type/Linear/EanTwo.php b/src/Type/Linear/EanTwo.php index 6f8e082..c2b1c0f 100644 --- a/src/Type/Linear/EanTwo.php +++ b/src/Type/Linear/EanTwo.php @@ -119,7 +119,7 @@ protected function formatCode(): void */ protected function setBars(): void { - $this::FORMATCode(); + $this->formatCode(); $chk = $this->getChecksum($this->extcode); $parity = $this::PARITIES[$chk]; $seq = '1011'; // left guard bar diff --git a/src/Type/Linear/Imb.php b/src/Type/Linear/Imb.php index a77384e..406427d 100644 --- a/src/Type/Linear/Imb.php +++ b/src/Type/Linear/Imb.php @@ -453,7 +453,7 @@ protected function getTables(int $type, int $size): array /** * Get the routing code binary block * - * @param string $routing_code the routing code + * @param numeric-string $routing_code the routing code * * @throws BarcodeException in case of error */ @@ -485,13 +485,13 @@ protected function getCharsArray(): array $tracking_number = $code_arr[0]; $binary_code = '0'; if (isset($code_arr[1])) { - $binary_code = $this->getRoutingCode($code_arr[1]); + $binary_code = $this->getRoutingCode($code_arr[1]); // @phpstan-ignore argument.type } - $binary_code = bcmul($binary_code, '10'); - $binary_code = bcadd($binary_code, $tracking_number[0]); - $binary_code = bcmul($binary_code, '5'); - $binary_code = bcadd($binary_code, $tracking_number[1]); + $binary_code = bcmul($binary_code, '10'); // @phpstan-ignore argument.type + $binary_code = bcadd($binary_code, $tracking_number[0]); // @phpstan-ignore argument.type + $binary_code = bcmul($binary_code, '5'); // @phpstan-ignore argument.type + $binary_code = bcadd($binary_code, $tracking_number[1]); // @phpstan-ignore argument.type $binary_code .= substr($tracking_number, 2, 18); // convert to hexadecimal $binary_code = $this->convertDecToHex($binary_code); @@ -504,7 +504,7 @@ protected function getCharsArray(): array // calculate frame check sequence $fcs = $this->getFrameCheckSequence($binary_code_arr); // exclude first 2 bits from first byte - $first_byte = sprintf('%2s', dechex((hexdec($binary_code_arr[0]) << 2) >> 2)); + $first_byte = sprintf('%2s', dechex((int) (hexdec($binary_code_arr[0]) << 2) >> 2)); $binary_code_102bit = $first_byte . substr($binary_code, 2); // convert binary data to codewords $codewords = []; diff --git a/src/Type/Linear/InterleavedTwoOfFiveCheck.php b/src/Type/Linear/InterleavedTwoOfFiveCheck.php index 0d09b43..11b19ac 100644 --- a/src/Type/Linear/InterleavedTwoOfFiveCheck.php +++ b/src/Type/Linear/InterleavedTwoOfFiveCheck.php @@ -76,7 +76,7 @@ protected function formatCode(): void */ protected function setBars(): void { - $this::FORMATCode(); + $this->formatCode(); if (strlen($this->extcode) % 2 != 0) { // add leading zero if code-length is odd $this->extcode = '0' . $this->extcode; diff --git a/src/Type/Linear/MsiCheck.php b/src/Type/Linear/MsiCheck.php index e5d03cd..19c737c 100644 --- a/src/Type/Linear/MsiCheck.php +++ b/src/Type/Linear/MsiCheck.php @@ -113,7 +113,7 @@ protected function formatCode(): void */ protected function setBars(): void { - $this::FORMATCode(); + $this->formatCode(); $seq = '110'; // left guard $clen = strlen($this->extcode); for ($pos = 0; $pos < $clen; ++$pos) { diff --git a/src/Type/Linear/Postnet.php b/src/Type/Linear/Postnet.php index 5cbb9ea..fcfc591 100644 --- a/src/Type/Linear/Postnet.php +++ b/src/Type/Linear/Postnet.php @@ -104,7 +104,7 @@ protected function setBars(): void $this->ncols = 0; $this->nrows = 2; $this->bars = []; - $this::FORMATCode(); + $this->formatCode(); $clen = strlen($this->extcode); // start bar $this->bars[] = [$this->ncols, 0, 1, 2]; diff --git a/src/Type/Linear/RoyalMailFourCc.php b/src/Type/Linear/RoyalMailFourCc.php index 736604c..ee7c4c4 100644 --- a/src/Type/Linear/RoyalMailFourCc.php +++ b/src/Type/Linear/RoyalMailFourCc.php @@ -175,7 +175,7 @@ protected function formatCode(): void */ protected function getCoreBars(): void { - $this::FORMATCode(); + $this->formatCode(); $clen = strlen($this->extcode); for ($chr = 0; $chr < $clen; ++$chr) { $char = $this->extcode[$chr]; diff --git a/src/Type/Linear/StandardTwoOfFiveCheck.php b/src/Type/Linear/StandardTwoOfFiveCheck.php index e36434d..4517959 100644 --- a/src/Type/Linear/StandardTwoOfFiveCheck.php +++ b/src/Type/Linear/StandardTwoOfFiveCheck.php @@ -102,7 +102,7 @@ protected function formatCode(): void */ protected function setBars(): void { - $this::FORMATCode(); + $this->formatCode(); if (strlen($this->extcode) % 2 != 0) { // add leading zero if code-length is odd $this->extcode = '0' . $this->extcode; diff --git a/src/Type/Linear/UpcE.php b/src/Type/Linear/UpcE.php index 4bf7b2e..ec77830 100644 --- a/src/Type/Linear/UpcE.php +++ b/src/Type/Linear/UpcE.php @@ -156,7 +156,7 @@ protected function formatCode(): void */ protected function setBars(): void { - $this::FORMATCode(); + $this->formatCode(); $upce_code = $this->convertUpcaToUpce($this->extcode); $seq = '101'; // left guard bar $parity = $this::PARITIES_UPCE[$this->extcode[1]][$this->check]; diff --git a/src/Type/Square/Aztec.php b/src/Type/Square/Aztec.php index c357aa4..3303081 100644 --- a/src/Type/Square/Aztec.php +++ b/src/Type/Square/Aztec.php @@ -76,8 +76,8 @@ class Aztec extends \Com\Tecnick\Barcode\Type\Square * 3: LAYERS : Custom number of layers (0 = auto). * 4: ECI : Extended Channel Interpretation (ECI) code. Use -1 for FNC1. See $this->eci. * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) + * @SuppressWarnings("PHPMD.CyclomaticComplexity") + * @SuppressWarnings("PHPMD.NPathComplexity") */ protected function setParameters(): void { diff --git a/src/Type/Square/Aztec/Bitstream.php b/src/Type/Square/Aztec/Bitstream.php index 68d5e23..d243160 100644 --- a/src/Type/Square/Aztec/Bitstream.php +++ b/src/Type/Square/Aztec/Bitstream.php @@ -31,7 +31,7 @@ * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * @link https://github.com/tecnickcom/tc-lib-barcode * - * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) + * @SuppressWarnings("PHPMD.ExcessiveClassComplexity") */ abstract class Bitstream extends \Com\Tecnick\Barcode\Type\Square\Aztec\Layers { @@ -56,17 +56,17 @@ protected function highLevelEncoding( $chars = array_values($chrarr); $chrlen = count($chars); if ($hint == 'B') { - $this->binaryEncode($chars, $chrlen); + $this->binaryEncode($chars, $chrlen); // @phpstan-ignore argument.type return; } - $this->autoEncode($chars, $chrlen); + $this->autoEncode($chars, $chrlen); // @phpstan-ignore argument.type } /** * Forced binary encoding for the given characters. * - * @param array $chars Integer ASCII values of the characters to encode. + * @param array $chars Integer ASCII values of the characters to encode. * @param int $chrlen Lenght of the $chars array. */ protected function binaryEncode(array $chars, int $chrlen): void @@ -107,7 +107,7 @@ protected function binaryEncode(array $chars, int $chrlen): void /** * Automatic encoding for the given characters. * - * @param array $chars Integer ASCII values of the characters to encode. + * @param array $chars Integer ASCII values of the characters to encode. * @param int $chrlen Lenght of the $chars array. */ protected function autoEncode(array $chars, int $chrlen): void @@ -129,7 +129,7 @@ protected function autoEncode(array $chars, int $chrlen): void /** * Process mode characters. * - * @param array $chars The array of characters. + * @param array $chars The array of characters. * @param int $idx The current character index. * @param int $chrlen The total number of characters to process. */ @@ -158,7 +158,7 @@ protected function processModeChars(array &$chars, int &$idx, int $chrlen): void /** * Count consecutive characters in the same mode. * - * @param array $chars The array of characters. + * @param array $chars The array of characters. * @param int $idx The current character index. * @param int $chrlen The total number of characters to process. * @param int $mode The current mode. @@ -192,7 +192,7 @@ protected function countModeChars( /** * Process consecutive binary characters. * - * @param array $chars The array of characters. + * @param array $chars The array of characters. * @param int $idx The current character index. * @param int $chrlen The total number of characters to process. * @@ -247,11 +247,11 @@ protected function processBinaryChars( /** * Count consecutive binary characters. * - * @param array $chars The array of characters. + * @param array $chars The array of characters. * @param int $idx The current character index. * @param int $chrlen The total number of characters to process. * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings("PHPMD.CyclomaticComplexity") */ protected function countBinaryChars( array &$chars, @@ -278,13 +278,13 @@ protected function countBinaryChars( /** * Process consecutive special Punctuation Pairs. * - * @param array $chars The array of characters. + * @param array $chars The array of characters. * @param int $idx The current character index. * @param int $chrlen The total number of characters to process. * * @return bool True if pair characters have been found and processed. * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings("PHPMD.CyclomaticComplexity") */ protected function processPunctPairs( array &$chars, @@ -334,7 +334,7 @@ protected function processPunctPairs( /** * Count consecutive special Punctuation Pairs. * - * @param array $chars The array of characters. + * @param array $chars The array of characters. * @param int $idx The current character index. * @param int $chrlen The total number of characters to process. */ @@ -364,7 +364,7 @@ protected function countPunctPairs( * Counts the number of consecutive charcters that are in both PUNCT or DIGIT modes. * Returns the array with the codewords. * - * @param array &$chars The string to count the characters in. + * @param array &$chars The string to count the characters in. * @param int $idx The starting index to count from. * @param int $chrlen The length of the string to count. * diff --git a/src/Type/Square/Aztec/Data.php b/src/Type/Square/Aztec/Data.php index 37d858c..91e0fb2 100644 --- a/src/Type/Square/Aztec/Data.php +++ b/src/Type/Square/Aztec/Data.php @@ -90,7 +90,7 @@ class Data /** * Code character encoding for each mode. * - * @var array> + * @var array> */ public const CHAR_ENC = [ // MODE_UPPER (initial mode) @@ -238,7 +238,7 @@ class Data * - the carriage return '\r' character (13) that maps for modes 3,4. * - the comma ',' and dot '.' characters (44,46) that map for modes 2,4. * - * @var array + * @var array */ public const CHAR_MODES = [ 1 => 3, // '^A' (SOH) diff --git a/src/Type/Square/Aztec/Encode.php b/src/Type/Square/Aztec/Encode.php index 60e0006..72d2ec7 100644 --- a/src/Type/Square/Aztec/Encode.php +++ b/src/Type/Square/Aztec/Encode.php @@ -36,7 +36,7 @@ class Encode extends \Com\Tecnick\Barcode\Type\Square\Aztec\Bitstream /** * Bidimensional grid containing the encoded data. * - * @var array> + * @var array> */ protected array $grid = []; @@ -77,7 +77,7 @@ public function __construct( /** * Returns the bidimensional grid containing the encoded data. * - * @return array> + * @return array> */ public function getGrid(): array { @@ -200,8 +200,8 @@ protected function setGrid(): void * * @param int $numcdw Number of data codewords. * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) + * @SuppressWarnings("PHPMD.CyclomaticComplexity") + * @SuppressWarnings("PHPMD.NPathComplexity") */ protected function drawMode(int $numcdw): void { diff --git a/src/Type/Square/Aztec/ErrorCorrection.php b/src/Type/Square/Aztec/ErrorCorrection.php index 50fb5e4..0eecca1 100644 --- a/src/Type/Square/Aztec/ErrorCorrection.php +++ b/src/Type/Square/Aztec/ErrorCorrection.php @@ -34,7 +34,7 @@ class ErrorCorrection /** * Galois Field primitive by word size. * - * @var array + * @var array */ protected const GF = [ 4 => 19, // 10011 GF(16) (x^4 + x + 1) Mode message @@ -48,7 +48,7 @@ class ErrorCorrection * Map the log and exp (inverse log) tables by word size. * NOTE: It is equal to 2^word_size. * - * @var array + * @var array */ protected const TSIZE = [ 4 => 16, @@ -61,14 +61,14 @@ class ErrorCorrection /** * Log table. * - * @var array + * @var array */ protected array $tlog = []; /** * Exponential (inverse log) table. * - * @var array + * @var array */ protected array $texp = []; @@ -90,15 +90,15 @@ public function __construct(int $wsize) /** * Returns the Reed-Solomon Error Correction Codewords added to the input data. * - * @param array $data Array of data codewords to process. + * @param array $data Array of data codewords to process. * @param int $necc Number of error correction bytes. * - * @return array + * @return array */ public function checkwords(array $data, int $necc): array { $coeff = $this->getCoefficients($data, $necc); - return array_pad($coeff, -$necc, 0); + return array_pad($coeff, -$necc, 0); // @phpstan-ignore return.type } /** @@ -131,10 +131,10 @@ protected function genTables(int $wsize): void /** * Calculates the coefficients of the error correction polynomial. * - * @param array $data Array of data codewords to process. + * @param array $data Array of data codewords to process. * @param int $necc Number of error correction bytes. * - * @return array Array of coefficients. + * @return array Array of coefficients. */ protected function getCoefficients(array $data, int $necc): array { @@ -159,10 +159,10 @@ protected function getCoefficients(array $data, int $necc): array /** * Returns the product of two coefficient arrays. * - * @param array $acf First array of coefficients. - * @param array $bcf Second array of coefficients. + * @param array $acf First array of coefficients. + * @param array $bcf Second array of coefficients. * - * @return array Array of coefficients. + * @return array Array of coefficients. */ protected function multiplyCoeff(array $acf, array $bcf): array { @@ -196,9 +196,9 @@ protected function multiply(int $aval, int $bval): int /** * Left-trim coefficients array. * - * @param array $coeff Array of coefficients. + * @param array $coeff Array of coefficients. * - * @return array Array of coefficients. + * @return array Array of coefficients. */ protected function trimCoefficients(array $coeff): array { @@ -212,11 +212,11 @@ protected function trimCoefficients(array $coeff): array /** * Returns the product of a polynomial by a monomial. * - * @param array $coeff Array of polynomial coefficients. + * @param array $coeff Array of polynomial coefficients. * @param int $mon Monomial. * @param int $deg Degree of the monomial. * - * @return array Array of coefficients. + * @return array Array of coefficients. */ protected function multiplyByMonomial(array $coeff, int $mon, int $deg): array { @@ -235,10 +235,10 @@ protected function multiplyByMonomial(array $coeff, int $mon, int $deg): array /** * Adds or subtracts two coefficient arrays. * - * @param array $smaller The smaller array of coefficients. - * @param array $larger The larger array of coefficients. + * @param array $smaller The smaller array of coefficients. + * @param array $larger The larger array of coefficients. * - * @return array Array of coefficients. + * @return array Array of coefficients. */ protected function addOrSubtract(array $smaller, array $larger): array { diff --git a/src/Type/Square/Datamatrix.php b/src/Type/Square/Datamatrix.php index ef7bba8..1953372 100644 --- a/src/Type/Square/Datamatrix.php +++ b/src/Type/Square/Datamatrix.php @@ -226,7 +226,7 @@ protected function setGrid( * * @return array Codewords * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings("PHPMD.CyclomaticComplexity") */ protected function getHighLevelEncoding(string $data): array { diff --git a/src/Type/Square/Datamatrix/EncodeTxt.php b/src/Type/Square/Datamatrix/EncodeTxt.php index b0d3553..83eea8d 100644 --- a/src/Type/Square/Datamatrix/EncodeTxt.php +++ b/src/Type/Square/Datamatrix/EncodeTxt.php @@ -76,7 +76,7 @@ public function encodeTXTC40shift( * @param array $temp_cw Temporary codewords array * @param int $ptr Pointer * @param int $epos End position - * @param array $charset Charset array + * @param array $charset Charset array * * @return int Curent character code */ diff --git a/src/Type/Square/Datamatrix/Steps.php b/src/Type/Square/Datamatrix/Steps.php index a87610a..7bfc4d3 100644 --- a/src/Type/Square/Datamatrix/Steps.php +++ b/src/Type/Square/Datamatrix/Steps.php @@ -81,7 +81,7 @@ public function lookAheadTest(string $data, int $pos, int $mode): int /** * Step K * - * @param array $numch Number of characters + * @param array $numch Number of characters * * @return int encoding mode */ @@ -154,7 +154,7 @@ protected function stepK(array $numch): int * Step L * * @param int $chr Character code - * @param array $numch Number of characters + * @param array $numch Number of characters */ protected function stepL(int $chr, array &$numch): void { @@ -173,7 +173,7 @@ protected function stepL(int $chr, array &$numch): void * Step M * * @param int $chr Character code - * @param array $numch Number of characters + * @param array $numch Number of characters */ protected function stepM(int $chr, array &$numch): void { @@ -190,7 +190,7 @@ protected function stepM(int $chr, array &$numch): void * Step N * * @param int $chr Character code - * @param array $numch Number of characters + * @param array $numch Number of characters */ protected function stepN(int $chr, array &$numch): void { @@ -207,7 +207,7 @@ protected function stepN(int $chr, array &$numch): void * Step O * * @param int $chr Character code - * @param array $numch Number of characters + * @param array $numch Number of characters */ protected function stepO(int $chr, array &$numch): void { @@ -224,7 +224,7 @@ protected function stepO(int $chr, array &$numch): void * Step P * * @param int $chr Character code - * @param array $numch Number of characters + * @param array $numch Number of characters */ protected function stepP(int $chr, array &$numch): void { @@ -241,7 +241,7 @@ protected function stepP(int $chr, array &$numch): void * Step Q * * @param int $chr Character code - * @param array $numch Number of characters + * @param array $numch Number of characters */ protected function stepQ(int $chr, array &$numch): void { @@ -255,7 +255,7 @@ protected function stepQ(int $chr, array &$numch): void /** * Step R-f * - * @param array $numch Number of characters + * @param array $numch Number of characters * @param int $pos Current position * @param int $data_length Data length * @param int $charscount Number of processed characters @@ -307,7 +307,7 @@ protected function stepRf( /** * Step R * - * @param array $numch Number of characters + * @param array $numch Number of characters * @param int $pos Current position * @param int $data_length Data length * @param int $charscount Number of processed characters diff --git a/src/Type/Square/PdfFourOneSeven.php b/src/Type/Square/PdfFourOneSeven.php index 5afb3f6..67f9c56 100644 --- a/src/Type/Square/PdfFourOneSeven.php +++ b/src/Type/Square/PdfFourOneSeven.php @@ -129,7 +129,7 @@ protected function setParameters(): void /** * Set macro block parameter * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings("PHPMD.CyclomaticComplexity") */ protected function setMacroBlockParam(): void { @@ -264,8 +264,14 @@ public function getCodewords( $errsize = (2 << $ecl); // calculate number of columns (number of codewords per row) and rows $nce = ($numcw + $errsize + 1); - $cols = min(30, max(1, round((sqrt(4761 + (68 * $this->aspectratio * $this->row_height * $nce)) - 69) / 34))); - $rows = min(90, max(3, ceil($nce / $cols))); + $cols = (int) min( + 30, + max(1, round((sqrt(4761 + (68 * $this->aspectratio * $this->row_height * $nce)) - 69) / 34)) + ); + $rows = (int) min( + 90, + max(3, ceil($nce / $cols)) + ); $size = ($cols * $rows); if ($size > 928) { // set dimensions to get maximum capacity diff --git a/src/Type/Square/PdfFourOneSeven/Compaction.php b/src/Type/Square/PdfFourOneSeven/Compaction.php index d7a7c13..2307cfe 100644 --- a/src/Type/Square/PdfFourOneSeven/Compaction.php +++ b/src/Type/Square/PdfFourOneSeven/Compaction.php @@ -149,10 +149,10 @@ protected function processByteCompaction(string $code, array &$codewords): void } // append the result array at the end - $codewords = array_merge($codewords, $cw6); + $codewords = array_merge($codewords, $cw6); //@phpstan-ignore parameterByRef.type } else { for ($idx = 0; $idx < $sublen; ++$idx) { - $codewords[] = ord($code[$idx]); + $codewords[] = ord($code[$idx]); //@phpstan-ignore parameterByRef.type } } diff --git a/src/Type/Square/PdfFourOneSeven/Data.php b/src/Type/Square/PdfFourOneSeven/Data.php index 59456de..5be4247 100644 --- a/src/Type/Square/PdfFourOneSeven/Data.php +++ b/src/Type/Square/PdfFourOneSeven/Data.php @@ -29,7 +29,7 @@ * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * @link https://github.com/tecnickcom/tc-lib-barcode * - * @SuppressWarnings(PHPMD.ExcessiveClassLength) + * @SuppressWarnings("PHPMD.ExcessiveClassLength") */ abstract class Data { diff --git a/src/Type/Square/QrCode.php b/src/Type/Square/QrCode.php index 43ac773..dfea82f 100644 --- a/src/Type/Square/QrCode.php +++ b/src/Type/Square/QrCode.php @@ -100,8 +100,8 @@ class QrCode extends \Com\Tecnick\Barcode\Type\Square * 6: BEST MASK - true to find the best mask (slow) * 7: DEFAULT MASK - mask to use when the best mask option is false * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) + * @SuppressWarnings("PHPMD.CyclomaticComplexity") + * @SuppressWarnings("PHPMD.NPathComplexity") */ protected function setParameters(): void { diff --git a/src/Type/Square/QrCode/EncodingMode.php b/src/Type/Square/QrCode/EncodingMode.php index 95a3d06..9532902 100644 --- a/src/Type/Square/QrCode/EncodingMode.php +++ b/src/Type/Square/QrCode/EncodingMode.php @@ -114,7 +114,7 @@ public function isAlphanumericAt(string $str, int $pos): bool */ protected function appendBitstream(array $bitstream, array $append): array { - if ((! is_array($append)) || (count($append) == 0)) { + if (count($append) == 0) { return $bitstream; } diff --git a/src/Type/Square/QrCode/Mask.php b/src/Type/Square/QrCode/Mask.php index bec570e..e1451a4 100644 --- a/src/Type/Square/QrCode/Mask.php +++ b/src/Type/Square/QrCode/Mask.php @@ -132,6 +132,7 @@ protected function makeMask( int $maskNo, int $level ): array { + $mask = []; $this->makeMaskNo($maskNo, $width, $frame, $mask); $this->writeFormatInformation($width, $mask, $maskNo, $level); return $mask; diff --git a/src/Type/Square/QrCode/SpecRs.php b/src/Type/Square/QrCode/SpecRs.php index 8146612..232ac77 100644 --- a/src/Type/Square/QrCode/SpecRs.php +++ b/src/Type/Square/QrCode/SpecRs.php @@ -27,7 +27,7 @@ * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * @link https://github.com/tecnickcom/tc-lib-barcode * - * @SuppressWarnings(PHPMD.TooManyPublicMethods) + * @SuppressWarnings("PHPMD.TooManyPublicMethods") */ abstract class SpecRs { diff --git a/test/Square/AztecTest.php b/test/Square/AztecTest.php index f4cdb58..97acb48 100644 --- a/test/Square/AztecTest.php +++ b/test/Square/AztecTest.php @@ -17,6 +17,7 @@ namespace Test\Square; use Test\TestUtil; +use PHPUnit\Framework\Attributes\DataProvider; /** * AZTEC Barcode class test @@ -51,9 +52,7 @@ public function testCapacityException(): void $barcode->getBarcodeObj('AZTEC,100,B,F,3', $code); } - /** - * @dataProvider getGridDataProvider - */ + #[DataProvider('getGridDataProvider')] public function testGetGrid(string $options, string $code, mixed $expected): void { $barcode = $this->getTestObject(); @@ -220,14 +219,12 @@ public static function getGridDataProvider(): array ]; } - /** - * @dataProvider getStringDataProvider - */ + #[DataProvider('getStringDataProvider')] public function testStrings(string $code): void { $barcode = $this->getTestObject(); $type = $barcode->getBarcodeObj('AZTEC,50,B,F', $code); - $this->assertNotNull($type); + $this->assertNotNull($type); // @phpstan-ignore method.alreadyNarrowedType } /** diff --git a/test/Square/DatamatrixTest.php b/test/Square/DatamatrixTest.php index 34777a5..8073eee 100644 --- a/test/Square/DatamatrixTest.php +++ b/test/Square/DatamatrixTest.php @@ -17,6 +17,7 @@ namespace Test\Square; use Test\TestUtil; +use PHPUnit\Framework\Attributes\DataProvider; /** * Datamatrix Barcode class test @@ -75,9 +76,7 @@ public function testEncodeTXTC40Exception(): void $encode->encodeTXTC40($data, $enc, $temp_cw, $ptr, $epos, $charset); } - /** - * @dataProvider getGridDataProvider - */ + #[DataProvider('getGridDataProvider')] public function testGetGrid(string $mode, string $code, mixed $expected): void { $barcode = $this->getTestObject(); @@ -430,14 +429,12 @@ public static function getGridDataProvider(): array ]; } - /** - * @dataProvider getStringDataProvider - */ + #[DataProvider('getStringDataProvider')] public function testStrings(string $code): void { $barcode = $this->getTestObject(); $type = $barcode->getBarcodeObj('DATAMATRIX', $code); - $this->assertNotNull($type); + $this->assertNotNull($type); // @phpstan-ignore method.alreadyNarrowedType } /** diff --git a/test/Square/PdfFourOneSevenTest.php b/test/Square/PdfFourOneSevenTest.php index 88ad338..c4180b2 100644 --- a/test/Square/PdfFourOneSevenTest.php +++ b/test/Square/PdfFourOneSevenTest.php @@ -17,6 +17,7 @@ namespace Test\Square; use Test\TestUtil; +use PHPUnit\Framework\Attributes\DataProvider; /** * PDF417 Barcode class test @@ -51,9 +52,7 @@ public function testCapacityException(): void $barcode->getBarcodeObj('PDF417', $code); } - /** - * @dataProvider getGridDataProvider - */ + #[DataProvider('getGridDataProvider')] public function testGetGrid(string $options, string $code, mixed $expected): void { $barcode = $this->getTestObject(); @@ -251,14 +250,12 @@ public static function getGridDataProvider(): array ]; } - /** - * @dataProvider getStringDataProvider - */ + #[DataProvider('getStringDataProvider')] public function testStrings(string $code): void { $barcode = $this->getTestObject(); $type = $barcode->getBarcodeObj('PDF417', $code); - $this->assertNotNull($type); + $this->assertNotNull($type); // @phpstan-ignore method.alreadyNarrowedType } /** diff --git a/test/Square/QrCodeTest.php b/test/Square/QrCodeTest.php index 0dec48e..93af29b 100644 --- a/test/Square/QrCodeTest.php +++ b/test/Square/QrCodeTest.php @@ -17,6 +17,7 @@ namespace Test\Square; use Test\TestUtil; +use PHPUnit\Framework\Attributes\DataProvider; /** * QR-Code Barcode class test @@ -51,9 +52,7 @@ public function testCapacityException(): void $barcode->getBarcodeObj('QRCODE', $code); } - /** - * @dataProvider getGridDataProvider - */ + #[DataProvider('getGridDataProvider')] public function testGetGrid(string $options, string $code, mixed $expected): void { $barcode = $this->getTestObject(); @@ -349,14 +348,12 @@ public static function getGridDataProvider(): array ]; } - /** - * @dataProvider getStringDataProvider - */ + #[DataProvider('getStringDataProvider')] public function testStrings(string $code): void { $barcode = $this->getTestObject(); $type = $barcode->getBarcodeObj('QRCODE,H,NL,0,1,3,1', $code); - $this->assertNotNull($type); + $this->assertNotNull($type); // @phpstan-ignore method.alreadyNarrowedType } /** diff --git a/test/TestUtil.php b/test/TestUtil.php index 65aa3ef..b97c685 100644 --- a/test/TestUtil.php +++ b/test/TestUtil.php @@ -28,6 +28,8 @@ * @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * @link https://github.com/tecnickcom/tc-lib-barcode + * + * @SuppressWarnings("PHPMD.NumberOfChildren") */ class TestUtil extends TestCase {