Skip to content

Commit

Permalink
Add QR-Code options method
Browse files Browse the repository at this point in the history
  • Loading branch information
Sébastien Despont committed May 14, 2024
1 parent c5e69dd commit 33ab770
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sprain\SwissQrBill\PaymentPart\Output\TcPdfOutput;

use Endroid\QrCode\Writer\SvgWriter;
use setasign\Fpdi\Tcpdf\Fpdi;
use Sprain\SwissQrBill\PaymentPart\Output\AbstractOutput;
use Sprain\SwissQrBill\PaymentPart\Output\Element\FurtherInformation;
Expand Down Expand Up @@ -98,6 +99,11 @@ private function addSwissQrCodeImage(): void
{
$qrCode = $this->getQrCode();

// The compact version uses the <path> element, which increases the size of the output file.
$qrCode->addOptions([

Check failure on line 103 in src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php

View workflow job for this annotation

GitHub Actions / Static code analysis

Parameter #1 $options of method Sprain\SwissQrBill\QrCode\QrCode::addOptions() expects array<string, bool>, array<int|string, bool> given.
SvgWriter::WRITER_OPTION_COMPACT => false

Check failure on line 104 in src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php

View workflow job for this annotation

GitHub Actions / Static code analysis

Access to undefined constant Endroid\QrCode\Writer\SvgWriter::WRITER_OPTION_COMPACT.
]);

$method = match ($this->getQrCodeImageFormat()) {
QrCode::FILE_FORMAT_SVG => 'ImageSVG',
default => 'Image',
Expand Down
13 changes: 12 additions & 1 deletion src/QrCode/QrCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ final class QrCode
private BaseQrCode $qrCode;
private Logo $qrCodeLogo;
private WriterInterface $qrCodeWriter;
/** @var array<string, bool> $options */
private array $options = [SvgWriter::WRITER_OPTION_FORCE_XLINK_HREF => true];

public static function create(string $data, string $fileFormat = null): self
{
Expand Down Expand Up @@ -70,6 +72,15 @@ private function __construct(string $data, string $fileFormat)
$this->setWriterByExtension($fileFormat);
}

/**
* @param array<string, bool> $options
* @return void
*/
public function addOptions(array $options): void
{
$this->options = array_merge($this->options, $options);
}

public function writeFile(string $path): void
{
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
Expand Down Expand Up @@ -124,7 +135,7 @@ private function getQrCodeResult(): ResultInterface
$this->qrCode,
$this->qrCodeLogo,
null,
[SvgWriter::WRITER_OPTION_FORCE_XLINK_HREF => true]
$this->options
);
}
}

0 comments on commit 33ab770

Please sign in to comment.