From b960ec0c16ba2d5d84e401bece1ea55047374136 Mon Sep 17 00:00:00 2001 From: Clifford Vickrey Date: Wed, 23 Oct 2024 09:56:32 -0400 Subject: [PATCH 1/3] add support for endroid/qr-code version 6 --- lib/Providers/Qr/EndroidQrCodeProvider.php | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/Providers/Qr/EndroidQrCodeProvider.php b/lib/Providers/Qr/EndroidQrCodeProvider.php index 4d42c18..3cc6204 100755 --- a/lib/Providers/Qr/EndroidQrCodeProvider.php +++ b/lib/Providers/Qr/EndroidQrCodeProvider.php @@ -28,10 +28,13 @@ class EndroidQrCodeProvider implements IQRCodeProvider protected $endroid5 = false; + protected $endroid6 = false; + public function __construct($bgcolor = 'ffffff', $color = '000000', $margin = 0, $errorcorrectionlevel = 'H') { - $this->endroid4 = method_exists(QrCode::class, 'create'); $this->endroid5 = enum_exists(ErrorCorrectionLevel::class); + $this->endroid6 = $this->endroid5 && !method_exists(QrCode::class, 'setSize'); + $this->endroid4 = $this->endroid6 || method_exists(QrCode::class, 'create'); $this->bgcolor = $this->handleColor($bgcolor); $this->color = $this->handleColor($color); @@ -56,15 +59,25 @@ public function getQRCodeImage(string $qrText, int $size): string protected function qrCodeInstance(string $qrText, int $size): QrCode { - $qrCode = new QrCode($qrText); - $qrCode->setSize($size); - - $qrCode->setErrorCorrectionLevel($this->errorcorrectionlevel); - $qrCode->setMargin($this->margin); - $qrCode->setBackgroundColor($this->bgcolor); - $qrCode->setForegroundColor($this->color); + if (!$this->endroid6) { + $qrCode = new QrCode($qrText); + $qrCode->setSize($size); + + $qrCode->setErrorCorrectionLevel($this->errorcorrectionlevel); + $qrCode->setMargin($this->margin); + $qrCode->setBackgroundColor($this->bgcolor); + $qrCode->setForegroundColor($this->color); + return $qrCode; + } - return $qrCode; + return new QrCode( + data: $qrText, + errorCorrectionLevel: $this->errorcorrectionlevel, + size: $size, + margin: $this->margin, + foregroundColor: $this->color, + backgroundColor: $this->bgcolor + ); } private function handleColor(string $color): Color|array From 759b8cf9c215dede4914b86e266b4f5a80b19b76 Mon Sep 17 00:00:00 2001 From: Clifford Vickrey Date: Wed, 23 Oct 2024 10:15:33 -0400 Subject: [PATCH 2/3] add endroid v6 to github workflows --- .github/workflows/test-endroid.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-endroid.yml b/.github/workflows/test-endroid.yml index 72b17bc..169f77b 100644 --- a/.github/workflows/test-endroid.yml +++ b/.github/workflows/test-endroid.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: php-version: ['8.2', '8.3'] - endroid-version: ["^3","^4","^5"] + endroid-version: ["^3","^4","^5","^6"] steps: - uses: actions/checkout@v4 From 98fcc0f2d2e4c64e61c32db4178895c6fc62f797 Mon Sep 17 00:00:00 2001 From: Clifford Vickrey Date: Wed, 23 Oct 2024 12:12:53 -0400 Subject: [PATCH 3/3] remove negative conditional (endroid-related) --- lib/Providers/Qr/EndroidQrCodeProvider.php | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/Providers/Qr/EndroidQrCodeProvider.php b/lib/Providers/Qr/EndroidQrCodeProvider.php index 3cc6204..a544cb6 100755 --- a/lib/Providers/Qr/EndroidQrCodeProvider.php +++ b/lib/Providers/Qr/EndroidQrCodeProvider.php @@ -59,25 +59,25 @@ public function getQRCodeImage(string $qrText, int $size): string protected function qrCodeInstance(string $qrText, int $size): QrCode { - if (!$this->endroid6) { - $qrCode = new QrCode($qrText); - $qrCode->setSize($size); - - $qrCode->setErrorCorrectionLevel($this->errorcorrectionlevel); - $qrCode->setMargin($this->margin); - $qrCode->setBackgroundColor($this->bgcolor); - $qrCode->setForegroundColor($this->color); - return $qrCode; + if ($this->endroid6) { + return new QrCode( + data: $qrText, + errorCorrectionLevel: $this->errorcorrectionlevel, + size: $size, + margin: $this->margin, + foregroundColor: $this->color, + backgroundColor: $this->bgcolor + ); } - return new QrCode( - data: $qrText, - errorCorrectionLevel: $this->errorcorrectionlevel, - size: $size, - margin: $this->margin, - foregroundColor: $this->color, - backgroundColor: $this->bgcolor - ); + $qrCode = new QrCode($qrText); + $qrCode->setSize($size); + + $qrCode->setErrorCorrectionLevel($this->errorcorrectionlevel); + $qrCode->setMargin($this->margin); + $qrCode->setBackgroundColor($this->bgcolor); + $qrCode->setForegroundColor($this->color); + return $qrCode; } private function handleColor(string $color): Color|array