Skip to content

Commit

Permalink
Merge pull request #240 from sprain/empty-line-before-alternative-sch…
Browse files Browse the repository at this point in the history
…emes

Add empty line before alternative schemes, if needed
  • Loading branch information
sprain committed Nov 16, 2023
2 parents fbb0564 + 207bdda commit eb68c11
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/DataGroup/EmptyElement/EmptyLine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace Sprain\SwissQrBill\DataGroup\EmptyElement;

use Sprain\SwissQrBill\DataGroup\QrCodeableInterface;

/**
* @internal
*/
final class EmptyLine implements QrCodeableInterface
{
public function getQrCodeData(): array
{
return [
null
];
}
}
13 changes: 13 additions & 0 deletions src/QrBill.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Sprain\SwissQrBill\DataGroup\Element\PaymentReference;
use Sprain\SwissQrBill\DataGroup\EmptyElement\EmptyAdditionalInformation;
use Sprain\SwissQrBill\DataGroup\EmptyElement\EmptyAddress;
use Sprain\SwissQrBill\DataGroup\EmptyElement\EmptyLine;
use Sprain\SwissQrBill\DataGroup\QrCodeableInterface;
use Sprain\SwissQrBill\Exception\InvalidQrBillDataException;
use Sprain\SwissQrBill\QrCode\QrCode;
Expand Down Expand Up @@ -189,6 +190,7 @@ private function getQrCodeContent(): string
$this->getUltimateDebtor() ?: new EmptyAddress(),
$this->getPaymentReference(),
$this->getAdditionalInformation() ?: new EmptyAdditionalInformation(),
$this->getPossibleEmptyLine(),
$this->getAlternativeSchemes()
];

Expand All @@ -197,6 +199,17 @@ private function getQrCodeContent(): string
return implode("\n", $qrCodeStringElements);
}

private function getPossibleEmptyLine(): ?EmptyLine
{
if ($this->getAlternativeSchemes()) {
if (null === $this->getAdditionalInformation()?->getBillInformation()) {
return new EmptyLine();
}
}

return null;
}

/**
* @param list<QrCodeableInterface|AddressInterface|list<AddressInterface|QrCodeableInterface>> $elements
* @return list<string|int|null>
Expand Down
Binary file modified tests/TestData/FpdfOutput/qr-alternative-schemes.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-alternative-schemes.print.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/TestData/HtmlOutput/qr-alternative-schemes.svg.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/TestData/QrCodes/TestDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function qrFileProvider(): array
{
return [
[__DIR__ . '/qr-additional-information.png', '5089db74d380d6ece97d02c86cb35e2d'],
[__DIR__ . '/qr-alternative-schemes.png', 'd34aeb0d10da0663a5dfd9df54503e71'],
[__DIR__ . '/qr-alternative-schemes.png', '0ac1061daa0114ba49708a5593471da0'],
[__DIR__ . '/qr-full-set.png', 'b52be79babcc58485ee68fb4f722657c'],
[__DIR__ . '/qr-international-ultimate-debtor.png', 'c56676e8c98f3ba54fac959c450a0995'],
[__DIR__ . '/qr-minimal-setup.png', '72911d0c7d23298aeb14e4960204d6e0'],
Expand All @@ -37,7 +37,7 @@ public function qrFileProvider(): array
[__DIR__ . '/qr-payment-reference-scor.png', '7abd60316b137fa472165faff8e4a28c'],
[__DIR__ . '/qr-ultimate-debtor.png', 'ed279b73f429a8d9960b8dcb94c2c429'],

[__DIR__ . '/proof-of-validation.png', 'a50bc5625703d22da79b46880ff3aef4'],
[__DIR__ . '/proof-of-validation.png', 'f40119eaf7bf58159f9da521e51f9278'],
];
}
}
Binary file modified tests/TestData/QrCodes/proof-of-validation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/TestData/QrCodes/qr-alternative-schemes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/TestData/QrCodes/qr-alternative-schemes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ QRR
123456789012345678901234567

EPD

CC/XRPL/10/bUuK6fwHtfZ3HGAgKvEV7Y5TzHEu8ChUj9
CC/XRPL/10/bUuK6fwHtfZ3HGAgKvEV7Y5TzHEu8ChUj9
Binary file modified tests/TestData/TcPdfOutput/qr-alternative-schemes.svg.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-alternative-schemes.svg.print.pdf
Binary file not shown.

0 comments on commit eb68c11

Please sign in to comment.