From f32b40f447d03274e846af6a5bc0b89e6e39e691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Turan=20Karatu=C4=9F?= Date: Fri, 8 Aug 2025 11:44:46 +0300 Subject: [PATCH 1/6] chore: update PHP version requirements in `composer.json` * Changed PHP requirement from `^7.2|^7.3|^7.4|^8.0|^8.1|^8.2|^8.3` to `^8.2|^8.3|^8.4` * Updated PHPUnit version requirement from `^8.5|^9.0|^10.0` to `^11.0|^12.0` * Ensures compatibility with newer PHP and PHPUnit versions --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index a1bb4fc..c982e04 100644 --- a/composer.json +++ b/composer.json @@ -18,12 +18,12 @@ } ], "require": { - "php": "^7.2|^7.3|^7.4|^8.0|^8.1|^8.2|^8.3", + "php": "^8.2|^8.3|^8.4", "ext-imagick": "*", - "symfony/process": "^4.4|^5.0|^6.0|^7.0" + "symfony/process": "^7.0" }, "require-dev": { - "phpunit/phpunit": "^8.5|^9.0|^10.0" + "phpunit/phpunit": "^11.0|^12.0" }, "autoload": { "psr-4": { From e3d7163490d93f870f6e28681cc7828bccbf5324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Turan=20Karatu=C4=9F?= Date: Fri, 8 Aug 2025 11:44:58 +0300 Subject: [PATCH 2/6] refactor: Correct directory suffix for test suite in `phpunit.xml.dist` * Updated the `` tag to include `suffix="Test.php"` for better test discovery. --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0b25dc6..cef8ef3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,7 +10,7 @@ backupStaticProperties="false"> - tests + ./tests From d44e18736e35d3c73325facda82bc520d3e34e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Turan=20Karatu=C4=9F?= Date: Fri, 8 Aug 2025 11:45:19 +0300 Subject: [PATCH 3/6] refactor: improve type hinting and constructor syntax in `BarCode`, `InvalidFormat`, `UnableToOpen`, and `Zbar` classes * Simplified constructor syntax using property promotion. * Added type hints for method parameters and return types. * Enhanced code readability and maintainability. --- src/BarCode.php | 24 ++------- src/Exceptions/InvalidFormat.php | 5 +- src/Exceptions/UnableToOpen.php | 5 +- src/Exceptions/ZbarError.php | 5 +- src/Zbar.php | 39 ++++---------- tests/ZbarTest.php | 93 ++++++++++++++------------------ 6 files changed, 54 insertions(+), 117 deletions(-) diff --git a/src/BarCode.php b/src/BarCode.php index b1375c8..5d377dc 100644 --- a/src/BarCode.php +++ b/src/BarCode.php @@ -4,38 +4,20 @@ class BarCode { - /** - * @var string - */ - protected $code; - - /** - * @var string - */ - protected $type; - - public function __construct($code, $type) - { - $this->code = $code; - $this->type = $type; - } + public function __construct(protected string $code, protected string $type) {} /** * Returns the bar code. - * - * @return string */ - public function code() + public function code(): string { return $this->code; } /** * Returns the type of bar code. - * - * @return string */ - public function type() + public function type(): string { return $this->type; } diff --git a/src/Exceptions/InvalidFormat.php b/src/Exceptions/InvalidFormat.php index 18e3519..cb1e230 100644 --- a/src/Exceptions/InvalidFormat.php +++ b/src/Exceptions/InvalidFormat.php @@ -8,11 +8,8 @@ class InvalidFormat extends Exception { /** * Invalid mime type exception. - * - * @param $mimeType - * @return static */ - public static function invalidMimeType($mimeType) + public static function invalidMimeType(string $mimeType): static { return new static("The file type `{$mimeType}` does not valid."); } diff --git a/src/Exceptions/UnableToOpen.php b/src/Exceptions/UnableToOpen.php index 7c467c8..753d9ca 100644 --- a/src/Exceptions/UnableToOpen.php +++ b/src/Exceptions/UnableToOpen.php @@ -8,11 +8,8 @@ class UnableToOpen extends Exception { /** * No such file exception. - * - * @param $file - * @return static */ - public static function noSuchFile($file) + public static function noSuchFile(string $file): static { return new static("Unable to open `{$file}`: No such file."); } diff --git a/src/Exceptions/ZbarError.php b/src/Exceptions/ZbarError.php index 1be860d..a32a663 100644 --- a/src/Exceptions/ZbarError.php +++ b/src/Exceptions/ZbarError.php @@ -8,11 +8,8 @@ class ZbarError extends Exception { /** * Zbar exit status code messages. - * - * @param $code - * @return static */ - public static function exitStatus($code) + public static function exitStatus(int $code): static { $message = ''; diff --git a/src/Zbar.php b/src/Zbar.php index 1de115e..8476f3b 100644 --- a/src/Zbar.php +++ b/src/Zbar.php @@ -9,22 +9,14 @@ class Zbar { - /** - * @var Process - */ - protected $process; + protected Process $process; - /** - * @var object - */ - protected $output; + protected object $output; /** * Supported file formats. - * - * @var array */ - protected $validFormats = [ + protected array $validFormats = [ 'application/pdf', 'image/png', 'image/jpeg', @@ -35,12 +27,10 @@ class Zbar /** * Zbar constructor. * - * @param $image - * * @throws InvalidFormat * @throws UnableToOpen */ - public function __construct($image) + public function __construct(string $image) { if (! file_exists($image)) { throw UnableToOpen::noSuchFile($image); @@ -58,11 +48,9 @@ public function __construct($image) /** * Run process and assign object data to output. * - * @return object - * * @throws \TarfinLabs\ZbarPhp\Exceptions\ZbarError */ - private function runProcess() + private function runProcess(): object { if (! empty($this->output)) { return $this->output; @@ -80,11 +68,9 @@ private function runProcess() /** * Scan bar-code and return value. * - * @return string - * * @throws \TarfinLabs\ZbarPhp\Exceptions\ZbarError */ - public function scan() + public function scan(): string { $output = $this->runProcess(); @@ -94,11 +80,9 @@ public function scan() /** * Get the bar-code type after scanning it. * - * @return string - * * @throws \TarfinLabs\ZbarPhp\Exceptions\ZbarError */ - public function type() + public function type(): string { return $this->decode()->type(); } @@ -106,11 +90,9 @@ public function type() /** * Find both the bar-code and type of the bar-code then returns an object. * - * @return BarCode - * * @throws \TarfinLabs\ZbarPhp\Exceptions\ZbarError */ - public function decode() + public function decode(): BarCode { $output = $this->runProcess(); $code = $output->data; @@ -121,11 +103,8 @@ public function decode() /** * Return symbol object. - * - * @param $output - * @return object */ - private function parse($output) + private function parse(string $output): object { $xml = simplexml_load_string($output, 'SimpleXMLElement', LIBXML_NOCDATA); $encodedOutput = json_encode($xml); diff --git a/tests/ZbarTest.php b/tests/ZbarTest.php index 1ef0bb7..4af07c7 100644 --- a/tests/ZbarTest.php +++ b/tests/ZbarTest.php @@ -3,72 +3,57 @@ namespace TarfinLabs\ZbarPhp\Tests; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Attributes\Test; use TarfinLabs\ZbarPhp\Exceptions\InvalidFormat; use TarfinLabs\ZbarPhp\Exceptions\UnableToOpen; use TarfinLabs\ZbarPhp\Exceptions\ZbarError; use TarfinLabs\ZbarPhp\Zbar; + class ZbarTest extends TestCase { - /** - * @var string - */ - protected $qrcode; - - /** - * @var string - */ - protected $barcode; - - /** - * @var string - */ - protected $invalidFile; - /** - * @var string - */ - protected $emptyImage; - - /** - * @var string - */ - protected $ean13; - - /** - * @var string - */ - protected $code128; + protected string $qrcode; + + protected string $barcode; + + protected string $invalidFile; + + protected string $emptyImage; + + protected string $ean13; + + protected string $code128; protected function setUp(): void { parent::setUp(); - $this->qrcode = __DIR__.'/files/qrcode.png'; - $this->barcode = __DIR__.'/files/barcode.gif'; - $this->invalidFile = __DIR__.'/files/qrcode.txt'; - $this->emptyImage = __DIR__.'/files/empty.png'; - $this->ean13 = __DIR__.'/files/ean-13.jpg'; - $this->code128 = __DIR__.'/files/code-128.png'; + $this->qrcode = __DIR__ . '/files/qrcode.png'; + $this->barcode = __DIR__ . '/files/barcode.gif'; + $this->invalidFile = __DIR__ . '/files/qrcode.txt'; + $this->emptyImage = __DIR__ . '/files/empty.png'; + $this->ean13 = __DIR__ . '/files/ean-13.jpg'; + $this->code128 = __DIR__ . '/files/code-128.png'; } - /** @test */ - public function it_will_throw_unable_to_open_exception_when_try_to_scan_non_existing_file() + #[Test] + public function it_will_throw_unable_to_open_exception_when_try_to_scan_non_existing_file(): void { $this->expectException(UnableToOpen::class); new Zbar('nonexisting.png'); } - /** @test */ - public function it_will_throw_invalid_format_exception_when_try_to_scan_invalid_file_type() + #[Test] + public function it_will_throw_invalid_format_exception_when_try_to_scan_invalid_file_type(): void { $this->expectException(InvalidFormat::class); new Zbar($this->invalidFile); } - /** @test */ - public function it_can_scan_qrcode() + #[Test] + public function it_can_scan_qrcode(): void { $zbar = new Zbar($this->qrcode); $code = $zbar->scan(); @@ -76,8 +61,8 @@ public function it_can_scan_qrcode() $this->assertSame('tarfin', $code); } - /** @test */ - public function it_will_throw_error_when_try_to_scan_empty_image() + #[Test] + public function it_will_throw_error_when_try_to_scan_empty_image(): void { $this->expectException(ZbarError::class); @@ -85,8 +70,8 @@ public function it_will_throw_error_when_try_to_scan_empty_image() $code = $zbar->scan(); } - /** @test */ - public function it_can_scan_barcode() + #[Test] + public function it_can_scan_barcode(): void { $zbar = new Zbar($this->barcode); $code = $zbar->scan(); @@ -94,8 +79,8 @@ public function it_can_scan_barcode() $this->assertSame('tarfin-1234', $code); } - /** @test */ - public function it_can_get_ean13_bar_code_type() + #[Test] + public function it_can_get_ean13_bar_code_type(): void { $zbar = new Zbar($this->ean13); $type = $zbar->type(); @@ -103,8 +88,8 @@ public function it_can_get_ean13_bar_code_type() $this->assertSame('EAN-13', $type); } - /** @test */ - public function it_can_get_code128_bar_code_type() + #[Test] + public function it_can_get_code128_bar_code_type(): void { $zbar = new ZBar($this->code128); $type = $zbar->type(); @@ -112,8 +97,8 @@ public function it_can_get_code128_bar_code_type() $this->assertSame('CODE-128', $type); } - /** @test */ - public function it_can_get_bar_code_and_type_of_code128_bar_code() + #[Test] + public function it_can_get_bar_code_and_type_of_code128_bar_code(): void { $zbar = new ZBar($this->code128); $barCode = $zbar->decode(); @@ -122,8 +107,8 @@ public function it_can_get_bar_code_and_type_of_code128_bar_code() $this->assertSame('CODE-128', $barCode->type()); } - /** @test */ - public function it_can_get_bar_code_and_type_of_ean13_bar_code() + #[Test] + public function it_can_get_bar_code_and_type_of_ean13_bar_code(): void { $zbar = new ZBar($this->ean13); $barCode = $zbar->decode(); @@ -132,8 +117,8 @@ public function it_can_get_bar_code_and_type_of_ean13_bar_code() $this->assertSame('EAN-13', $barCode->type()); } - /** @test */ - public function it_can_get_bar_code_and_type_of_qrcode() + #[Test] + public function it_can_get_bar_code_and_type_of_qrcode(): void { $zbar = new ZBar($this->qrcode); $barCode = $zbar->decode(); From dc42047d753d6667e1f1dc2e2c5dab49aa183acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Turan=20Karatu=C4=9F?= Date: Fri, 8 Aug 2025 11:45:31 +0300 Subject: [PATCH 4/6] chore: update `CHANGELOG.md` for version 2.0.0 * Dropped support for PHP versions under 8.2 * Added PHP 8.4 support --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0633413..adeba9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to `zbar-php` will be documented in this file ## Unreleased +## 2.0.0 - 2025-08-08 +- Dropped support for PHP versions under 8.2 +- Added PHP 8.4 support + ## 1.6.0 - 2023-05-11 - PHP 8.2 support added. From 875838de1a1ca31bc4bfcf3db6e6dc5ccd5364fa Mon Sep 17 00:00:00 2001 From: Faruk Can Date: Fri, 8 Aug 2025 11:46:05 +0300 Subject: [PATCH 5/6] Apply fixes from StyleCI (#21) --- src/BarCode.php | 4 +++- tests/ZbarTest.php | 15 +++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/BarCode.php b/src/BarCode.php index 5d377dc..4b726bf 100644 --- a/src/BarCode.php +++ b/src/BarCode.php @@ -4,7 +4,9 @@ class BarCode { - public function __construct(protected string $code, protected string $type) {} + public function __construct(protected string $code, protected string $type) + { + } /** * Returns the bar code. diff --git a/tests/ZbarTest.php b/tests/ZbarTest.php index 4af07c7..1abcc39 100644 --- a/tests/ZbarTest.php +++ b/tests/ZbarTest.php @@ -2,14 +2,13 @@ namespace TarfinLabs\ZbarPhp\Tests; -use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\TestCase; use TarfinLabs\ZbarPhp\Exceptions\InvalidFormat; use TarfinLabs\ZbarPhp\Exceptions\UnableToOpen; use TarfinLabs\ZbarPhp\Exceptions\ZbarError; use TarfinLabs\ZbarPhp\Zbar; - class ZbarTest extends TestCase { protected string $qrcode; @@ -28,12 +27,12 @@ protected function setUp(): void { parent::setUp(); - $this->qrcode = __DIR__ . '/files/qrcode.png'; - $this->barcode = __DIR__ . '/files/barcode.gif'; - $this->invalidFile = __DIR__ . '/files/qrcode.txt'; - $this->emptyImage = __DIR__ . '/files/empty.png'; - $this->ean13 = __DIR__ . '/files/ean-13.jpg'; - $this->code128 = __DIR__ . '/files/code-128.png'; + $this->qrcode = __DIR__.'/files/qrcode.png'; + $this->barcode = __DIR__.'/files/barcode.gif'; + $this->invalidFile = __DIR__.'/files/qrcode.txt'; + $this->emptyImage = __DIR__.'/files/empty.png'; + $this->ean13 = __DIR__.'/files/ean-13.jpg'; + $this->code128 = __DIR__.'/files/code-128.png'; } #[Test] From 5d735f6609471069c9188bac01f48bb8944c6076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Turan=20Karatu=C4=9F?= Date: Fri, 8 Aug 2025 11:48:28 +0300 Subject: [PATCH 6/6] refactor: update PHP version matrix in GitHub Actions workflow * Reduced PHP version matrix to [8.2, 8.3, 8.4] for testing. * This change aligns the testing environment with supported PHP versions. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dda3b8a..81029cb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: true matrix: - php: [7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3] + php: [8.2, 8.3, 8.4] dependency-version: [prefer-lowest, prefer-stable] name: P${{ matrix.php }} - ${{ matrix.dependency-version }}