Skip to content

Commit

Permalink
Add support for endroid/qr-code v6
Browse files Browse the repository at this point in the history
  • Loading branch information
sprain committed Oct 22, 2024
1 parent e5f5b6e commit 1ab9622
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
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 1ab9622

Please sign in to comment.