@@ -26,9 +26,12 @@ class EndroidQrCodeProvider implements IQRCodeProvider
26
26
27
27
protected $ endroid4 = false ;
28
28
29
+ protected $ endroid5 = false ;
30
+
29
31
public function __construct ($ bgcolor = 'ffffff ' , $ color = '000000 ' , $ margin = 0 , $ errorcorrectionlevel = 'H ' )
30
32
{
31
33
$ this ->endroid4 = method_exists (QrCode::class, 'create ' );
34
+ $ this ->endroid5 = enum_exists (ErrorCorrectionLevel::class);
32
35
33
36
$ this ->bgcolor = $ this ->handleColor ($ bgcolor );
34
37
$ this ->color = $ this ->handleColor ($ color );
@@ -76,11 +79,32 @@ private function handleColor(string $color): Color|array
76
79
77
80
private function handleErrorCorrectionLevel (string $ level ): ErrorCorrectionLevelInterface |ErrorCorrectionLevel
78
81
{
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
79
103
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 (),
84
108
};
85
109
}
86
110
}
0 commit comments