🛀 clean-up (again)

This commit is contained in:
smiley
2023-11-27 22:53:38 +01:00
parent 2d2a00fabb
commit 00800ef901
44 changed files with 93 additions and 114 deletions
-1
View File
@@ -97,7 +97,6 @@ final class BitMatrix extends QRMatrix{
// mirror vertically
$this->matrix = array_reverse($this->matrix);
// rotate by 90 degrees clockwise
/** @phan-suppress-next-line PhanTypeMismatchReturnSuperType */
return $this->rotate90();
}
+15 -5
View File
@@ -11,9 +11,11 @@
namespace chillerlan\QRCode\Decoder;
use chillerlan\QRCode\QROptions;
use chillerlan\QRCode\Common\{BitBuffer, EccLevel, LuminanceSourceInterface, MaskPattern, Mode, Version};
use chillerlan\QRCode\Data\{AlphaNum, Byte, ECI, Hanzi, Kanji, Number};
use chillerlan\QRCode\Detector\Detector;
use chillerlan\Settings\SettingsContainerInterface;
use Throwable;
use function chr, str_replace;
@@ -25,10 +27,18 @@ use function chr, str_replace;
*/
final class Decoder{
private ?Version $version = null;
private ?EccLevel $eccLevel = null;
private ?MaskPattern $maskPattern = null;
private BitBuffer $bitBuffer;
/**
* @var \chillerlan\QRCode\QROptions|\chillerlan\Settings\SettingsContainerInterface
*/
private SettingsContainerInterface|QROptions $options;
private ?Version $version = null;
private ?EccLevel $eccLevel = null;
private ?MaskPattern $maskPattern = null;
private BitBuffer $bitBuffer;
public function __construct(SettingsContainerInterface|QROptions $options = new QROptions){
$this->options = $options;
}
/**
* Decodes a QR Code represented as a BitMatrix.
@@ -56,7 +66,7 @@ final class Decoder{
*/
return $this->decodeMatrix($matrix->resetVersionInfo()->mirrorDiagonal());
}
catch(Throwable $f){
catch(Throwable){
// Throw the exception from the original reading
throw $e;
}
+2 -2
View File
@@ -11,8 +11,8 @@
namespace chillerlan\QRCode\Decoder;
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Common\{BitBuffer, EccLevel, MaskPattern, Version};
use chillerlan\QRCode\Data\QRMatrix;
use function property_exists;
/**
@@ -85,7 +85,7 @@ final class DecoderResult{
}
/**
* Returns a QRMatrix instance with thesettings and data of the reader result
* Returns a QRMatrix instance with the settings and data of the reader result
*/
public function getQRMatrix():QRMatrix{
return (new QRMatrix($this->version, $this->eccLevel))
+7 -8
View File
@@ -12,7 +12,6 @@
namespace chillerlan\QRCode\Decoder;
use chillerlan\QRCode\Common\{BitBuffer, EccLevel, GenericGFPoly, GF256, Version};
use chillerlan\QRCode\QRCodeException;
use function array_fill, array_reverse, count;
/**
@@ -167,7 +166,7 @@ final class ReedSolomonDecoder{
* @param int $numEccCodewords number of error-correction codewords available
*
* @return int[]
* @throws \chillerlan\QRCode\QRCodeException if decoding fails for any reason
* @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException if decoding fails for any reason
*/
private function decodeWords(array $received, int $numEccCodewords):array{
$poly = new GenericGFPoly($received);
@@ -201,7 +200,7 @@ final class ReedSolomonDecoder{
$position = ($receivedCount - 1 - GF256::log($errorLocations[$i]));
if($position < 0){
throw new QRCodeException('Bad error location');
throw new QRCodeDecoderException('Bad error location');
}
$received[$position] ^= $errorMagnitudes[$i];
@@ -212,7 +211,7 @@ final class ReedSolomonDecoder{
/**
* @return \chillerlan\QRCode\Common\GenericGFPoly[] [sigma, omega]
* @throws \chillerlan\QRCode\QRCodeException
* @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException
*/
private function runEuclideanAlgorithm(GenericGFPoly $a, GenericGFPoly $b, int $z):array{
// Assume a's degree is >= b's
@@ -240,14 +239,14 @@ final class ReedSolomonDecoder{
$t = $q->multiply($tLast)->addOrSubtract($tLastLast);
if($r->getDegree() >= $rLast->getDegree()){
throw new QRCodeException('Division algorithm failed to reduce polynomial?');
throw new QRCodeDecoderException('Division algorithm failed to reduce polynomial?');
}
}
$sigmaTildeAtZero = $t->getCoefficient(0);
if($sigmaTildeAtZero === 0){
throw new QRCodeException('sigmaTilde(0) was zero');
throw new QRCodeDecoderException('sigmaTilde(0) was zero');
}
$inverse = GF256::inverse($sigmaTildeAtZero);
@@ -256,7 +255,7 @@ final class ReedSolomonDecoder{
}
/**
* @throws \chillerlan\QRCode\QRCodeException
* @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException
*/
private function findErrorLocations(GenericGFPoly $errorLocator):array{
// This is a direct application of Chien's search
@@ -277,7 +276,7 @@ final class ReedSolomonDecoder{
}
if($e !== $numErrors){
throw new QRCodeException('Error locator degree does not match number of roots');
throw new QRCodeDecoderException('Error locator degree does not match number of roots');
}
return $result;