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 }}
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.
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": {
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
diff --git a/src/BarCode.php b/src/BarCode.php
index b1375c8..4b726bf 100644
--- a/src/BarCode.php
+++ b/src/BarCode.php
@@ -4,38 +4,22 @@
class BarCode
{
- /**
- * @var string
- */
- protected $code;
-
- /**
- * @var string
- */
- protected $type;
-
- public function __construct($code, $type)
+ public function __construct(protected string $code, protected string $type)
{
- $this->code = $code;
- $this->type = $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..1abcc39 100644
--- a/tests/ZbarTest.php
+++ b/tests/ZbarTest.php
@@ -2,6 +2,7 @@
namespace TarfinLabs\ZbarPhp\Tests;
+use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use TarfinLabs\ZbarPhp\Exceptions\InvalidFormat;
use TarfinLabs\ZbarPhp\Exceptions\UnableToOpen;
@@ -10,34 +11,17 @@
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
{
@@ -51,24 +35,24 @@ protected function setUp(): void
$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 +60,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 +69,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 +78,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 +87,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 +96,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 +106,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 +116,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();