Skip to content

Commit 8f49951

Browse files
authored
Merge pull request #22 from tarfin-labs/php-8.4-support
Php 8.4 support
2 parents 81399de + f508950 commit 8f49951

File tree

10 files changed

+56
-114
lines changed

10 files changed

+56
-114
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: true
1111
matrix:
12-
php: [7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3]
12+
php: [8.2, 8.3, 8.4]
1313
dependency-version: [prefer-lowest, prefer-stable]
1414

1515
name: P${{ matrix.php }} - ${{ matrix.dependency-version }}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to `zbar-php` will be documented in this file
44

55
## Unreleased
66

7+
## 2.0.0 - 2025-08-08
8+
- Dropped support for PHP versions under 8.2
9+
- Added PHP 8.4 support
10+
711
## 1.6.0 - 2023-05-11
812
- PHP 8.2 support added.
913

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
}
1919
],
2020
"require": {
21-
"php": "^7.2|^7.3|^7.4|^8.0|^8.1|^8.2|^8.3",
21+
"php": "^8.2|^8.3|^8.4",
2222
"ext-imagick": "*",
23-
"symfony/process": "^4.4|^5.0|^6.0|^7.0"
23+
"symfony/process": "^7.0"
2424
},
2525
"require-dev": {
26-
"phpunit/phpunit": "^8.5|^9.0|^10.0"
26+
"phpunit/phpunit": "^11.0|^12.0"
2727
},
2828
"autoload": {
2929
"psr-4": {

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
backupStaticProperties="false">
1111
<testsuites>
1212
<testsuite name="Test Suite">
13-
<directory>tests</directory>
13+
<directory suffix="Test.php">./tests</directory>
1414
</testsuite>
1515
</testsuites>
1616
<logging>

src/BarCode.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,22 @@
44

55
class BarCode
66
{
7-
/**
8-
* @var string
9-
*/
10-
protected $code;
11-
12-
/**
13-
* @var string
14-
*/
15-
protected $type;
16-
17-
public function __construct($code, $type)
7+
public function __construct(protected string $code, protected string $type)
188
{
19-
$this->code = $code;
20-
$this->type = $type;
219
}
2210

2311
/**
2412
* Returns the bar code.
25-
*
26-
* @return string
2713
*/
28-
public function code()
14+
public function code(): string
2915
{
3016
return $this->code;
3117
}
3218

3319
/**
3420
* Returns the type of bar code.
35-
*
36-
* @return string
3721
*/
38-
public function type()
22+
public function type(): string
3923
{
4024
return $this->type;
4125
}

src/Exceptions/InvalidFormat.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ class InvalidFormat extends Exception
88
{
99
/**
1010
* Invalid mime type exception.
11-
*
12-
* @param $mimeType
13-
* @return static
1411
*/
15-
public static function invalidMimeType($mimeType)
12+
public static function invalidMimeType(string $mimeType): static
1613
{
1714
return new static("The file type `{$mimeType}` does not valid.");
1815
}

src/Exceptions/UnableToOpen.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ class UnableToOpen extends Exception
88
{
99
/**
1010
* No such file exception.
11-
*
12-
* @param $file
13-
* @return static
1411
*/
15-
public static function noSuchFile($file)
12+
public static function noSuchFile(string $file): static
1613
{
1714
return new static("Unable to open `{$file}`: No such file.");
1815
}

src/Exceptions/ZbarError.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ class ZbarError extends Exception
88
{
99
/**
1010
* Zbar exit status code messages.
11-
*
12-
* @param $code
13-
* @return static
1411
*/
15-
public static function exitStatus($code)
12+
public static function exitStatus(int $code): static
1613
{
1714
$message = '';
1815

src/Zbar.php

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,14 @@
99

1010
class Zbar
1111
{
12-
/**
13-
* @var Process
14-
*/
15-
protected $process;
12+
protected Process $process;
1613

17-
/**
18-
* @var object
19-
*/
20-
protected $output;
14+
protected object $output;
2115

2216
/**
2317
* Supported file formats.
24-
*
25-
* @var array
2618
*/
27-
protected $validFormats = [
19+
protected array $validFormats = [
2820
'application/pdf',
2921
'image/png',
3022
'image/jpeg',
@@ -35,12 +27,10 @@ class Zbar
3527
/**
3628
* Zbar constructor.
3729
*
38-
* @param $image
39-
*
4030
* @throws InvalidFormat
4131
* @throws UnableToOpen
4232
*/
43-
public function __construct($image)
33+
public function __construct(string $image)
4434
{
4535
if (! file_exists($image)) {
4636
throw UnableToOpen::noSuchFile($image);
@@ -58,11 +48,9 @@ public function __construct($image)
5848
/**
5949
* Run process and assign object data to output.
6050
*
61-
* @return object
62-
*
6351
* @throws \TarfinLabs\ZbarPhp\Exceptions\ZbarError
6452
*/
65-
private function runProcess()
53+
private function runProcess(): object
6654
{
6755
if (! empty($this->output)) {
6856
return $this->output;
@@ -80,11 +68,9 @@ private function runProcess()
8068
/**
8169
* Scan bar-code and return value.
8270
*
83-
* @return string
84-
*
8571
* @throws \TarfinLabs\ZbarPhp\Exceptions\ZbarError
8672
*/
87-
public function scan()
73+
public function scan(): string
8874
{
8975
$output = $this->runProcess();
9076

@@ -94,23 +80,19 @@ public function scan()
9480
/**
9581
* Get the bar-code type after scanning it.
9682
*
97-
* @return string
98-
*
9983
* @throws \TarfinLabs\ZbarPhp\Exceptions\ZbarError
10084
*/
101-
public function type()
85+
public function type(): string
10286
{
10387
return $this->decode()->type();
10488
}
10589

10690
/**
10791
* Find both the bar-code and type of the bar-code then returns an object.
10892
*
109-
* @return BarCode
110-
*
11193
* @throws \TarfinLabs\ZbarPhp\Exceptions\ZbarError
11294
*/
113-
public function decode()
95+
public function decode(): BarCode
11496
{
11597
$output = $this->runProcess();
11698
$code = $output->data;
@@ -121,11 +103,8 @@ public function decode()
121103

122104
/**
123105
* Return symbol object.
124-
*
125-
* @param $output
126-
* @return object
127106
*/
128-
private function parse($output)
107+
private function parse(string $output): object
129108
{
130109
$xml = simplexml_load_string($output, 'SimpleXMLElement', LIBXML_NOCDATA);
131110
$encodedOutput = json_encode($xml);

tests/ZbarTest.php

Lines changed: 32 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace TarfinLabs\ZbarPhp\Tests;
44

5+
use PHPUnit\Framework\Attributes\Test;
56
use PHPUnit\Framework\TestCase;
67
use TarfinLabs\ZbarPhp\Exceptions\InvalidFormat;
78
use TarfinLabs\ZbarPhp\Exceptions\UnableToOpen;
@@ -10,34 +11,17 @@
1011

1112
class ZbarTest extends TestCase
1213
{
13-
/**
14-
* @var string
15-
*/
16-
protected $qrcode;
17-
18-
/**
19-
* @var string
20-
*/
21-
protected $barcode;
22-
23-
/**
24-
* @var string
25-
*/
26-
protected $invalidFile;
27-
/**
28-
* @var string
29-
*/
30-
protected $emptyImage;
31-
32-
/**
33-
* @var string
34-
*/
35-
protected $ean13;
36-
37-
/**
38-
* @var string
39-
*/
40-
protected $code128;
14+
protected string $qrcode;
15+
16+
protected string $barcode;
17+
18+
protected string $invalidFile;
19+
20+
protected string $emptyImage;
21+
22+
protected string $ean13;
23+
24+
protected string $code128;
4125

4226
protected function setUp(): void
4327
{
@@ -51,69 +35,69 @@ protected function setUp(): void
5135
$this->code128 = __DIR__.'/files/code-128.png';
5236
}
5337

54-
/** @test */
55-
public function it_will_throw_unable_to_open_exception_when_try_to_scan_non_existing_file()
38+
#[Test]
39+
public function it_will_throw_unable_to_open_exception_when_try_to_scan_non_existing_file(): void
5640
{
5741
$this->expectException(UnableToOpen::class);
5842

5943
new Zbar('nonexisting.png');
6044
}
6145

62-
/** @test */
63-
public function it_will_throw_invalid_format_exception_when_try_to_scan_invalid_file_type()
46+
#[Test]
47+
public function it_will_throw_invalid_format_exception_when_try_to_scan_invalid_file_type(): void
6448
{
6549
$this->expectException(InvalidFormat::class);
6650

6751
new Zbar($this->invalidFile);
6852
}
6953

70-
/** @test */
71-
public function it_can_scan_qrcode()
54+
#[Test]
55+
public function it_can_scan_qrcode(): void
7256
{
7357
$zbar = new Zbar($this->qrcode);
7458
$code = $zbar->scan();
7559

7660
$this->assertSame('tarfin', $code);
7761
}
7862

79-
/** @test */
80-
public function it_will_throw_error_when_try_to_scan_empty_image()
63+
#[Test]
64+
public function it_will_throw_error_when_try_to_scan_empty_image(): void
8165
{
8266
$this->expectException(ZbarError::class);
8367

8468
$zbar = new Zbar($this->emptyImage);
8569
$code = $zbar->scan();
8670
}
8771

88-
/** @test */
89-
public function it_can_scan_barcode()
72+
#[Test]
73+
public function it_can_scan_barcode(): void
9074
{
9175
$zbar = new Zbar($this->barcode);
9276
$code = $zbar->scan();
9377

9478
$this->assertSame('tarfin-1234', $code);
9579
}
9680

97-
/** @test */
98-
public function it_can_get_ean13_bar_code_type()
81+
#[Test]
82+
public function it_can_get_ean13_bar_code_type(): void
9983
{
10084
$zbar = new Zbar($this->ean13);
10185
$type = $zbar->type();
10286

10387
$this->assertSame('EAN-13', $type);
10488
}
10589

106-
/** @test */
107-
public function it_can_get_code128_bar_code_type()
90+
#[Test]
91+
public function it_can_get_code128_bar_code_type(): void
10892
{
10993
$zbar = new ZBar($this->code128);
11094
$type = $zbar->type();
11195

11296
$this->assertSame('CODE-128', $type);
11397
}
11498

115-
/** @test */
116-
public function it_can_get_bar_code_and_type_of_code128_bar_code()
99+
#[Test]
100+
public function it_can_get_bar_code_and_type_of_code128_bar_code(): void
117101
{
118102
$zbar = new ZBar($this->code128);
119103
$barCode = $zbar->decode();
@@ -122,8 +106,8 @@ public function it_can_get_bar_code_and_type_of_code128_bar_code()
122106
$this->assertSame('CODE-128', $barCode->type());
123107
}
124108

125-
/** @test */
126-
public function it_can_get_bar_code_and_type_of_ean13_bar_code()
109+
#[Test]
110+
public function it_can_get_bar_code_and_type_of_ean13_bar_code(): void
127111
{
128112
$zbar = new ZBar($this->ean13);
129113
$barCode = $zbar->decode();
@@ -132,8 +116,8 @@ public function it_can_get_bar_code_and_type_of_ean13_bar_code()
132116
$this->assertSame('EAN-13', $barCode->type());
133117
}
134118

135-
/** @test */
136-
public function it_can_get_bar_code_and_type_of_qrcode()
119+
#[Test]
120+
public function it_can_get_bar_code_and_type_of_qrcode(): void
137121
{
138122
$zbar = new ZBar($this->qrcode);
139123
$barCode = $zbar->decode();

0 commit comments

Comments
 (0)