From 3e1403360cb5a4c1b282d83da9b523e8841d7d4f Mon Sep 17 00:00:00 2001 From: Manuel Reinhard Date: Wed, 4 Oct 2023 16:06:18 +0200 Subject: [PATCH 1/2] Add support for Endroid 5 --- composer.json | 2 +- composer.lock | 20 ++++++++++---------- src/QrCode/QrCode.php | 27 +++++++++++++++++++-------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index b5d07b24..1ec66f81 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/composer.lock b/composer.lock index 8abdee91..083662a9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4f8c8009f4976379503522594ce61e52", + "content-hash": "9da3c6bb2613f31f739b5f33012af323", "packages": [ { "name": "bacon/bacon-qr-code", @@ -112,21 +112,21 @@ }, { "name": "endroid/qr-code", - "version": "4.8.1", + "version": "5.0.1", "source": { "type": "git", "url": "https://github.com/endroid/qr-code.git", - "reference": "652157aee43d919be36cf2100a5a25b0882462f7" + "reference": "3601a9df66f6c526e4bb6dc2261e1ce03064e7d2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/endroid/qr-code/zipball/652157aee43d919be36cf2100a5a25b0882462f7", - "reference": "652157aee43d919be36cf2100a5a25b0882462f7", + "url": "https://api.github.com/repos/endroid/qr-code/zipball/3601a9df66f6c526e4bb6dc2261e1ce03064e7d2", + "reference": "3601a9df66f6c526e4bb6dc2261e1ce03064e7d2", "shasum": "" }, "require": { "bacon/bacon-qr-code": "^2.0.5", - "php": "^8.0" + "php": "^8.1" }, "conflict": { "khanamiryan/qrcode-detector-decoder": "^1.0.6" @@ -146,7 +146,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.x-dev" + "dev-master": "5.x-dev" } }, "autoload": { @@ -175,7 +175,7 @@ ], "support": { "issues": "https://github.com/endroid/qr-code/issues", - "source": "https://github.com/endroid/qr-code/tree/4.8.1" + "source": "https://github.com/endroid/qr-code/tree/5.0.1" }, "funding": [ { @@ -183,7 +183,7 @@ "type": "github" } ], - "time": "2023-02-23T08:56:09+00:00" + "time": "2023-10-02T22:39:22+00:00" }, { "name": "kmukku/php-iso11649", @@ -4763,5 +4763,5 @@ "ext-dom": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/QrCode/QrCode.php b/src/QrCode/QrCode.php index e1733775..78680adf 100644 --- a/src/QrCode/QrCode.php +++ b/src/QrCode/QrCode.php @@ -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; @@ -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()) + ->setSize(self::PX_QR_CODE) + ->setMargin(0) + ->setRoundBlockSizeMode(new RoundBlockSizeMode\RoundBlockSizeModeEnlarge()); + } else { + // Endroid 5.x + $this->qrCode = BaseQrCode::create($data) + ->setEncoding(new Encoding('UTF-8')) + ->setErrorCorrectionLevel(ErrorCorrectionLevel::Medium) + ->setSize(self::PX_QR_CODE) + ->setMargin(0) + ->setRoundBlockSizeMode(RoundBlockSizeMode::Enlarge); + } $this->qrCodeLogo = Logo::create(self::SWISS_CROSS_LOGO_FILE) ->setResizeToWidth(self::PX_SWISS_CROSS); From 51888c05d08d512d91d6a02e532418e169130e4c Mon Sep 17 00:00:00 2001 From: Manuel Reinhard Date: Wed, 4 Oct 2023 16:11:06 +0200 Subject: [PATCH 2/2] Ignore PHPStan errors on different Endroid versions --- src/QrCode/QrCode.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/QrCode/QrCode.php b/src/QrCode/QrCode.php index 78680adf..6db38ee5 100644 --- a/src/QrCode/QrCode.php +++ b/src/QrCode/QrCode.php @@ -46,17 +46,21 @@ private function __construct(string $data, string $fileFormat) // Endroid 4.x $this->qrCode = BaseQrCode::create($data) ->setEncoding(new Encoding('UTF-8')) + /** @phpstan-ignore-next-line as it throws error if Endroid 5 is installed */ ->setErrorCorrectionLevel(new ErrorCorrectionLevel\ErrorCorrectionLevelMedium()) ->setSize(self::PX_QR_CODE) ->setMargin(0) + /** @phpstan-ignore-next-line as it throws error if Endroid 5 is installed */ ->setRoundBlockSizeMode(new RoundBlockSizeMode\RoundBlockSizeModeEnlarge()); } else { // Endroid 5.x $this->qrCode = BaseQrCode::create($data) ->setEncoding(new Encoding('UTF-8')) + /** @phpstan-ignore-next-line as it throws error if Endroid 4 is installed */ ->setErrorCorrectionLevel(ErrorCorrectionLevel::Medium) ->setSize(self::PX_QR_CODE) ->setMargin(0) + /** @phpstan-ignore-next-line as it throws error if Endroid 4 is installed */ ->setRoundBlockSizeMode(RoundBlockSizeMode::Enlarge); }