Skip to content

Commit 5a74873

Browse files
committed
Update supported versions
1 parent 21e888e commit 5a74873

File tree

8 files changed

+45
-16
lines changed

8 files changed

+45
-16
lines changed

.github/workflows/CI.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
php-versions: ['8.2', '8.3', '8.4']
10+
php-versions: ['8.4', '8.5']
1111
fail-fast: false
1212
steps:
13-
- uses: actions/checkout@v4
13+
- uses: actions/checkout@v5
1414
- uses: shivammathur/setup-php@v2
1515
with:
1616
php-version: ${{ matrix.php-versions }}
@@ -54,7 +54,7 @@ jobs:
5454
run: |
5555
composer update --prefer-lowest
5656
vendor/bin/unit-test
57-
vendor/bin/functional-test 5.4
57+
vendor/bin/functional-test 6.4
5858
5959
- name: Archive logs
6060
if: ${{ failure() }}
@@ -64,7 +64,7 @@ jobs:
6464
path: vendor/endroid/quality/application/var/log
6565

6666
- name: Archive code coverage results
67-
uses: actions/upload-artifact@v4
67+
uses: actions/upload-artifact@v5
6868
with:
6969
name: coverage-php-${{ matrix.php-versions }}
7070
path: tests/coverage

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
}
1313
],
1414
"require": {
15-
"php": "^8.2",
15+
"php": "^8.4",
1616
"bacon/bacon-qr-code": "^3.0"
1717
},
1818
"require-dev": {
1919
"ext-gd": "*",
2020
"endroid/quality": "dev-main",
21-
"khanamiryan/qrcode-detector-decoder": "^2.0.2",
21+
"khanamiryan/qrcode-detector-decoder": "^2.0.3",
2222
"setasign/fpdf": "^1.8.2"
2323
},
2424
"suggest": {

src/Bacon/MatrixFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function create(QrCodeInterface $qrCode): MatrixInterface
2323
for ($rowIndex = 0; $rowIndex < $rowCount; ++$rowIndex) {
2424
$blockValues[$rowIndex] = [];
2525
for ($columnIndex = 0; $columnIndex < $columnCount; ++$columnIndex) {
26-
$blockValues[$rowIndex][$columnIndex] = $baconMatrix->get($columnIndex, $rowIndex);
26+
$blockValues[$rowIndex][$columnIndex] = 1 === $baconMatrix->get($columnIndex, $rowIndex) ? 1 : 0;
2727
}
2828
}
2929

src/Color/Color.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
final readonly class Color implements ColorInterface
88
{
99
public function __construct(
10+
/** @var int<0, 255> */
1011
private int $red,
12+
/** @var int<0, 255> */
1113
private int $green,
14+
/** @var int<0, 255> */
1215
private int $blue,
16+
/** @var int<0, 127> */
1317
private int $alpha = 0,
1418
) {
1519
}

src/Color/ColorInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66

77
interface ColorInterface
88
{
9+
/** @return int<0, 255> */
910
public function getRed(): int;
1011

12+
/** @return int<0, 255> */
1113
public function getGreen(): int;
1214

15+
/** @return int<0, 255> */
1316
public function getBlue(): int;
1417

18+
/** @return int<0, 127> */
1519
public function getAlpha(): int;
1620

1721
public function getOpacity(): float;

src/ImageData/LogoImageData.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public static function createForLogo(LogoInterface $logo): self
6363
}
6464

6565
// Only target width specified: calculate height
66-
if (null !== $width && null === $height) {
66+
if (null !== $width) {
6767
return new self($data, $image, $mimeType, $width, intval(imagesy($image) * $width / imagesx($image)), $logo->getPunchoutBackground());
6868
}
6969

7070
// Only target height specified: calculate width
71-
if (null === $width && null !== $height) {
71+
if (null !== $height) {
7272
return new self($data, $image, $mimeType, intval(imagesx($image) * $height / imagesy($image)), $height, $logo->getPunchoutBackground());
7373
}
7474

src/Matrix/Matrix.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
private int $marginLeft;
1616
private int $marginRight;
1717

18-
/** @param array<array<int>> $blockValues */
18+
/** @param array<array<int<0, 1>>> $blockValues */
1919
public function __construct(
2020
private array $blockValues,
2121
int $size,

src/Writer/AbstractGdWriter.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ public function write(QrCodeInterface $qrCode, ?LogoInterface $logo = null, ?Lab
3636
$matrix = $this->getMatrix($qrCode);
3737

3838
$baseBlockSize = RoundBlockSizeMode::None === $qrCode->getRoundBlockSizeMode() ? 10 : intval($matrix->getBlockSize());
39-
$baseImage = imagecreatetruecolor($matrix->getBlockCount() * $baseBlockSize, $matrix->getBlockCount() * $baseBlockSize);
39+
/** @var int<1, max> $baseImageSize */
40+
$baseImageSize = $matrix->getBlockCount() * $baseBlockSize;
41+
$baseImage = imagecreatetruecolor($baseImageSize, $baseImageSize);
4042

4143
if (!$baseImage) {
4244
throw new \Exception('Unable to generate image: please check if the GD extension is enabled and configured correctly');
4345
}
4446

45-
/** @var int $foregroundColor */
4647
$foregroundColor = imagecolorallocatealpha(
4748
$baseImage,
4849
$qrCode->getForegroundColor()->getRed(),
@@ -51,9 +52,16 @@ public function write(QrCodeInterface $qrCode, ?LogoInterface $logo = null, ?Lab
5152
$qrCode->getForegroundColor()->getAlpha()
5253
);
5354

54-
/** @var int $transparentColor */
55+
if (false === $foregroundColor) {
56+
throw new \Exception('Unable to generate image: please check if the GD extension is enabled and configured correctly');
57+
}
58+
5559
$transparentColor = imagecolorallocatealpha($baseImage, 255, 255, 255, 127);
5660

61+
if (false === $transparentColor) {
62+
throw new \Exception('Unable to generate image: please check if the GD extension is enabled and configured correctly');
63+
}
64+
5765
imagefill($baseImage, 0, 0, $transparentColor);
5866

5967
for ($rowIndex = 0; $rowIndex < $matrix->getBlockCount(); ++$rowIndex) {
@@ -71,21 +79,23 @@ public function write(QrCodeInterface $qrCode, ?LogoInterface $logo = null, ?Lab
7179
}
7280
}
7381

82+
/** @var int<1, max> $targetWidth */
7483
$targetWidth = $matrix->getOuterSize();
84+
/** @var int<1, max> $targetHeight */
7585
$targetHeight = $matrix->getOuterSize();
7686

7787
if ($label instanceof LabelInterface) {
7888
$labelImageData = LabelImageData::createForLabel($label);
7989
$targetHeight += $labelImageData->getHeight() + $label->getMargin()->getTop() + $label->getMargin()->getBottom();
8090
}
8191

92+
/** @var int<1, max> $targetHeight */
8293
$targetImage = imagecreatetruecolor($targetWidth, $targetHeight);
8394

8495
if (!$targetImage) {
8596
throw new \Exception('Unable to generate image: please check if the GD extension is enabled and configured correctly');
8697
}
8798

88-
/** @var int $backgroundColor */
8999
$backgroundColor = imagecolorallocatealpha(
90100
$targetImage,
91101
$qrCode->getBackgroundColor()->getRed(),
@@ -94,6 +104,10 @@ public function write(QrCodeInterface $qrCode, ?LogoInterface $logo = null, ?Lab
94104
$qrCode->getBackgroundColor()->getAlpha()
95105
);
96106

107+
if (false === $backgroundColor) {
108+
throw new \Exception('Unable to generate image: please check if the GD extension is enabled and configured correctly');
109+
}
110+
97111
imagefill($targetImage, 0, 0, $backgroundColor);
98112

99113
imagecopyresampled(
@@ -138,8 +152,12 @@ private function addLogo(LogoInterface $logo, GdResult $result): GdResult
138152
$matrix = $result->getMatrix();
139153

140154
if ($logoImageData->getPunchoutBackground()) {
141-
/** @var int $transparent */
142155
$transparent = imagecolorallocatealpha($targetImage, 255, 255, 255, 127);
156+
157+
if (false === $transparent) {
158+
throw new \Exception('Unable to allocate color: please check if the GD extension is enabled and configured correctly');
159+
}
160+
143161
imagealphablending($targetImage, false);
144162
$xOffsetStart = intval($matrix->getOuterSize() / 2 - $logoImageData->getWidth() / 2);
145163
$yOffsetStart = intval($matrix->getOuterSize() / 2 - $logoImageData->getHeight() / 2);
@@ -172,7 +190,6 @@ private function addLabel(LabelInterface $label, GdResult $result): GdResult
172190

173191
$labelImageData = LabelImageData::createForLabel($label);
174192

175-
/** @var int $textColor */
176193
$textColor = imagecolorallocatealpha(
177194
$targetImage,
178195
$label->getTextColor()->getRed(),
@@ -181,6 +198,10 @@ private function addLabel(LabelInterface $label, GdResult $result): GdResult
181198
$label->getTextColor()->getAlpha()
182199
);
183200

201+
if (false === $textColor) {
202+
throw new \Exception('Unable to allocate color: please check if the GD extension is enabled and configured correctly');
203+
}
204+
184205
$x = intval(imagesx($targetImage) / 2 - $labelImageData->getWidth() / 2);
185206
$y = imagesy($targetImage) - $label->getMargin()->getBottom();
186207

0 commit comments

Comments
 (0)