diff --git a/composer.json b/composer.json index 4710c75a..b71cd239 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "symfony/validator": "^4.4|^5.0|^6.0|^7.0", "symfony/intl": "^4.4|^5.0|^6.0|^7.0", "kmukku/php-iso11649": "^1.5", - "endroid/qr-code": "^4.4.4|^5.0", + "endroid/qr-code": "^4.4.4|^5.0|^6.0", "symfony/polyfill-intl-icu": "^1.23", "symfony/polyfill-mbstring": "^1.30" }, diff --git a/phpstan.neon.dist b/phpstan.neon.dist index e6cfcd2f..5eb79d07 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,4 +2,6 @@ parameters: level: 7 paths: - src/ + excludePaths: + - src/QrCode/QrCode.php reportUnmatchedIgnoredErrors: false diff --git a/src/QrCode/QrCode.php b/src/QrCode/QrCode.php index c02769dc..2c4907f9 100644 --- a/src/QrCode/QrCode.php +++ b/src/QrCode/QrCode.php @@ -67,26 +67,39 @@ private function __construct(string $data, string $fileFormat, array $unsupporte // 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 { + } elseif (method_exists(BaseQrCode::class, 'create')) { // 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); + } else { + // Endroid 6.x + $this->qrCode = new BaseQrCode( + $data, + new Encoding('UTF-8'), + ErrorCorrectionLevel::Medium, + self::PX_QR_CODE, + 0, + RoundBlockSizeMode::Enlarge + ); } - $this->qrCodeLogo = Logo::create(self::SWISS_CROSS_LOGO_FILE) - ->setResizeToWidth(self::PX_SWISS_CROSS); + if (method_exists(Logo::class, 'create')) { + $this->qrCodeLogo = Logo::create(self::SWISS_CROSS_LOGO_FILE) + ->setResizeToWidth(self::PX_SWISS_CROSS); + } else { + $this->qrCodeLogo = new Logo( + self::SWISS_CROSS_LOGO_FILE, + self::PX_SWISS_CROSS + ); + } $this->setWriterByExtension($fileFormat); }