Skip to content

Commit

Permalink
Add support for Endroid 5
Browse files Browse the repository at this point in the history
  • Loading branch information
sprain committed Oct 4, 2023
1 parent 2820c82 commit 3e14033
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"symfony/validator": "^4.4|^5.0|^6.0",
"symfony/intl": "^4.4|^5.0|^6.0",
"kmukku/php-iso11649": "^1.5",
"endroid/qr-code": "^4.4.4",
"endroid/qr-code": "^4.4.4|^5.0",
"symfony/polyfill-intl-icu": "^1.23"
},
"require-dev": {
Expand Down
20 changes: 10 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 19 additions & 8 deletions src/QrCode/QrCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Sprain\SwissQrBill\QrCode;

use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelMedium;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\Logo\Logo;
use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeEnlarge;
use Endroid\QrCode\QrCode as BaseQrCode;
use Endroid\QrCode\RoundBlockSizeMode;
use Endroid\QrCode\Writer\PngWriter;
use Endroid\QrCode\Writer\Result\ResultInterface;
use Endroid\QrCode\Writer\SvgWriter;
Expand Down Expand Up @@ -42,12 +42,23 @@ public static function create(string $data, string $fileFormat = null): self

private function __construct(string $data, string $fileFormat)
{
$this->qrCode = BaseQrCode::create($data)
->setEncoding(new Encoding('UTF-8'))
->setErrorCorrectionLevel(new ErrorCorrectionLevelMedium())
->setSize(self::PX_QR_CODE)
->setMargin(0)
->setRoundBlockSizeMode(new RoundBlockSizeModeEnlarge());
if (class_exists(ErrorCorrectionLevel\ErrorCorrectionLevelMedium::class)) {
// Endroid 4.x
$this->qrCode = BaseQrCode::create($data)
->setEncoding(new Encoding('UTF-8'))
->setErrorCorrectionLevel(new ErrorCorrectionLevel\ErrorCorrectionLevelMedium())

Check failure on line 49 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable

Parameter #1 $errorCorrectionLevel of method Endroid\QrCode\QrCode::setErrorCorrectionLevel() expects Endroid\QrCode\ErrorCorrectionLevel, Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelMedium given.

Check failure on line 49 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable

Parameter #1 $errorCorrectionLevel of method Endroid\QrCode\QrCode::setErrorCorrectionLevel() expects Endroid\QrCode\ErrorCorrectionLevel, Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelMedium given.
->setSize(self::PX_QR_CODE)
->setMargin(0)
->setRoundBlockSizeMode(new RoundBlockSizeMode\RoundBlockSizeModeEnlarge());

Check failure on line 52 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable

Instantiated class Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeEnlarge not found.

Check failure on line 52 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable

Parameter #1 $roundBlockSizeMode of method Endroid\QrCode\QrCode::setRoundBlockSizeMode() expects Endroid\QrCode\RoundBlockSizeMode, Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeEnlarge given.

Check failure on line 52 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable

Instantiated class Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeEnlarge not found.

Check failure on line 52 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable

Parameter #1 $roundBlockSizeMode of method Endroid\QrCode\QrCode::setRoundBlockSizeMode() expects Endroid\QrCode\RoundBlockSizeMode, Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeEnlarge given.
} else {
// Endroid 5.x
$this->qrCode = BaseQrCode::create($data)
->setEncoding(new Encoding('UTF-8'))
->setErrorCorrectionLevel(ErrorCorrectionLevel::Medium)

Check failure on line 57 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 - prefer-lowest

Access to constant Medium on an unknown class Endroid\QrCode\ErrorCorrectionLevel.

Check failure on line 57 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest

Access to constant Medium on an unknown class Endroid\QrCode\ErrorCorrectionLevel.

Check failure on line 57 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-lowest

Access to constant Medium on an unknown class Endroid\QrCode\ErrorCorrectionLevel.

Check failure on line 57 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest

Access to constant Medium on an unknown class Endroid\QrCode\ErrorCorrectionLevel.
->setSize(self::PX_QR_CODE)
->setMargin(0)
->setRoundBlockSizeMode(RoundBlockSizeMode::Enlarge);

Check failure on line 60 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 - prefer-lowest

Access to constant Enlarge on an unknown class Endroid\QrCode\RoundBlockSizeMode.

Check failure on line 60 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest

Access to constant Enlarge on an unknown class Endroid\QrCode\RoundBlockSizeMode.

Check failure on line 60 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-lowest

Access to constant Enlarge on an unknown class Endroid\QrCode\RoundBlockSizeMode.

Check failure on line 60 in src/QrCode/QrCode.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest

Access to constant Enlarge on an unknown class Endroid\QrCode\RoundBlockSizeMode.
}

$this->qrCodeLogo = Logo::create(self::SWISS_CROSS_LOGO_FILE)
->setResizeToWidth(self::PX_SWISS_CROSS);
Expand Down

0 comments on commit 3e14033

Please sign in to comment.