Skip to content

Commit

Permalink
Merge pull request #262 from sprain/endroid-qr-v6
Browse files Browse the repository at this point in the history
Add support for endroid/qr-code v6
  • Loading branch information
sprain authored Oct 22, 2024
2 parents 3805597 + 1ab9622 commit 4af926f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ parameters:
level: 7
paths:
- src/
excludePaths:
- src/QrCode/QrCode.php
reportUnmatchedIgnoredErrors: false
27 changes: 20 additions & 7 deletions src/QrCode/QrCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 4af926f

Please sign in to comment.