From 153603a5dc1d79f86d25208897809437ef4d111d Mon Sep 17 00:00:00 2001 From: codemasher Date: Sun, 21 Nov 2021 11:41:40 +0100 Subject: [PATCH] :bath: more docblock cleanup & micro optimizations --- src/Common/BitBuffer.php | 30 +++++++++++++--------------- src/Common/ECICharset.php | 8 +++++++- src/Common/EccLevel.php | 13 +++++++++++- src/Common/FormatInformation.php | 33 ++++++++++++++++++++----------- src/Common/GenericGFPoly.php | 10 +++++----- src/Common/MaskPattern.php | 6 ++++++ src/Common/MaskPatternTester.php | 14 ++++++------- src/Common/ReedSolomonDecoder.php | 2 +- src/Data/AlphaNum.php | 25 ++++++++++++----------- src/Data/Byte.php | 11 +++++++---- src/Data/ECI.php | 5 ++++- src/Data/Kanji.php | 12 ++++++----- src/Data/Number.php | 19 ++++++++++-------- src/Data/QRMatrix.php | 6 +++--- src/Decoder/BitMatrixParser.php | 6 +++--- src/Output/QRFpdf.php | 11 ++++++++--- src/Output/QRImage.php | 8 ++++---- src/Output/QRImagick.php | 5 +++-- src/Output/QRMarkup.php | 4 ++-- src/Output/QROutputAbstract.php | 2 -- src/QRCode.php | 17 +++++++++++++++- src/QROptionsTrait.php | 4 +--- tests/Common/BitBufferTest.php | 6 ------ tests/QRCodeReaderTest.php | 2 +- 24 files changed, 158 insertions(+), 101 deletions(-) diff --git a/src/Common/BitBuffer.php b/src/Common/BitBuffer.php index 03d2d2a0d..07d3a2622 100644 --- a/src/Common/BitBuffer.php +++ b/src/Common/BitBuffer.php @@ -11,7 +11,7 @@ namespace chillerlan\QRCode\Common; use InvalidArgumentException; -use function count, floor; +use function count, floor, min; /** * Holds the raw binary data @@ -30,34 +30,33 @@ final class BitBuffer{ */ private int $length; + /** + * Read count (bytes) + */ private int $bytesRead = 0; + + /** + * Read count (bits) + */ private int $bitsRead = 0; /** * BitBuffer constructor. + * + * @param int[] $bytes */ public function __construct(array $bytes = null){ $this->buffer = $bytes ?? []; $this->length = count($this->buffer); } - /** - * clears the buffer - */ - public function clear():self{ - $this->buffer = []; - $this->length = 0; - - return $this; - } - /** * appends a sequence of bits */ - public function put(int $num, int $length):self{ + public function put(int $bits, int $length):self{ for($i = 0; $i < $length; $i++){ - $this->putBit((($num >> ($length - $i - 1)) & 1) === 1); + $this->putBit((($bits >> ($length - $i - 1)) & 1) === 1); } return $this; @@ -108,8 +107,7 @@ final class BitBuffer{ * * @param int $numBits number of bits to read * - * @return int representing the bits read. The bits will appear as the least-significant - * bits of the int + * @return int representing the bits read. The bits will appear as the least-significant bits of the int * @throws InvalidArgumentException if numBits isn't in [1,32] or more than is available */ public function read(int $numBits):int{ @@ -123,7 +121,7 @@ final class BitBuffer{ // First, read remainder from current byte if($this->bitsRead > 0){ $bitsLeft = 8 - $this->bitsRead; - $toRead = $numBits < $bitsLeft ? $numBits : $bitsLeft; + $toRead = min($numBits, $bitsLeft); $bitsToNotRead = $bitsLeft - $toRead; $mask = (0xff >> (8 - $toRead)) << $bitsToNotRead; $result = ($this->buffer[$this->bytesRead] & $mask) >> $bitsToNotRead; diff --git a/src/Common/ECICharset.php b/src/Common/ECICharset.php index 9f12bc71c..48c3c3cf5 100644 --- a/src/Common/ECICharset.php +++ b/src/Common/ECICharset.php @@ -87,6 +87,9 @@ final class ECICharset{ self::EUC_KR => 'EUC-KR', ]; + /** + * The current ECI character set ID + */ private int $charsetID; /** @@ -102,14 +105,17 @@ final class ECICharset{ } /** - * + * Returns the current character set ID */ public function getID():int{ return $this->charsetID; } /** + * Returns the name of the current character set or null if no name is available * + * @see \mb_convert_encoding() + * @see \iconv() */ public function getName():?string{ return self::MB_ENCODINGS[$this->charsetID]; diff --git a/src/Common/EccLevel.php b/src/Common/EccLevel.php index d1f77b2fa..6687a8c26 100644 --- a/src/Common/EccLevel.php +++ b/src/Common/EccLevel.php @@ -15,7 +15,7 @@ use chillerlan\QRCode\QRCodeException; use function array_column, array_combine, array_keys; /** - * + * This class encapsulates the four error correction levels defined by the QR code standard. */ final class EccLevel{ @@ -46,6 +46,9 @@ final class EccLevel{ self::H => 3, ]; + /** + * @var string[] + */ public const MODES_STRING = [ self::L => 'L', self::M => 'M', @@ -152,6 +155,14 @@ final class EccLevel{ ], ]; + /** + * The current ECC level value + * + * L: 0b01 + * M: 0b00 + * Q: 0b11 + * H: 0b10 + */ private int $eccLevel; /** diff --git a/src/Common/FormatInformation.php b/src/Common/FormatInformation.php index da46ff055..ac5500f21 100644 --- a/src/Common/FormatInformation.php +++ b/src/Common/FormatInformation.php @@ -12,15 +12,14 @@ namespace chillerlan\QRCode\Common; /** - *

Encapsulates a QR Code's format information, including the data mask used and - * error correction level.

+ * Encapsulates a QR Code's format information, including the data mask used and error correction level. * * @author Sean Owen - * @see \chillerlan\QRCode\Common\ErrorCorrectionLevel + * @see \chillerlan\QRCode\Common\EccLevel */ final class FormatInformation{ - public const MASK_QR = 0x5412; + public const FORMAT_INFO_MASK_QR = 0x5412; /** * See ISO 18004:2006, Annex C, Table C.1 @@ -62,29 +61,41 @@ final class FormatInformation{ [0x1F, 0x2BED], ]; + /** + * The current ECC level value + * + * L: 0b01 + * M: 0b00 + * Q: 0b11 + * H: 0b10 + */ private int $errorCorrectionLevel; - private int $dataMask; /** - * + * The current mask pattern (0-7) + */ + private int $maskPattern; + + /** + * Receives the format information from a parsed QR Code, detects ECC level and mask pattern */ public function __construct(int $formatInfo){ $this->errorCorrectionLevel = ($formatInfo >> 3) & 0x03; // Bits 3,4 - $this->dataMask = ($formatInfo & 0x07); // Bottom 3 bits + $this->maskPattern = ($formatInfo & 0x07); // Bottom 3 bits } /** - * + * Returns and EccLevel instance ith the detected ECC level set */ public function getErrorCorrectionLevel():EccLevel{ return new EccLevel($this->errorCorrectionLevel); } /** - * + * Returns a MaskPattern instance with the detected mask pattern set */ - public function getDataMask():MaskPattern{ - return new MaskPattern($this->dataMask); + public function getMaskPattern():MaskPattern{ + return new MaskPattern($this->maskPattern); } } diff --git a/src/Common/GenericGFPoly.php b/src/Common/GenericGFPoly.php index 98962356e..c46e77e4a 100644 --- a/src/Common/GenericGFPoly.php +++ b/src/Common/GenericGFPoly.php @@ -16,11 +16,11 @@ use InvalidArgumentException; use function array_fill, array_slice, array_splice, count; /** - *

Represents a polynomial whose coefficients are elements of a GF. - * Instances of this class are immutable.

+ * Represents a polynomial whose coefficients are elements of a GF. + * Instances of this class are immutable. * - *

Much credit is due to William Rucklidge since portions of this code are an indirect - * port of his C++ Reed-Solomon implementation.

+ * Much credit is due to William Rucklidge since portions of this code are an indirect + * port of his C++ Reed-Solomon implementation. * * @author Sean Owen */ @@ -34,7 +34,7 @@ final class GenericGFPoly{ * @param int|null $degree * * @throws \InvalidArgumentException if argument is null or empty, or if leading coefficient is 0 and this is not a - * constant polynomial (that is, it is not the monomial "0") + * constant polynomial (that is, it is not the monomial "0") */ public function __construct(array $coefficients, int $degree = null){ $degree ??= 0; diff --git a/src/Common/MaskPattern.php b/src/Common/MaskPattern.php index 7e3f77d62..9a57d1007 100644 --- a/src/Common/MaskPattern.php +++ b/src/Common/MaskPattern.php @@ -27,6 +27,9 @@ final class MaskPattern{ public const PATTERN_110 = 0b110; public const PATTERN_111 = 0b111; + /** + * @var int[] + */ public const PATTERNS = [ self::PATTERN_000, self::PATTERN_001, @@ -38,6 +41,9 @@ final class MaskPattern{ self::PATTERN_111, ]; + /** + * The current mask pattern value (0-7) + */ private int $maskPattern; /** diff --git a/src/Common/MaskPatternTester.php b/src/Common/MaskPatternTester.php index abda352a7..1a0549064 100644 --- a/src/Common/MaskPatternTester.php +++ b/src/Common/MaskPatternTester.php @@ -129,7 +129,7 @@ final class MaskPatternTester{ } if( - $val === $m[$y][$x + 1] + $val === $row[$x + 1] && $val === $m[$y + 1][$x] && $val === $m[$y + 1][$x + 1] ){ @@ -153,12 +153,12 @@ final class MaskPatternTester{ if( $x + 6 < $size && $val - && !$m[$y][$x + 1] - && $m[$y][$x + 2] - && $m[$y][$x + 3] - && $m[$y][$x + 4] - && !$m[$y][$x + 5] - && $m[$y][$x + 6] + && !$row[$x + 1] + && $row[$x + 2] + && $row[$x + 3] + && $row[$x + 4] + && !$row[$x + 5] + && $row[$x + 6] ){ $penalties++; } diff --git a/src/Common/ReedSolomonDecoder.php b/src/Common/ReedSolomonDecoder.php index 213f06179..e575a87ed 100644 --- a/src/Common/ReedSolomonDecoder.php +++ b/src/Common/ReedSolomonDecoder.php @@ -109,7 +109,7 @@ final class ReedSolomonDecoder{ $t = new GenericGFPoly([1]); // Run Euclidean algorithm until r's degree is less than R/2 - while($r->getDegree() >= $R / 2){ + while(2 * $r->getDegree() >= $R){ $rLastLast = $rLast; $tLastLast = $tLast; $rLast = $r; diff --git a/src/Data/AlphaNum.php b/src/Data/AlphaNum.php index 409351cbe..be91aa59e 100644 --- a/src/Data/AlphaNum.php +++ b/src/Data/AlphaNum.php @@ -27,7 +27,7 @@ final class AlphaNum extends QRDataModeAbstract{ * * @var int[] */ - private const CHAR_MAP_ALPHANUM = [ + private const CHAR_TO_ORD = [ '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, 'L' => 21, 'M' => 22, 'N' => 23, @@ -36,22 +36,25 @@ final class AlphaNum extends QRDataModeAbstract{ '+' => 40, '-' => 41, '.' => 42, '/' => 43, ':' => 44, ]; + /** + * @inheritDoc + */ protected static int $datamode = Mode::DATA_ALPHANUM; /** - * @inheritdoc + * @inheritDoc */ public function getLengthInBits():int{ return (int)ceil($this->getCharCount() * (11 / 2)); } /** - * @inheritdoc + * @inheritDoc */ public static function validateString(string $string):bool{ foreach(str_split($string) as $chr){ - if(!isset(self::CHAR_MAP_ALPHANUM[$chr])){ + if(!isset(self::CHAR_TO_ORD[$chr])){ return false; } } @@ -60,7 +63,7 @@ final class AlphaNum extends QRDataModeAbstract{ } /** - * @inheritdoc + * @inheritDoc */ public function write(BitBuffer $bitBuffer, int $versionNumber):void{ $len = $this->getCharCount(); @@ -87,23 +90,23 @@ final class AlphaNum extends QRDataModeAbstract{ * * @throws \chillerlan\QRCode\Data\QRCodeDataException on an illegal character occurence */ - protected function getCharCode(string $chr):int{ + private function getCharCode(string $chr):int{ - if(!isset(self::CHAR_MAP_ALPHANUM[$chr])){ - throw new QRCodeDataException(sprintf('illegal char: "%s" [%d]', $chr, ord($chr))); + if(isset(self::CHAR_TO_ORD[$chr])){ + return self::CHAR_TO_ORD[$chr]; } - return self::CHAR_MAP_ALPHANUM[$chr]; + throw new QRCodeDataException(sprintf('illegal char: "%s" [%d]', $chr, ord($chr))); } /** - * @inheritdoc + * @inheritDoc * * @throws \chillerlan\QRCode\Data\QRCodeDataException */ public static function decodeSegment(BitBuffer $bitBuffer, int $versionNumber):string{ $length = $bitBuffer->read(Mode::getLengthBitsForVersion(self::$datamode, $versionNumber)); - $charmap = array_flip(self::CHAR_MAP_ALPHANUM); + $charmap = array_flip(self::CHAR_TO_ORD); // @todo $toAlphaNumericChar = function(int $ord) use ($charmap):string{ diff --git a/src/Data/Byte.php b/src/Data/Byte.php index 06963e21e..2529408aa 100644 --- a/src/Data/Byte.php +++ b/src/Data/Byte.php @@ -22,24 +22,27 @@ use function ord; */ final class Byte extends QRDataModeAbstract{ + /** + * @inheritDoc + */ protected static int $datamode = Mode::DATA_BYTE; /** - * @inheritdoc + * @inheritDoc */ public function getLengthInBits():int{ return $this->getCharCount() * 8; } /** - * @inheritdoc + * @inheritDoc */ public static function validateString(string $string):bool{ return !empty($string); } /** - * @inheritdoc + * @inheritDoc */ public function write(BitBuffer $bitBuffer, int $versionNumber):void{ $len = $this->getCharCount(); @@ -59,7 +62,7 @@ final class Byte extends QRDataModeAbstract{ } /** - * @inheritdoc + * @inheritDoc * * @throws \chillerlan\QRCode\Data\QRCodeDataException */ diff --git a/src/Data/ECI.php b/src/Data/ECI.php index 86fe22e0a..9ba36e1bc 100644 --- a/src/Data/ECI.php +++ b/src/Data/ECI.php @@ -19,6 +19,9 @@ use chillerlan\QRCode\Common\{BitBuffer, ECICharset, Mode}; */ final class ECI extends QRDataModeAbstract{ + /** + * @inheritDoc + */ protected static int $datamode = Mode::DATA_ECI; /** @@ -41,7 +44,7 @@ final class ECI extends QRDataModeAbstract{ return 8; } - /** + /** * @inheritDoc */ public function write(BitBuffer $bitBuffer, int $versionNumber):void{ diff --git a/src/Data/Kanji.php b/src/Data/Kanji.php index e9664d4a4..80814cf25 100644 --- a/src/Data/Kanji.php +++ b/src/Data/Kanji.php @@ -22,6 +22,9 @@ use function chr, implode, mb_convert_encoding, mb_detect_encoding, mb_internal_ */ final class Kanji extends QRDataModeAbstract{ + /** + * @inheritDoc + */ protected static int $datamode = Mode::DATA_KANJI; /** @@ -30,19 +33,18 @@ final class Kanji extends QRDataModeAbstract{ public function __construct(string $data){ parent::__construct($data); - /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->data = mb_convert_encoding($this->data, 'SJIS', mb_detect_encoding($this->data)); } /** - * @inheritdoc + * @inheritDoc */ protected function getCharCount():int{ return mb_strlen($this->data, 'SJIS'); } /** - * @inheritdoc + * @inheritDoc */ public function getLengthInBits():int{ return $this->getCharCount() * 13; @@ -69,7 +71,7 @@ final class Kanji extends QRDataModeAbstract{ } /** - * @inheritdoc + * @inheritDoc * * @throws \chillerlan\QRCode\Data\QRCodeDataException on an illegal character occurence */ @@ -105,7 +107,7 @@ final class Kanji extends QRDataModeAbstract{ } /** - * @inheritdoc + * @inheritDoc * * @throws \chillerlan\QRCode\Data\QRCodeDataException */ diff --git a/src/Data/Number.php b/src/Data/Number.php index 46fac07a7..fc6ffe27d 100644 --- a/src/Data/Number.php +++ b/src/Data/Number.php @@ -25,26 +25,29 @@ final class Number extends QRDataModeAbstract{ /** * @var int[] */ - private const CHAR_MAP_NUMBER = [ + private const NUMBER_TO_ORD = [ '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, ]; + /** + * @inheritDoc + */ protected static int $datamode = Mode::DATA_NUMBER; /** - * @inheritdoc + * @inheritDoc */ public function getLengthInBits():int{ return (int)ceil($this->getCharCount() * (10 / 3)); } /** - * @inheritdoc + * @inheritDoc */ public static function validateString(string $string):bool{ foreach(str_split($string) as $chr){ - if(!isset(self::CHAR_MAP_NUMBER[$chr])){ + if(!isset(self::NUMBER_TO_ORD[$chr])){ return false; } } @@ -53,7 +56,7 @@ final class Number extends QRDataModeAbstract{ } /** - * @inheritdoc + * @inheritDoc */ public function write(BitBuffer $bitBuffer, int $versionNumber):void{ $len = $this->getCharCount(); @@ -97,7 +100,7 @@ final class Number extends QRDataModeAbstract{ foreach(str_split($string) as $chr){ $c = ord($chr); - if(!isset(self::CHAR_MAP_NUMBER[$chr])){ + if(!isset(self::NUMBER_TO_ORD[$chr])){ throw new QRCodeDataException(sprintf('illegal char: "%s" [%d]', $chr, $c)); } @@ -109,13 +112,13 @@ final class Number extends QRDataModeAbstract{ } /** - * @inheritdoc + * @inheritDoc * * @throws \chillerlan\QRCode\Data\QRCodeDataException */ public static function decodeSegment(BitBuffer $bitBuffer, int $versionNumber):string{ $length = $bitBuffer->read(Mode::getLengthBitsForVersion(self::$datamode, $versionNumber)); - $charmap = array_flip(self::CHAR_MAP_NUMBER); + $charmap = array_flip(self::NUMBER_TO_ORD); // @todo $toNumericChar = function(int $ord) use ($charmap):string{ diff --git a/src/Data/QRMatrix.php b/src/Data/QRMatrix.php index d648e8fe3..6bf7c05bd 100755 --- a/src/Data/QRMatrix.php +++ b/src/Data/QRMatrix.php @@ -13,7 +13,7 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Version}; use SplFixedArray; -use function array_fill, array_push, array_unshift, floor, max, min, range; +use function array_fill, array_unshift, floor, max, min, range; /** * Holds a numerical representation of the final QR Code; @@ -414,7 +414,7 @@ final class QRMatrix{ for($y = 0; $y < $this->moduleCount; $y++){ for($i = 0; $i < $size; $i++){ array_unshift($this->matrix[$y], $this::M_QUIETZONE); - array_push($this->matrix[$y], $this::M_QUIETZONE); + $this->matrix[$y][] = $this::M_QUIETZONE; } } @@ -424,7 +424,7 @@ final class QRMatrix{ for($i = 0; $i < $size; $i++){ array_unshift($this->matrix, $r); - array_push($this->matrix, $r); + $this->matrix[] = $r; } return $this; diff --git a/src/Decoder/BitMatrixParser.php b/src/Decoder/BitMatrixParser.php index 24ae15f94..95ceb2ecc 100644 --- a/src/Decoder/BitMatrixParser.php +++ b/src/Decoder/BitMatrixParser.php @@ -88,7 +88,7 @@ final class BitMatrixParser{ // Get the data mask for the format used in this QR Code. This will exclude // some bits from reading as we wind through the bit matrix. $dimension = $this->bitMatrix->getDimension(); - $this->bitMatrix->unmask($dimension, $formatInfo->getDataMask()); + $this->bitMatrix->unmask($dimension, $formatInfo->getMaskPattern()); $functionPattern = $this->bitMatrix->buildFunctionPattern($version); $readingUp = true; @@ -189,8 +189,8 @@ final class BitMatrixParser{ // Should return null, but, some QR codes apparently do not mask this info. // Try again by actually masking the pattern first. $this->parsedFormatInfo = $this->doDecodeFormatInformation( - $formatInfoBits1 ^ FormatInformation::MASK_QR, - $formatInfoBits2 ^ FormatInformation::MASK_QR + $formatInfoBits1 ^ FormatInformation::FORMAT_INFO_MASK_QR, + $formatInfoBits2 ^ FormatInformation::FORMAT_INFO_MASK_QR ); if($this->parsedFormatInfo !== null){ diff --git a/src/Output/QRFpdf.php b/src/Output/QRFpdf.php index 4500c0a6e..062c0f9c8 100644 --- a/src/Output/QRFpdf.php +++ b/src/Output/QRFpdf.php @@ -12,7 +12,6 @@ namespace chillerlan\QRCode\Output; use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\QRCodeException; use chillerlan\Settings\SettingsContainerInterface; use FPDF; @@ -26,12 +25,18 @@ use function array_values, class_exists, count, is_array; */ class QRFpdf extends QROutputAbstract{ + /** + * QRFpdf constructor. + * + * @throws \chillerlan\QRCode\Output\QRCodeOutputException + */ public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){ if(!class_exists(FPDF::class)){ // @codeCoverageIgnoreStart - throw new QRCodeException( - 'The QRFpdf output requires FPDF as dependency but the class "\FPDF" couldn\'t be found.' + throw new QRCodeOutputException( + 'The QRFpdf output requires FPDF (https://github.com/Setasign/FPDF)'. + ' as dependency but the class "\\FPDF" couldn\'t be found.' ); // @codeCoverageIgnoreEnd } diff --git a/src/Output/QRImage.php b/src/Output/QRImage.php index e746f127b..b17c86587 100644 --- a/src/Output/QRImage.php +++ b/src/Output/QRImage.php @@ -13,7 +13,7 @@ namespace chillerlan\QRCode\Output; use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\{QRCode, QRCodeException}; +use chillerlan\QRCode\QRCode; use chillerlan\Settings\SettingsContainerInterface; use Exception; @@ -51,12 +51,12 @@ class QRImage extends QROutputAbstract{ /** * @inheritDoc * - * @throws \chillerlan\QRCode\QRCodeException + * @throws \chillerlan\QRCode\Output\QRCodeOutputException */ public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){ if(!extension_loaded('gd')){ - throw new QRCodeException('ext-gd not loaded'); // @codeCoverageIgnore + throw new QRCodeOutputException('ext-gd not loaded'); // @codeCoverageIgnore } parent::__construct($options, $matrix); @@ -95,7 +95,7 @@ class QRImage extends QROutputAbstract{ $this->image = imagecreatetruecolor($this->length, $this->length); - // avoid: Indirect modification of overloaded property $imageTransparencyBG has no effect + // avoid: "Indirect modification of overloaded property $imageTransparencyBG has no effect" // https://stackoverflow.com/a/10455217 $tbg = $this->options->imageTransparencyBG; /** @phan-suppress-next-line PhanParamTooFewInternalUnpack */ diff --git a/src/Output/QRImagick.php b/src/Output/QRImagick.php index d93cb758f..9027395d7 100644 --- a/src/Output/QRImagick.php +++ b/src/Output/QRImagick.php @@ -13,7 +13,6 @@ namespace chillerlan\QRCode\Output; use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\QRCodeException; use chillerlan\Settings\SettingsContainerInterface; use Imagick, ImagickDraw, ImagickPixel; @@ -31,11 +30,13 @@ class QRImagick extends QROutputAbstract{ /** * @inheritDoc + * + * @throws \chillerlan\QRCode\Output\QRCodeOutputException */ public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){ if(!extension_loaded('imagick')){ - throw new QRCodeException('ext-imagick not loaded'); // @codeCoverageIgnore + throw new QRCodeOutputException('ext-imagick not loaded'); // @codeCoverageIgnore } parent::__construct($options, $matrix); diff --git a/src/Output/QRMarkup.php b/src/Output/QRMarkup.php index bf79bdcdf..fa1b97299 100644 --- a/src/Output/QRMarkup.php +++ b/src/Output/QRMarkup.php @@ -24,8 +24,8 @@ class QRMarkup extends QROutputAbstract{ /** * @see \sprintf() */ - protected string $svgHeader = ''; + protected string $svgHeader = ''; /** * @inheritDoc diff --git a/src/Output/QROutputAbstract.php b/src/Output/QROutputAbstract.php index 0c384e6d6..9dc8f6f2d 100644 --- a/src/Output/QROutputAbstract.php +++ b/src/Output/QROutputAbstract.php @@ -115,8 +115,6 @@ abstract class QROutputAbstract implements QROutputInterface{ /** * @inheritDoc - * - * @return mixed */ public function dump(string $file = null){ $file ??= $this->options->cachefile; diff --git a/src/QRCode.php b/src/QRCode.php index d60dd3ebe..ab1ad6078 100755 --- a/src/QRCode.php +++ b/src/QRCode.php @@ -116,6 +116,7 @@ class QRCode{ */ public function __construct(SettingsContainerInterface $options = null){ $this->options = $options ?? new QROptions; + // i hate this $this->luminanceSourceClass = $this->options->useImagickIfAvailable ? IMagickLuminanceSource::class : GDLuminanceSource::class; @@ -241,6 +242,8 @@ class QRCode{ } /** + * Adds a data segment + * * ISO/IEC 18004:2000 8.3.6 - Mixing modes * ISO/IEC 18004:2000 Annex H - Optimisation of bit stream length */ @@ -258,15 +261,19 @@ class QRCode{ } /** + * Adds a numeric data segment + * * ISO/IEC 18004:2000 8.3.2 - Numeric Mode */ - public function addNumberSegment(string $data):self{ + public function addNumericSegment(string $data):self{ $this->addSegment(new Number($data)); return $this; } /** + * Adds an alphanumeric data segment + * * ISO/IEC 18004:2000 8.3.3 - Alphanumeric Mode */ public function addAlphaNumSegment(string $data):self{ @@ -276,6 +283,8 @@ class QRCode{ } /** + * Adds a Kanji data segment + * * ISO/IEC 18004:2000 8.3.5 - Kanji Mode */ public function addKanjiSegment(string $data):self{ @@ -285,6 +294,8 @@ class QRCode{ } /** + * Adds an 8-bit byte data segment + * * ISO/IEC 18004:2000 8.3.4 - 8-bit Byte Mode */ public function addByteSegment(string $data):self{ @@ -294,6 +305,8 @@ class QRCode{ } /** + * Adds a standalone ECI designator + * * ISO/IEC 18004:2000 8.3.1 - Extended Channel Interpretation (ECI) Mode */ public function addEciDesignator(int $encoding):self{ @@ -303,6 +316,8 @@ class QRCode{ } /** + * Adds an ECI data segment (including designator) + * * i hate this somehow but i'll leave it for now * * @throws \chillerlan\QRCode\QRCodeException diff --git a/src/QROptionsTrait.php b/src/QROptionsTrait.php index b009024ed..410ef3f68 100644 --- a/src/QROptionsTrait.php +++ b/src/QROptionsTrait.php @@ -53,7 +53,7 @@ trait QROptionsTrait{ protected int $eccLevel = EccLevel::L; /** - * Mask Pattern to use + * Mask Pattern to use (no value in using, mostly for unit testing purposes) * * [0...7] or QRCode::MASK_PATTERN_AUTO */ @@ -335,8 +335,6 @@ trait QROptionsTrait{ /** * enables Imagick for the QR Code reader if the extension is available - * - * @codeCoverageIgnore */ protected function set_useImagickIfAvailable(bool $useImagickIfAvailable):void{ $this->useImagickIfAvailable = $useImagickIfAvailable && extension_loaded('imagick'); diff --git a/tests/Common/BitBufferTest.php b/tests/Common/BitBufferTest.php index 09342f0a5..5946508d9 100644 --- a/tests/Common/BitBufferTest.php +++ b/tests/Common/BitBufferTest.php @@ -42,10 +42,4 @@ final class BitBufferTest extends TestCase{ $this::assertSame(4, $this->bitBuffer->getLength()); } - public function testClear():void{ - $this->bitBuffer->clear(); - $this::assertSame([], $this->bitBuffer->getBuffer()); - $this::assertSame(0, $this->bitBuffer->getLength()); - } - } diff --git a/tests/QRCodeReaderTest.php b/tests/QRCodeReaderTest.php index 562bacd89..6dae2009c 100644 --- a/tests/QRCodeReaderTest.php +++ b/tests/QRCodeReaderTest.php @@ -89,7 +89,7 @@ class QRCodeReaderTest extends TestCase{ $byte = 'https://smiley.codes/qrcode/'; $qrcode = (new QRCode($options)) - ->addNumberSegment($numeric) + ->addNumericSegment($numeric) ->addAlphaNumSegment($alphanum) ->addKanjiSegment($kanji) ->addByteSegment($byte)