diff --git a/.molireali b/.molireali index 96fcbfa..d07dc86 100755 --- a/.molireali +++ b/.molireali @@ -1,7 +1,7 @@ authors composer PetrKnap\\SpaydQr dockerfile php 8.1-cli -docker-scripts petrknap/php-spaydqr +docker-scripts petrknap/php-spayd-qr donation github-workflow docker "composer ci-script" github-workflow linter-docker diff --git a/composer.json b/composer.json index 66b8b33..9646f9e 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "url": "https://petrknap.github.io/donate.html" } ], - "homepage": "https://github.com/petrknap/php-spaydqr", + "homepage": "https://github.com/petrknap/php-spayd-qr", "keywords": [ "spayd", "qrcode", diff --git a/src/QrCodeWriter.php b/src/QrCodeWriter.php new file mode 100644 index 0000000..7670a5a --- /dev/null +++ b/src/QrCodeWriter.php @@ -0,0 +1,29 @@ + new PngWriter(), + self::Svg => new SvgWriter(), + self::WebP => new WebPWriter(), + }; + } +} diff --git a/src/SpaydQr.php b/src/SpaydQr.php index 523fd96..18af039 100755 --- a/src/SpaydQr.php +++ b/src/SpaydQr.php @@ -7,9 +7,7 @@ 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; @@ -17,6 +15,7 @@ /** * @todo make it final + * @todo create SpaydBuilder */ class SpaydQr implements SpaydQrInterface { @@ -35,12 +34,12 @@ protected function __construct( ->add(self::SPAYD_CURRENCY, $money->getCurrency()->getCode()); } - public static function create(string $iban, Money $money, WriterInterface $writer = null): self + public static function create(string $iban, Money $money, QrCodeWriter $writer = QrCodeWriter::Png): self { return new self( new Spayd(), Builder::create() - ->writer($writer ?: new PngWriter()) + ->writer($writer->endroid()) ->encoding(new Encoding('UTF-8')), $iban, $money @@ -87,9 +86,9 @@ public function setInvoice( return $this; } - public function setWriter(WriterInterface $writer): self + public function setWriter(QrCodeWriter $writer): self { - $this->qrCodeBuilder->writer($writer); + $this->qrCodeBuilder->writer($writer->endroid()); return $this; } diff --git a/src/SpaydQrInterface.php b/src/SpaydQrInterface.php index 67b1f20..1b292c6 100755 --- a/src/SpaydQrInterface.php +++ b/src/SpaydQrInterface.php @@ -4,7 +4,6 @@ namespace PetrKnap\SpaydQr; -use Endroid\QrCode\Writer\WriterInterface; use Money\Money; interface SpaydQrInterface @@ -44,10 +43,7 @@ public function setInvoice( ?string $description ): self; - /** - * @todo create own enum of writers - */ - public function setWriter(WriterInterface $writer): self; + public function setWriter(QrCodeWriter $writer): self; public function getContentType(): string; diff --git a/tests/SpaydQrTest.php b/tests/SpaydQrTest.php index dab6d7c..86e959b 100755 --- a/tests/SpaydQrTest.php +++ b/tests/SpaydQrTest.php @@ -32,11 +32,11 @@ public function testFactoryWorks() public function testSetWriterWorks() { - $writer = $this->getMockBuilder(WriterInterface::class)->getMock(); + $writer = QrCodeWriter::Svg; $qrCodeBuilder = $this->getMockBuilder(BuilderInterface::class)->getMock(); $qrCodeBuilder->expects($this->once()) ->method('writer') - ->with($writer) + ->with($writer->endroid()) ->willReturnSelf(); $this->getSpaydQr(null, $qrCodeBuilder)->setWriter($writer); @@ -245,7 +245,7 @@ public function dataWriteFileWorks() public function testEndToEnd() { $spaydQr = $this->getSpaydQr(null, null) - ->setWriter(new SvgWriter()) + ->setWriter(QrCodeWriter::Svg) ->setVariableSymbol(123) ->setInvoice( '1',