Skip to content

Commit

Permalink
Requires PHP 8.1+ ; Updated dependencies and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni committed Dec 25, 2024
1 parent 9499e6b commit fc927d4
Show file tree
Hide file tree
Showing 47 changed files with 165 additions and 166 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 }}
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.1
2.4.2
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@
}
],
"require": {
"php": ">=8.0",
"php": ">=8.1",
"ext-bcmath": "*",
"ext-date": "*",
"ext-gd": "*",
"ext-pcre": "*",
"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": {
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ parameters:
paths:
- src
- test
scanDirectories:
excludePaths:
- vendor
ignoreErrors:
reportUnmatchedIgnoredErrors: false
Expand Down
32 changes: 18 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnPhpunitDeprecations="true"
processIsolation="false"
stopOnFailure="false"
verbose="true">
stopOnFailure="false">
<testsuites>
<testsuite name="tc-lib-barcode Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix="php">src</directory>
</whitelist>
</filter>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
<coverage>
<report>
<clover outputFile="target/coverage/coverage.xml"/>
<html outputDirectory="target/coverage" lowUpperBound="50" highLowerBound="90"/>
</report>
</coverage>
<logging>
<log type="coverage-html" target="target/coverage"/>
<log type="coverage-clover" target="target/coverage/coverage.xml"/>
<log type="junit" target="target/logs/junit.xml"/>
<junit outputFile="target/logs/junit.xml"/>
</logging>
</phpunit>
2 changes: 1 addition & 1 deletion resources/debian/compat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9
10
2 changes: 1 addition & 1 deletion resources/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions resources/rpm/rpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 13 additions & 15 deletions src/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -85,8 +85,6 @@ protected function setParameters(): void

/**
* Set the bars array
*
* @throws BarcodeException in case of error
*/
protected function setBars(): void
{
Expand Down Expand Up @@ -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)'
);
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ abstract class Convert
* Array containing the position and dimensions of each barcode bar
* (x, y, width, height)
*
* @var array<array{int, int, int, int}>,
* @var array<array{int, int, int, int}>
*/
protected array $bars = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Type/Linear/Codabar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions src/Type/Linear/CodeNineThree.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Linear/CodeOneOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 2 additions & 4 deletions src/Type/Linear/CodeOneTwoEight.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -174,8 +174,6 @@ protected function processSequenceBA(
* @param array<int, int> $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,
Expand All @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Type/Linear/CodeOneTwoEight/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Linear/CodeThreeNineExtCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Linear/EanEight.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/Type/Linear/EanOneThree.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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]];
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Linear/EanTwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit fc927d4

Please sign in to comment.