Skip to content

Commit

Permalink
Merge pull request #23 from petrknap/revert-v3
Browse files Browse the repository at this point in the history
Reverted to v3
  • Loading branch information
petrknap authored Jun 4, 2024
2 parents 5cd3d38 + 92c40dd commit b1accf4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 38 deletions.
29 changes: 0 additions & 29 deletions src/QrCodeWriter.php

This file was deleted.

12 changes: 7 additions & 5 deletions src/SpaydQr.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Builder\BuilderInterface;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\Writer\PngWriter;
use Endroid\QrCode\Writer\Result\ResultInterface;
use Endroid\QrCode\Writer\WriterInterface;
use Money\Currencies\ISOCurrencies;
use Money\Formatter\DecimalMoneyFormatter;
use Money\Money;
Expand All @@ -34,13 +36,13 @@ protected function __construct(
->add(self::SPAYD_CURRENCY, $money->getCurrency()->getCode());
}

public static function create(string $iban, Money $money, QrCodeWriter $writer = QrCodeWriter::Png): self
public static function create(string $iban, Money $money, WriterInterface $writer = null): self
{
return new self(
new Spayd(),
Builder::create()
->writer($writer->endroid())
->encoding(new Encoding('UTF-8')),
->writer($writer ?: new PngWriter())
->encoding(new Encoding('UTF-8')),
$iban,
$money
);
Expand Down Expand Up @@ -151,9 +153,9 @@ public function setInvoice(
return $this;
}

public function setWriter(QrCodeWriter $writer): self
public function setWriter(WriterInterface $writer): self
{
$this->qrCodeBuilder->writer($writer->endroid());
$this->qrCodeBuilder->writer($writer);

return $this;
}
Expand Down
3 changes: 2 additions & 1 deletion src/SpaydQrInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace PetrKnap\SpaydQr;

use Endroid\QrCode\Builder\BuilderInterface;
use Endroid\QrCode\Writer\WriterInterface;
use Money\Money;
use Sunfox\Spayd\Spayd;

Expand Down Expand Up @@ -139,7 +140,7 @@ public function setInvoice(
?string $description
): self;

public function setWriter(QrCodeWriter $writer): self;
public function setWriter(WriterInterface $writer): self;

public function getContentType(): string;

Expand Down
6 changes: 3 additions & 3 deletions tests/SpaydQrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public function testFactoryWorks()

public function testSetWriterWorks()
{
$writer = QrCodeWriter::Svg;
$writer = new SvgWriter();
$qrCodeBuilder = $this->getMockBuilder(BuilderInterface::class)->getMock();
$qrCodeBuilder->expects($this->once())
->method('writer')
->with($writer->endroid())
->with($writer)
->willReturnSelf();

$this->getSpaydQr(null, $qrCodeBuilder)->setWriter($writer);
Expand Down Expand Up @@ -245,7 +245,7 @@ public function dataWriteFileWorks()
public function testEndToEnd()
{
$spaydQr = $this->getSpaydQr(null, null)
->setWriter(QrCodeWriter::Svg)
->setWriter(new SvgWriter())
->setVariableSymbol(123)
->setInvoice(
'1',
Expand Down

0 comments on commit b1accf4

Please sign in to comment.