Skip to content

Commit

Permalink
Switch to QR code provider (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage authored Sep 27, 2021
1 parent 318b605 commit 4587cc8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
"require": {
"php": "^7.3|^8.0",
"ext-mbstring": "*",
"rikudou/qr-payment-interface": "^1.0"
"rikudou/qr-payment-interface": "^1.0",
"rikudou/qr-payment-qr-code-provider": "^1.0"
},
"autoload": {
"psr-4": {
"rikudou\\EuQrPayment\\": "src/"
}
},
"suggest": {
"endroid/qr-code": "^3.2"
"endroid/qr-code": "For generating QR code image"
},
"require-dev": {
"phpoffice/phpspreadsheet": "^1.5",
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- '#Attribute class JetBrains.+? does not exist#'
21 changes: 19 additions & 2 deletions src/QrPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DateTimeInterface;
use Endroid\QrCode\QrCode;
use JetBrains\PhpStorm\Deprecated;
use rikudou\EuQrPayment\Config\Configuration;
use rikudou\EuQrPayment\Config\ConfigurationInterface;
use rikudou\EuQrPayment\Exceptions\InvalidIbanException;
Expand All @@ -14,9 +15,14 @@
use rikudou\EuQrPayment\Iban\IbanInterface;
use rikudou\EuQrPayment\Sepa\CharacterSet;
use Rikudou\QrPayment\QrPaymentInterface;
use Rikudou\QrPaymentQrCodeProvider\EndroidQrCode3;
use Rikudou\QrPaymentQrCodeProvider\Exception\NoProviderFoundException;
use Rikudou\QrPaymentQrCodeProvider\GetQrCodeTrait;

final class QrPayment implements QrPaymentInterface
{
use GetQrCodeTrait;

/**
* @var IbanInterface
*/
Expand Down Expand Up @@ -375,13 +381,24 @@ public function getQrString(): string
*
* @return \Endroid\QrCode\QrCode
*/
#[Deprecated('This method has been deprecated, please use getQrCode()', '%class%->getQrCode()->getRawObject()')]
public function getQrImage(): QrCode
{
if (!class_exists("Endroid\QrCode\QrCode")) {
try {
$code = $this->getQrCode();
if (!$code instanceof EndroidQrCode3) {
throw new \LogicException('Error: library endroid/qr-code is not loaded or is not a 3.x version. For newer versions please use method getQrCode()');
}
// @codeCoverageIgnoreStart
} catch (NoProviderFoundException $e) {
throw new \LogicException('Error: library endroid/qr-code is not loaded.');
// @codeCoverageIgnoreEnd
}

return new QrCode($this->getQrString());
$raw = $code->getRawObject();
assert($raw instanceof QrCode);

return $raw;
}

/**
Expand Down
17 changes: 0 additions & 17 deletions tests/QrPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,23 +332,6 @@ public function testSetCurrency()
$this->getDefaultPayment()->setCurrency('EURO');
}

public function testGetQrImageFailure()
{
$this->expectException(LogicException::class);
$payment = $this->getDefaultPayment();

$this->unregisterAutoloader();

try {
$payment
->setBeneficiaryName('My company')
->getQrImage();
} catch (Throwable $exception) {
$this->reregisterAutoloader();
throw $exception;
}
}

public function testGetQrImage()
{
$this->reregisterAutoloader();
Expand Down

0 comments on commit 4587cc8

Please sign in to comment.