@@ -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,30 @@ private function handleColor(string $color): Color|array
76
79
77
80
private function handleErrorCorrectionLevel (string $ level ): ErrorCorrectionLevelInterface |ErrorCorrectionLevel
78
81
{
82
+ if ($ this ->endroid4 ) {
83
+ return match ($ level ) {
84
+ 'L ' => new ErrorCorrectionLevelLow (),
85
+ 'M ' => new ErrorCorrectionLevelMedium (),
86
+ 'Q ' => new ErrorCorrectionLevelQuartile (),
87
+ default => new ErrorCorrectionLevelHigh (),
88
+ };
89
+ }
90
+
91
+ if ($ this ->endroid5 ) {
92
+ return match ($ level ) {
93
+ 'L ' => ErrorCorrectionLevel::Low,
94
+ 'M ' => ErrorCorrectionLevel::Medium,
95
+ 'Q ' => ErrorCorrectionLevel::Quartile,
96
+ default => ErrorCorrectionLevel::High,
97
+ };
98
+ }
99
+
100
+ // Assuming this is for version EndroidQR < 4
79
101
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 (),
102
+ 'L ' => ErrorCorrectionLevel::LOW (),
103
+ 'M ' => ErrorCorrectionLevel::MEDIUM (),
104
+ 'Q ' => ErrorCorrectionLevel::QUARTILE (),
105
+ default => ErrorCorrectionLevel::HIGH (),
84
106
};
85
107
}
86
108
}
0 commit comments