Bacon / BaconQrCode

QR Code Generator for PHP
BSD 2-Clause "Simplified" License
1.83k stars 208 forks source link

Why are error correction level constants protected? #77

Closed Synchro closed 3 years ago

Synchro commented 3 years ago

I want to be able to set the error correction level of a QR by passing a param to the writer, as it permits. I have no need to know precisely what these values are, so it makes sense to pick a constant to say it for me, and I have seen some code in this repo that does exactly that, for example:

$writer->writeFile('hello', "code.png", Encoder::DEFAULT_BYTE_MODE_ECODING, ErrorCorrectionLevel::H);

However this no longer works because those constants are protected and thus can't be accessed from outside. The only option available is via the forBits() method – but in order to use that I need to know the bit numbers the levels correspond to, which makes no sense to me! So to get H level, I have to say:

$writer->writeFile('hello', "code.png", Encoder::DEFAULT_BYTE_MODE_ECODING, ErrorCorrectionLevel::forBits(2));
// or
$writer->writeFile('hello', "code.png", Encoder::DEFAULT_BYTE_MODE_ECODING, 0x02);

It's doubly confusing because the levels are not in any guessable order. Is this a mistake, or should I specify the correction level in some other way?

DASPRiD commented 3 years ago

You use the following:

ErrorCorrectionLevel::H().

https://github.com/Bacon/BaconQrCode/blob/master/src/Common/ErrorCorrectionLevel.php#L12-L15

Synchro commented 3 years ago

Thank you for clarifying!