@@ -26,9 +26,12 @@ class EndroidQrCodeProvider implements IQRCodeProvider
2626
2727 protected $ endroid4 = false ;
2828
29+ protected $ endroid5 = false ;
30+
2931 public function __construct ($ bgcolor = 'ffffff ' , $ color = '000000 ' , $ margin = 0 , $ errorcorrectionlevel = 'H ' )
3032 {
3133 $ this ->endroid4 = method_exists (QrCode::class, 'create ' );
34+ $ this ->endroid5 = enum_exists (ErrorCorrectionLevel::class);
3235
3336 $ this ->bgcolor = $ this ->handleColor ($ bgcolor );
3437 $ this ->color = $ this ->handleColor ($ color );
@@ -76,11 +79,32 @@ private function handleColor(string $color): Color|array
7679
7780 private function handleErrorCorrectionLevel (string $ level ): ErrorCorrectionLevelInterface |ErrorCorrectionLevel
7881 {
82+ // First check for version 5 (using enums)
83+ if ($ this ->endroid5 ) {
84+ return match ($ level ) {
85+ 'L ' => ErrorCorrectionLevel::Low,
86+ 'M ' => ErrorCorrectionLevel::Medium,
87+ 'Q ' => ErrorCorrectionLevel::Quartile,
88+ default => ErrorCorrectionLevel::High,
89+ };
90+ }
91+
92+ // If not check for version 4 (using classes)
93+ if ($ this ->endroid4 ) {
94+ return match ($ level ) {
95+ 'L ' => new ErrorCorrectionLevelLow (),
96+ 'M ' => new ErrorCorrectionLevelMedium (),
97+ 'Q ' => new ErrorCorrectionLevelQuartile (),
98+ default => new ErrorCorrectionLevelHigh (),
99+ };
100+ }
101+
102+ // Any other version will be using strings
79103 return match ($ level ) {
80- 'L ' => $ this -> endroid4 ? new ErrorCorrectionLevelLow () : ErrorCorrectionLevel::LOW (),
81- 'M ' => $ this -> endroid4 ? new ErrorCorrectionLevelMedium () : ErrorCorrectionLevel::MEDIUM (),
82- 'Q ' => $ this -> endroid4 ? new ErrorCorrectionLevelQuartile () : ErrorCorrectionLevel::QUARTILE (),
83- default => $ this -> endroid4 ? new ErrorCorrectionLevelHigh () : ErrorCorrectionLevel::HIGH (),
104+ 'L ' => ErrorCorrectionLevel::LOW (),
105+ 'M ' => ErrorCorrectionLevel::MEDIUM (),
106+ 'Q ' => ErrorCorrectionLevel::QUARTILE (),
107+ default => ErrorCorrectionLevel::HIGH (),
84108 };
85109 }
86110}
0 commit comments