Skip to content

Commit b9b3578

Browse files
authored
changed/php84 ready (#19)
1 parent 8a3e43d commit b9b3578

File tree

9 files changed

+57
-53
lines changed

9 files changed

+57
-53
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [2.1.0] - 2025-12-29
10+
11+
### Changed
12+
- Drop PHP 8.1 and prepare for PHP 8.4.
13+
- endroid/qr-code for PHP 8.4+ support.
14+
915
## [2.0.0] - 2024-12-05
1016

1117
### Updated

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ composer test
5757
sh autofix.sh
5858
```
5959

60-
### PHP 7.3
60+
### PHP 8.4
6161

6262
```bash
63-
docker run -it --rm --name php73 -e PHP_EXTENSIONS="gd" -v "$PWD":/usr/src/app thecodingmachine/php:7.3-v4-cli bash
63+
docker run -it --rm --name php84 -e PHP_EXTENSIONS="gd" -v "$PWD":/usr/src/app thecodingmachine/php:8.4-v4-cli bash
6464
```

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^8.1",
19-
"endroid/qr-code": "5.0.9",
18+
"php": "^8.4",
19+
"endroid/qr-code": "^6.0.0",
2020
"ext-gd": "*"
2121
},
2222
"require-dev": {

src/CryptoQr.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace CryptoQr;
1212

13+
use Endroid\QrCode\Writer\Result\ResultInterface;
14+
1315
class CryptoQr extends Qr
1416
{
1517
/**
@@ -38,34 +40,38 @@ protected function getAddressProtocol(): string
3840
public function setLabel(string $label): void
3941
{
4042
$this->label = $label;
41-
$this->updateText();
4243
}
4344

4445
public function setAmount(float $amount): void
4546
{
4647
$this->amount = $amount;
47-
$this->updateText();
4848
}
4949

5050
public function setMessage(string $message): void
5151
{
5252
$this->message = $message;
53-
$this->updateText();
5453
}
5554

56-
protected function updateText(): void
55+
private function buildData(): void
5756
{
5857
$uri = empty($this->getAddressProtocol()) ? '' : $this->getAddressProtocol() . ':';
5958
$uri .= $this->getAddress();
60-
$params = $this->getParam('amount', $this->getAmountString()) .
61-
$this->getParam('label', $this->getLabel()) .
62-
$this->getParam('message', $this->getMessage());
59+
$params = $this->getParam('amount', $this->getAmountString())
60+
. $this->getParam('label', $this->getLabel())
61+
. $this->getParam('message', $this->getMessage());
6362

64-
$this->getQrCode()->setData(
63+
$this->setAddress(
6564
$uri . ($params !== '' ? '?' . substr($params, 1) : '')
6665
);
6766
}
6867

68+
protected function writerResult(): ResultInterface
69+
{
70+
$this->buildData();
71+
72+
return parent::writerResult();
73+
}
74+
6975
private function getParam(string $label, string $value): string
7076
{
7177
return !empty($value) ? '&' . $label . '=' . rawurlencode($value) : '';

src/Qr.php

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717

1818
class Qr
1919
{
20-
/**
21-
* @var string
22-
*/
23-
protected $address = '';
2420
/**
2521
* @var PngWriter
2622
*/
@@ -29,29 +25,18 @@ class Qr
2925
* @var LogoInterface|null
3026
*/
3127
protected $logo;
32-
/**
33-
* @var QrCode
34-
*/
35-
protected $qr_code;
28+
protected ?int $size = 300;
3629

37-
public function __construct(string $address = '')
38-
{
39-
$this->qr_code = new QrCode($address);
30+
public function __construct(
31+
private string $address = ''
32+
) {
4033
$this->setAddress($address);
4134
$this->writer = new PngWriter();
4235
}
4336

4437
public function setAddress(string $address): void
4538
{
4639
$this->address = $address;
47-
$this->updateText();
48-
}
49-
50-
protected function updateText(): void
51-
{
52-
$uri = $this->getAddress();
53-
54-
$this->getQrCode()->setData($uri);
5540
}
5641

5742
public function getAddress(): string
@@ -64,14 +49,20 @@ public function setLogo(LogoInterface $logo): void
6449
$this->logo = $logo;
6550
}
6651

67-
public function getQrCode(): QrCode
52+
public function setSize(int $size): void
6853
{
69-
return $this->qr_code;
54+
$this->size = $size;
7055
}
7156

72-
private function writerResult(): ResultInterface
57+
protected function writerResult(): ResultInterface
7358
{
74-
return $this->writer->write($this->getQrCode(), $this->logo);
59+
return $this->writer->write(
60+
new QrCode(
61+
data: $this->address,
62+
size: $this->size
63+
),
64+
$this->logo
65+
);
7566
}
7667

7768
public function getString(): string

tests/BitcoinQrTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public function testBitcoinQrWithLabel(): void
3939
$pngData = $qr->getString();
4040

4141
$reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB);
42-
$this->assertSame('bitcoin:' . $address .
43-
'?label=Caritas', $reader->text());
42+
$this->assertSame('bitcoin:' . $address
43+
. '?label=Caritas', $reader->text());
4444
}
4545

4646
public function testBitcoinQrWithRequestBtc(): void
@@ -68,8 +68,8 @@ public function testBitcoinQrWithRequestAndMessage(): void
6868

6969
$reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB);
7070
$this->assertSame(
71-
'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY?amount=0.000023456789' .
72-
'&message=Donation%20for%20project%20xyz',
71+
'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY?amount=0.000023456789'
72+
. '&message=Donation%20for%20project%20xyz',
7373
$reader->text()
7474
);
7575
}
@@ -83,8 +83,8 @@ public function testBitcoinQrWithMessage(): void
8383

8484
$reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB);
8585
$this->assertSame(
86-
'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY' .
87-
'?message=Donation%20for%20project%20xyz',
86+
'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'
87+
. '?message=Donation%20for%20project%20xyz',
8888
$reader->text()
8989
);
9090
}

tests/CryptoQrTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function testBitcoinQrWithLabel(): void
4949
$pngData = $qr->getString();
5050

5151
$reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB);
52-
$this->assertSame('bitcoin:' . $address .
53-
'?label=Caritas', $reader->text());
52+
$this->assertSame('bitcoin:' . $address
53+
. '?label=Caritas', $reader->text());
5454
}
5555

5656
public function testBitcoinQrWithRequestBtc(): void
@@ -78,8 +78,8 @@ public function testBitcoinQrWithRequestAndMessage(): void
7878

7979
$reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB);
8080
$this->assertSame(
81-
'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY?amount=0.000023456789' .
82-
'&message=Donation%20for%20project%20xyz',
81+
'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY?amount=0.000023456789'
82+
. '&message=Donation%20for%20project%20xyz',
8383
$reader->text()
8484
);
8585
}
@@ -93,8 +93,8 @@ public function testBitcoinQrWithMessage(): void
9393

9494
$reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB);
9595
$this->assertSame(
96-
'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY' .
97-
'?message=Donation%20for%20project%20xyz',
96+
'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'
97+
. '?message=Donation%20for%20project%20xyz',
9898
$reader->text()
9999
);
100100
}

tests/EthereumQrTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function testEthereumQrWithLabel(): void
3838
$pngData = $qr->getString();
3939

4040
$reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB);
41-
$this->assertSame('ethereum:' . $address .
42-
'?label=Caritas', $reader->text());
41+
$this->assertSame('ethereum:' . $address
42+
. '?label=Caritas', $reader->text());
4343
}
4444

4545
public function testEthereumQrWithRequestEth(): void
@@ -67,8 +67,8 @@ public function testEthereumQrWithRequestAndMessage(): void
6767

6868
$reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB);
6969
$this->assertSame(
70-
'ethereum:0xe8ecDFacE0b274042aAD072149eEc3e232586499?amount=0.000023456789' .
71-
'&message=Donation%20for%20project%20xyz',
70+
'ethereum:0xe8ecDFacE0b274042aAD072149eEc3e232586499?amount=0.000023456789'
71+
. '&message=Donation%20for%20project%20xyz',
7272
$reader->text()
7373
);
7474
}
@@ -82,8 +82,8 @@ public function testEthereumQrWithMessage(): void
8282

8383
$reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB);
8484
$this->assertSame(
85-
'ethereum:0xe8ecDFacE0b274042aAD072149eEc3e232586499' .
86-
'?message=Donation%20for%20project%20xyz',
85+
'ethereum:0xe8ecDFacE0b274042aAD072149eEc3e232586499'
86+
. '?message=Donation%20for%20project%20xyz',
8787
$reader->text()
8888
);
8989
}

tests/QrTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function testSetQrLogo(): void
4343
{
4444
$qr = new Qr('34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY');
4545
$qr->setLogo(new Logo(__DIR__ . '/resources/img/BTC.png'));
46+
$qr->setSize(200);
4647
$pngUri = $qr->getDataUri();
4748

4849
$this->assertNotEmpty($pngUri);

0 commit comments

Comments
 (0)