From d01dc334d7f38ac41338d6115be524704673d6f8 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 18 Feb 2024 19:58:19 +0100 Subject: [PATCH] Update to endroid/qr-code 5 --- composer.json | 4 +- module/Core/src/Action/Model/QrCodeParams.php | 44 ++++++++----------- module/Core/src/Action/QrCodeAction.php | 1 - 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index 3ce4f63a..173c0eb1 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "cakephp/chronos": "^3.0.2", "doctrine/migrations": "^3.6", "doctrine/orm": "^3.0", - "endroid/qr-code": "^4.8", + "endroid/qr-code": "^5.0", "friendsofphp/proxy-manager-lts": "^1.0", "geoip2/geoip2": "^3.0", "guzzlehttp/guzzle": "^7.5", @@ -42,7 +42,7 @@ "pugx/shortid-php": "^1.1", "ramsey/uuid": "^4.7", "shlinkio/doctrine-specification": "^2.1.1", - "shlinkio/shlink-common": "dev-main#762b3b8 as 6.0", + "shlinkio/shlink-common": "dev-main#b9a6bd5 as 6.0", "shlinkio/shlink-config": "dev-main#a43b380 as 3.0", "shlinkio/shlink-event-dispatcher": "dev-main#aa9023c as 4.0", "shlinkio/shlink-importer": "dev-main#65a9a30 as 5.3", diff --git a/module/Core/src/Action/Model/QrCodeParams.php b/module/Core/src/Action/Model/QrCodeParams.php index 638d9929..0fc1ebc6 100644 --- a/module/Core/src/Action/Model/QrCodeParams.php +++ b/module/Core/src/Action/Model/QrCodeParams.php @@ -6,31 +6,25 @@ namespace Shlinkio\Shlink\Core\Action\Model; use Endroid\QrCode\Color\Color; use Endroid\QrCode\Color\ColorInterface; -use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelHigh; -use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelInterface; -use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelLow; -use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelMedium; -use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelQuartile; -use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeInterface; -use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin; -use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeNone; +use Endroid\QrCode\ErrorCorrectionLevel; +use Endroid\QrCode\RoundBlockSizeMode; use Endroid\QrCode\Writer\PngWriter; use Endroid\QrCode\Writer\SvgWriter; use Endroid\QrCode\Writer\WriterInterface; use Psr\Http\Message\ServerRequestInterface; use Shlinkio\Shlink\Core\Options\QrCodeOptions; - use Throwable; + use function hexdec; use function ltrim; use function max; use function min; -use function self; use function Shlinkio\Shlink\Core\ArrayUtils\contains; use function strlen; use function strtolower; use function substr; use function trim; + use const Shlinkio\Shlink\DEFAULT_QR_CODE_BG_COLOR; use const Shlinkio\Shlink\DEFAULT_QR_CODE_COLOR; @@ -44,8 +38,8 @@ final class QrCodeParams public readonly int $size, public readonly int $margin, public readonly WriterInterface $writer, - public readonly ErrorCorrectionLevelInterface $errorCorrectionLevel, - public readonly RoundBlockSizeModeInterface $roundBlockSizeMode, + public readonly ErrorCorrectionLevel $errorCorrectionLevel, + public readonly RoundBlockSizeMode $roundBlockSizeMode, public readonly ColorInterface $color, public readonly ColorInterface $bgColor, ) { @@ -98,23 +92,23 @@ final class QrCodeParams }; } - private static function resolveErrorCorrection(array $query, QrCodeOptions $defaults): ErrorCorrectionLevelInterface + private static function resolveErrorCorrection(array $query, QrCodeOptions $defaults): ErrorCorrectionLevel { $errorCorrectionLevel = self::normalizeParam($query['errorCorrection'] ?? $defaults->errorCorrection); return match ($errorCorrectionLevel) { - 'h' => new ErrorCorrectionLevelHigh(), - 'q' => new ErrorCorrectionLevelQuartile(), - 'm' => new ErrorCorrectionLevelMedium(), - default => new ErrorCorrectionLevelLow(), // 'l' + 'h' => ErrorCorrectionLevel::High, + 'q' => ErrorCorrectionLevel::Quartile, + 'm' => ErrorCorrectionLevel::Medium, + default => ErrorCorrectionLevel::Low, // 'l' }; } - private static function resolveRoundBlockSize(array $query, QrCodeOptions $defaults): RoundBlockSizeModeInterface + private static function resolveRoundBlockSize(array $query, QrCodeOptions $defaults): RoundBlockSizeMode { $doNotRoundBlockSize = isset($query['roundBlockSize']) ? $query['roundBlockSize'] === 'false' : ! $defaults->roundBlockSize; - return $doNotRoundBlockSize ? new RoundBlockSizeModeNone() : new RoundBlockSizeModeMargin(); + return $doNotRoundBlockSize ? RoundBlockSizeMode::None : RoundBlockSizeMode::Margin; } private static function resolveColor(array $query, QrCodeOptions $defaults): ColorInterface @@ -136,16 +130,16 @@ final class QrCodeParams try { if (strlen($hexColor) === 3) { return new Color( - hexdec(substr($hexColor, 0, 1) . substr($hexColor, 0, 1)), - hexdec(substr($hexColor, 1, 1) . substr($hexColor, 1, 1)), - hexdec(substr($hexColor, 2, 1) . substr($hexColor, 2, 1)), + (int) hexdec(substr($hexColor, 0, 1) . substr($hexColor, 0, 1)), + (int) hexdec(substr($hexColor, 1, 1) . substr($hexColor, 1, 1)), + (int) hexdec(substr($hexColor, 2, 1) . substr($hexColor, 2, 1)), ); } return new Color( - hexdec(substr($hexColor, 0, 2)), - hexdec(substr($hexColor, 2, 2)), - hexdec(substr($hexColor, 4, 2)), + (int) hexdec(substr($hexColor, 0, 2)), + (int) hexdec(substr($hexColor, 2, 2)), + (int) hexdec(substr($hexColor, 4, 2)), ); } catch (Throwable $e) { // If a non-hex value was provided and an error occurs, fall back to the default color. diff --git a/module/Core/src/Action/QrCodeAction.php b/module/Core/src/Action/QrCodeAction.php index 748ed01b..53fb1251 100644 --- a/module/Core/src/Action/QrCodeAction.php +++ b/module/Core/src/Action/QrCodeAction.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Action; use Endroid\QrCode\Builder\Builder; -use Endroid\QrCode\Color\Color; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\MiddlewareInterface;