Browse Source

:bath: more docblock cleanup & micro optimizations

codemasher 4 năm trước cách đây
mục cha
commit
153603a5dc

+ 14 - 16
src/Common/BitBuffer.php

@@ -11,7 +11,7 @@
 namespace chillerlan\QRCode\Common;
 namespace chillerlan\QRCode\Common;
 
 
 use InvalidArgumentException;
 use InvalidArgumentException;
-use function count, floor;
+use function count, floor, min;
 
 
 /**
 /**
  * Holds the raw binary data
  * Holds the raw binary data
@@ -30,34 +30,33 @@ final class BitBuffer{
 	 */
 	 */
 	private int $length;
 	private int $length;
 
 
+	/**
+	 * Read count (bytes)
+	 */
 	private int $bytesRead = 0;
 	private int $bytesRead = 0;
+
+	/**
+	 * Read count (bits)
+	 */
 	private int $bitsRead  = 0;
 	private int $bitsRead  = 0;
 
 
 	/**
 	/**
 	 * BitBuffer constructor.
 	 * BitBuffer constructor.
+	 *
+	 * @param int[] $bytes
 	 */
 	 */
 	public function __construct(array $bytes = null){
 	public function __construct(array $bytes = null){
 		$this->buffer = $bytes ?? [];
 		$this->buffer = $bytes ?? [];
 		$this->length = count($this->buffer);
 		$this->length = count($this->buffer);
 	}
 	}
 
 
-	/**
-	 * clears the buffer
-	 */
-	public function clear():self{
-		$this->buffer = [];
-		$this->length = 0;
-
-		return $this;
-	}
-
 	/**
 	/**
 	 * appends a sequence of bits
 	 * 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++){
 		for($i = 0; $i < $length; $i++){
-			$this->putBit((($num >> ($length - $i - 1)) & 1) === 1);
+			$this->putBit((($bits >> ($length - $i - 1)) & 1) === 1);
 		}
 		}
 
 
 		return $this;
 		return $this;
@@ -108,8 +107,7 @@ final class BitBuffer{
 	 *
 	 *
 	 * @param int $numBits number of bits to read
 	 * @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
 	 * @throws InvalidArgumentException if numBits isn't in [1,32] or more than is available
 	 */
 	 */
 	public function read(int $numBits):int{
 	public function read(int $numBits):int{
@@ -123,7 +121,7 @@ final class BitBuffer{
 		// First, read remainder from current byte
 		// First, read remainder from current byte
 		if($this->bitsRead > 0){
 		if($this->bitsRead > 0){
 			$bitsLeft       = 8 - $this->bitsRead;
 			$bitsLeft       = 8 - $this->bitsRead;
-			$toRead         = $numBits < $bitsLeft ? $numBits : $bitsLeft;
+			$toRead         = min($numBits, $bitsLeft);
 			$bitsToNotRead  = $bitsLeft - $toRead;
 			$bitsToNotRead  = $bitsLeft - $toRead;
 			$mask           = (0xff >> (8 - $toRead)) << $bitsToNotRead;
 			$mask           = (0xff >> (8 - $toRead)) << $bitsToNotRead;
 			$result         = ($this->buffer[$this->bytesRead] & $mask) >> $bitsToNotRead;
 			$result         = ($this->buffer[$this->bytesRead] & $mask) >> $bitsToNotRead;

+ 7 - 1
src/Common/ECICharset.php

@@ -87,6 +87,9 @@ final class ECICharset{
 		self::EUC_KR                => 'EUC-KR',
 		self::EUC_KR                => 'EUC-KR',
 	];
 	];
 
 
+	/**
+	 * The current ECI character set ID
+	 */
 	private int $charsetID;
 	private int $charsetID;
 
 
 	/**
 	/**
@@ -102,14 +105,17 @@ final class ECICharset{
 	}
 	}
 
 
 	/**
 	/**
-	 *
+	 * Returns the current character set ID
 	 */
 	 */
 	public function getID():int{
 	public function getID():int{
 		return $this->charsetID;
 		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{
 	public function getName():?string{
 		return self::MB_ENCODINGS[$this->charsetID];
 		return self::MB_ENCODINGS[$this->charsetID];

+ 12 - 1
src/Common/EccLevel.php

@@ -15,7 +15,7 @@ use chillerlan\QRCode\QRCodeException;
 use function array_column, array_combine, array_keys;
 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{
 final class EccLevel{
 
 
@@ -46,6 +46,9 @@ final class EccLevel{
 		self::H => 3,
 		self::H => 3,
 	];
 	];
 
 
+	/**
+	 * @var string[]
+	 */
 	public const MODES_STRING = [
 	public const MODES_STRING = [
 		self::L => 'L',
 		self::L => 'L',
 		self::M => 'M',
 		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;
 	private int $eccLevel;
 
 
 	/**
 	/**

+ 22 - 11
src/Common/FormatInformation.php

@@ -12,15 +12,14 @@
 namespace chillerlan\QRCode\Common;
 namespace chillerlan\QRCode\Common;
 
 
 /**
 /**
- * <p>Encapsulates a QR Code's format information, including the data mask used and
- * error correction level.</p>
+ * Encapsulates a QR Code's format information, including the data mask used and error correction level.
  *
  *
  * @author Sean Owen
  * @author Sean Owen
- * @see    \chillerlan\QRCode\Common\ErrorCorrectionLevel
+ * @see    \chillerlan\QRCode\Common\EccLevel
  */
  */
 final class FormatInformation{
 final class FormatInformation{
 
 
-	public const MASK_QR = 0x5412;
+	public const FORMAT_INFO_MASK_QR = 0x5412;
 
 
 	/**
 	/**
 	 * See ISO 18004:2006, Annex C, Table C.1
 	 * See ISO 18004:2006, Annex C, Table C.1
@@ -62,29 +61,41 @@ final class FormatInformation{
 		[0x1F, 0x2BED],
 		[0x1F, 0x2BED],
 	];
 	];
 
 
+	/**
+	 * The current ECC level value
+	 *
+	 * L: 0b01
+	 * M: 0b00
+	 * Q: 0b11
+	 * H: 0b10
+	 */
 	private int $errorCorrectionLevel;
 	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){
 	public function __construct(int $formatInfo){
 		$this->errorCorrectionLevel = ($formatInfo >> 3) & 0x03; // Bits 3,4
 		$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{
 	public function getErrorCorrectionLevel():EccLevel{
 		return new EccLevel($this->errorCorrectionLevel);
 		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);
 	}
 	}
 
 
 }
 }

+ 5 - 5
src/Common/GenericGFPoly.php

@@ -16,11 +16,11 @@ use InvalidArgumentException;
 use function array_fill, array_slice, array_splice, count;
 use function array_fill, array_slice, array_splice, count;
 
 
 /**
 /**
- * <p>Represents a polynomial whose coefficients are elements of a GF.
- * Instances of this class are immutable.</p>
+ * Represents a polynomial whose coefficients are elements of a GF.
+ * Instances of this class are immutable.
  *
  *
- * <p>Much credit is due to William Rucklidge since portions of this code are an indirect
- * port of his C++ Reed-Solomon implementation.</p>
+ * 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
  * @author Sean Owen
  */
  */
@@ -34,7 +34,7 @@ final class GenericGFPoly{
 	 * @param int|null   $degree
 	 * @param int|null   $degree
 	 *
 	 *
 	 * @throws \InvalidArgumentException if argument is null or empty, or if leading coefficient is 0 and this is not a
 	 * @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){
 	public function __construct(array $coefficients, int $degree = null){
 		$degree ??= 0;
 		$degree ??= 0;

+ 6 - 0
src/Common/MaskPattern.php

@@ -27,6 +27,9 @@ final class MaskPattern{
 	public const PATTERN_110 = 0b110;
 	public const PATTERN_110 = 0b110;
 	public const PATTERN_111 = 0b111;
 	public const PATTERN_111 = 0b111;
 
 
+	/**
+	 * @var int[]
+	 */
 	public const PATTERNS = [
 	public const PATTERNS = [
 		self::PATTERN_000,
 		self::PATTERN_000,
 		self::PATTERN_001,
 		self::PATTERN_001,
@@ -38,6 +41,9 @@ final class MaskPattern{
 		self::PATTERN_111,
 		self::PATTERN_111,
 	];
 	];
 
 
+	/**
+	 * The current mask pattern value (0-7)
+	 */
 	private int $maskPattern;
 	private int $maskPattern;
 
 
 	/**
 	/**

+ 7 - 7
src/Common/MaskPatternTester.php

@@ -129,7 +129,7 @@ final class MaskPatternTester{
 				}
 				}
 
 
 				if(
 				if(
-					   $val === $m[$y][$x + 1]
+					   $val === $row[$x + 1]
 					&& $val === $m[$y + 1][$x]
 					&& $val === $m[$y + 1][$x]
 					&& $val === $m[$y + 1][$x + 1]
 					&& $val === $m[$y + 1][$x + 1]
 				){
 				){
@@ -153,12 +153,12 @@ final class MaskPatternTester{
 				if(
 				if(
 					$x + 6 < $size
 					$x + 6 < $size
 					&&  $val
 					&&  $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++;
 					$penalties++;
 				}
 				}

+ 1 - 1
src/Common/ReedSolomonDecoder.php

@@ -109,7 +109,7 @@ final class ReedSolomonDecoder{
 		$t     = new GenericGFPoly([1]);
 		$t     = new GenericGFPoly([1]);
 
 
 		// Run Euclidean algorithm until r's degree is less than R/2
 		// Run Euclidean algorithm until r's degree is less than R/2
-		while($r->getDegree() >= $R / 2){
+		while(2 * $r->getDegree() >= $R){
 			$rLastLast = $rLast;
 			$rLastLast = $rLast;
 			$tLastLast = $tLast;
 			$tLastLast = $tLast;
 			$rLast     = $r;
 			$rLast     = $r;

+ 14 - 11
src/Data/AlphaNum.php

@@ -27,7 +27,7 @@ final class AlphaNum extends QRDataModeAbstract{
 	 *
 	 *
 	 * @var int[]
 	 * @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,
 		'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,
 		'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,
 		'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,
 		'+' => 40, '-' => 41, '.' => 42, '/' => 43, ':' => 44,
 	];
 	];
 
 
+	/**
+	 * @inheritDoc
+	 */
 	protected static int $datamode = Mode::DATA_ALPHANUM;
 	protected static int $datamode = Mode::DATA_ALPHANUM;
 
 
 	/**
 	/**
-	 * @inheritdoc
+	 * @inheritDoc
 	 */
 	 */
 	public function getLengthInBits():int{
 	public function getLengthInBits():int{
 		return (int)ceil($this->getCharCount() * (11 / 2));
 		return (int)ceil($this->getCharCount() * (11 / 2));
 	}
 	}
 
 
 	/**
 	/**
-	 * @inheritdoc
+	 * @inheritDoc
 	 */
 	 */
 	public static function validateString(string $string):bool{
 	public static function validateString(string $string):bool{
 
 
 		foreach(str_split($string) as $chr){
 		foreach(str_split($string) as $chr){
-			if(!isset(self::CHAR_MAP_ALPHANUM[$chr])){
+			if(!isset(self::CHAR_TO_ORD[$chr])){
 				return false;
 				return false;
 			}
 			}
 		}
 		}
@@ -60,7 +63,7 @@ final class AlphaNum extends QRDataModeAbstract{
 	}
 	}
 
 
 	/**
 	/**
-	 * @inheritdoc
+	 * @inheritDoc
 	 */
 	 */
 	public function write(BitBuffer $bitBuffer, int $versionNumber):void{
 	public function write(BitBuffer $bitBuffer, int $versionNumber):void{
 		$len = $this->getCharCount();
 		$len = $this->getCharCount();
@@ -87,23 +90,23 @@ final class AlphaNum extends QRDataModeAbstract{
 	 *
 	 *
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException on an illegal character occurence
 	 * @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
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
 	 */
 	public static function decodeSegment(BitBuffer $bitBuffer, int $versionNumber):string{
 	public static function decodeSegment(BitBuffer $bitBuffer, int $versionNumber):string{
 		$length  = $bitBuffer->read(Mode::getLengthBitsForVersion(self::$datamode, $versionNumber));
 		$length  = $bitBuffer->read(Mode::getLengthBitsForVersion(self::$datamode, $versionNumber));
-		$charmap = array_flip(self::CHAR_MAP_ALPHANUM);
+		$charmap = array_flip(self::CHAR_TO_ORD);
 
 
 		// @todo
 		// @todo
 		$toAlphaNumericChar = function(int $ord) use ($charmap):string{
 		$toAlphaNumericChar = function(int $ord) use ($charmap):string{

+ 7 - 4
src/Data/Byte.php

@@ -22,24 +22,27 @@ use function ord;
  */
  */
 final class Byte extends QRDataModeAbstract{
 final class Byte extends QRDataModeAbstract{
 
 
+	/**
+	 * @inheritDoc
+	 */
 	protected static int $datamode = Mode::DATA_BYTE;
 	protected static int $datamode = Mode::DATA_BYTE;
 
 
 	/**
 	/**
-	 * @inheritdoc
+	 * @inheritDoc
 	 */
 	 */
 	public function getLengthInBits():int{
 	public function getLengthInBits():int{
 		return $this->getCharCount() * 8;
 		return $this->getCharCount() * 8;
 	}
 	}
 
 
 	/**
 	/**
-	 * @inheritdoc
+	 * @inheritDoc
 	 */
 	 */
 	public static function validateString(string $string):bool{
 	public static function validateString(string $string):bool{
 		return !empty($string);
 		return !empty($string);
 	}
 	}
 
 
 	/**
 	/**
-	 * @inheritdoc
+	 * @inheritDoc
 	 */
 	 */
 	public function write(BitBuffer $bitBuffer, int $versionNumber):void{
 	public function write(BitBuffer $bitBuffer, int $versionNumber):void{
 		$len = $this->getCharCount();
 		$len = $this->getCharCount();
@@ -59,7 +62,7 @@ final class Byte extends QRDataModeAbstract{
 	}
 	}
 
 
 	/**
 	/**
-	 * @inheritdoc
+	 * @inheritDoc
 	 *
 	 *
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
 	 */

+ 4 - 1
src/Data/ECI.php

@@ -19,6 +19,9 @@ use chillerlan\QRCode\Common\{BitBuffer, ECICharset, Mode};
  */
  */
 final class ECI extends QRDataModeAbstract{
 final class ECI extends QRDataModeAbstract{
 
 
+	/**
+	 * @inheritDoc
+	 */
 	protected static int $datamode = Mode::DATA_ECI;
 	protected static int $datamode = Mode::DATA_ECI;
 
 
 	/**
 	/**
@@ -41,7 +44,7 @@ final class ECI extends QRDataModeAbstract{
 		return 8;
 		return 8;
 	}
 	}
 
 
-		/**
+	/**
 	 * @inheritDoc
 	 * @inheritDoc
 	 */
 	 */
 	public function write(BitBuffer $bitBuffer, int $versionNumber):void{
 	public function write(BitBuffer $bitBuffer, int $versionNumber):void{

+ 7 - 5
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{
 final class Kanji extends QRDataModeAbstract{
 
 
+	/**
+	 * @inheritDoc
+	 */
 	protected static int $datamode = Mode::DATA_KANJI;
 	protected static int $datamode = Mode::DATA_KANJI;
 
 
 	/**
 	/**
@@ -30,19 +33,18 @@ final class Kanji extends QRDataModeAbstract{
 	public function __construct(string $data){
 	public function __construct(string $data){
 		parent::__construct($data);
 		parent::__construct($data);
 
 
-		/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
 		$this->data = mb_convert_encoding($this->data, 'SJIS', mb_detect_encoding($this->data));
 		$this->data = mb_convert_encoding($this->data, 'SJIS', mb_detect_encoding($this->data));
 	}
 	}
 
 
 	/**
 	/**
-	 * @inheritdoc
+	 * @inheritDoc
 	 */
 	 */
 	protected function getCharCount():int{
 	protected function getCharCount():int{
 		return mb_strlen($this->data, 'SJIS');
 		return mb_strlen($this->data, 'SJIS');
 	}
 	}
 
 
 	/**
 	/**
-	 * @inheritdoc
+	 * @inheritDoc
 	 */
 	 */
 	public function getLengthInBits():int{
 	public function getLengthInBits():int{
 		return $this->getCharCount() * 13;
 		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
 	 * @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
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
 	 */

+ 11 - 8
src/Data/Number.php

@@ -25,26 +25,29 @@ final class Number extends QRDataModeAbstract{
 	/**
 	/**
 	 * @var int[]
 	 * @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,
 		'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;
 	protected static int $datamode = Mode::DATA_NUMBER;
 
 
 	/**
 	/**
-	 * @inheritdoc
+	 * @inheritDoc
 	 */
 	 */
 	public function getLengthInBits():int{
 	public function getLengthInBits():int{
 		return (int)ceil($this->getCharCount() * (10 / 3));
 		return (int)ceil($this->getCharCount() * (10 / 3));
 	}
 	}
 
 
 	/**
 	/**
-	 * @inheritdoc
+	 * @inheritDoc
 	 */
 	 */
 	public static function validateString(string $string):bool{
 	public static function validateString(string $string):bool{
 
 
 		foreach(str_split($string) as $chr){
 		foreach(str_split($string) as $chr){
-			if(!isset(self::CHAR_MAP_NUMBER[$chr])){
+			if(!isset(self::NUMBER_TO_ORD[$chr])){
 				return false;
 				return false;
 			}
 			}
 		}
 		}
@@ -53,7 +56,7 @@ final class Number extends QRDataModeAbstract{
 	}
 	}
 
 
 	/**
 	/**
-	 * @inheritdoc
+	 * @inheritDoc
 	 */
 	 */
 	public function write(BitBuffer $bitBuffer, int $versionNumber):void{
 	public function write(BitBuffer $bitBuffer, int $versionNumber):void{
 		$len = $this->getCharCount();
 		$len = $this->getCharCount();
@@ -97,7 +100,7 @@ final class Number extends QRDataModeAbstract{
 		foreach(str_split($string) as $chr){
 		foreach(str_split($string) as $chr){
 			$c = ord($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));
 				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
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
 	 */
 	public static function decodeSegment(BitBuffer $bitBuffer, int $versionNumber):string{
 	public static function decodeSegment(BitBuffer $bitBuffer, int $versionNumber):string{
 		$length  = $bitBuffer->read(Mode::getLengthBitsForVersion(self::$datamode, $versionNumber));
 		$length  = $bitBuffer->read(Mode::getLengthBitsForVersion(self::$datamode, $versionNumber));
-		$charmap = array_flip(self::CHAR_MAP_NUMBER);
+		$charmap = array_flip(self::NUMBER_TO_ORD);
 
 
 		// @todo
 		// @todo
 		$toNumericChar = function(int $ord) use ($charmap):string{
 		$toNumericChar = function(int $ord) use ($charmap):string{

+ 3 - 3
src/Data/QRMatrix.php

@@ -13,7 +13,7 @@ namespace chillerlan\QRCode\Data;
 use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Version};
 use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Version};
 
 
 use SplFixedArray;
 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;
  * Holds a numerical representation of the final QR Code;
@@ -414,7 +414,7 @@ final class QRMatrix{
 		for($y = 0; $y < $this->moduleCount; $y++){
 		for($y = 0; $y < $this->moduleCount; $y++){
 			for($i = 0; $i < $size; $i++){
 			for($i = 0; $i < $size; $i++){
 				array_unshift($this->matrix[$y], $this::M_QUIETZONE);
 				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++){
 		for($i = 0; $i < $size; $i++){
 			array_unshift($this->matrix, $r);
 			array_unshift($this->matrix, $r);
-			array_push($this->matrix, $r);
+			$this->matrix[] = $r;
 		}
 		}
 
 
 		return $this;
 		return $this;

+ 3 - 3
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
 		// 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.
 		// some bits from reading as we wind through the bit matrix.
 		$dimension = $this->bitMatrix->getDimension();
 		$dimension = $this->bitMatrix->getDimension();
-		$this->bitMatrix->unmask($dimension, $formatInfo->getDataMask());
+		$this->bitMatrix->unmask($dimension, $formatInfo->getMaskPattern());
 		$functionPattern = $this->bitMatrix->buildFunctionPattern($version);
 		$functionPattern = $this->bitMatrix->buildFunctionPattern($version);
 
 
 		$readingUp    = true;
 		$readingUp    = true;
@@ -189,8 +189,8 @@ final class BitMatrixParser{
 		// Should return null, but, some QR codes apparently do not mask this info.
 		// Should return null, but, some QR codes apparently do not mask this info.
 		// Try again by actually masking the pattern first.
 		// Try again by actually masking the pattern first.
 		$this->parsedFormatInfo = $this->doDecodeFormatInformation(
 		$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){
 		if($this->parsedFormatInfo !== null){

+ 8 - 3
src/Output/QRFpdf.php

@@ -12,7 +12,6 @@
 namespace chillerlan\QRCode\Output;
 namespace chillerlan\QRCode\Output;
 
 
 use chillerlan\QRCode\Data\QRMatrix;
 use chillerlan\QRCode\Data\QRMatrix;
-use chillerlan\QRCode\QRCodeException;
 use chillerlan\Settings\SettingsContainerInterface;
 use chillerlan\Settings\SettingsContainerInterface;
 use FPDF;
 use FPDF;
 
 
@@ -26,12 +25,18 @@ use function array_values, class_exists, count, is_array;
  */
  */
 class QRFpdf extends QROutputAbstract{
 class QRFpdf extends QROutputAbstract{
 
 
+	/**
+	 * QRFpdf constructor.
+	 *
+	 * @throws \chillerlan\QRCode\Output\QRCodeOutputException
+	 */
 	public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){
 	public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){
 
 
 		if(!class_exists(FPDF::class)){
 		if(!class_exists(FPDF::class)){
 			// @codeCoverageIgnoreStart
 			// @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
 			// @codeCoverageIgnoreEnd
 		}
 		}

+ 4 - 4
src/Output/QRImage.php

@@ -13,7 +13,7 @@
 namespace chillerlan\QRCode\Output;
 namespace chillerlan\QRCode\Output;
 
 
 use chillerlan\QRCode\Data\QRMatrix;
 use chillerlan\QRCode\Data\QRMatrix;
-use chillerlan\QRCode\{QRCode, QRCodeException};
+use chillerlan\QRCode\QRCode;
 use chillerlan\Settings\SettingsContainerInterface;
 use chillerlan\Settings\SettingsContainerInterface;
 use Exception;
 use Exception;
 
 
@@ -51,12 +51,12 @@ class QRImage extends QROutputAbstract{
 	/**
 	/**
 	 * @inheritDoc
 	 * @inheritDoc
 	 *
 	 *
-	 * @throws \chillerlan\QRCode\QRCodeException
+	 * @throws \chillerlan\QRCode\Output\QRCodeOutputException
 	 */
 	 */
 	public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){
 	public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){
 
 
 		if(!extension_loaded('gd')){
 		if(!extension_loaded('gd')){
-			throw new QRCodeException('ext-gd not loaded'); // @codeCoverageIgnore
+			throw new QRCodeOutputException('ext-gd not loaded'); // @codeCoverageIgnore
 		}
 		}
 
 
 		parent::__construct($options, $matrix);
 		parent::__construct($options, $matrix);
@@ -95,7 +95,7 @@ class QRImage extends QROutputAbstract{
 
 
 		$this->image = imagecreatetruecolor($this->length, $this->length);
 		$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
 		// https://stackoverflow.com/a/10455217
 		$tbg        = $this->options->imageTransparencyBG;
 		$tbg        = $this->options->imageTransparencyBG;
 		/** @phan-suppress-next-line PhanParamTooFewInternalUnpack */
 		/** @phan-suppress-next-line PhanParamTooFewInternalUnpack */

+ 3 - 2
src/Output/QRImagick.php

@@ -13,7 +13,6 @@
 namespace chillerlan\QRCode\Output;
 namespace chillerlan\QRCode\Output;
 
 
 use chillerlan\QRCode\Data\QRMatrix;
 use chillerlan\QRCode\Data\QRMatrix;
-use chillerlan\QRCode\QRCodeException;
 use chillerlan\Settings\SettingsContainerInterface;
 use chillerlan\Settings\SettingsContainerInterface;
 use Imagick, ImagickDraw, ImagickPixel;
 use Imagick, ImagickDraw, ImagickPixel;
 
 
@@ -31,11 +30,13 @@ class QRImagick extends QROutputAbstract{
 
 
 	/**
 	/**
 	 * @inheritDoc
 	 * @inheritDoc
+	 *
+	 * @throws \chillerlan\QRCode\Output\QRCodeOutputException
 	 */
 	 */
 	public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){
 	public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){
 
 
 		if(!extension_loaded('imagick')){
 		if(!extension_loaded('imagick')){
-			throw new QRCodeException('ext-imagick not loaded'); // @codeCoverageIgnore
+			throw new QRCodeOutputException('ext-imagick not loaded'); // @codeCoverageIgnore
 		}
 		}
 
 
 		parent::__construct($options, $matrix);
 		parent::__construct($options, $matrix);

+ 2 - 2
src/Output/QRMarkup.php

@@ -24,8 +24,8 @@ class QRMarkup extends QROutputAbstract{
 	/**
 	/**
 	 * @see \sprintf()
 	 * @see \sprintf()
 	 */
 	 */
-	protected string $svgHeader = '<svg xmlns="http://www.w3.org/2000/svg" class="qr-svg %1$s" '.
-	                              'style="width: 100%%; height: auto;" viewBox="0 0 %2$d %2$d">';
+	protected string $svgHeader = '<svg xmlns="http://www.w3.org/2000/svg"'.
+	' class="qr-svg %1$s" style="width: 100%%; height: auto;" viewBox="0 0 %2$d %2$d">';
 
 
 	/**
 	/**
 	 * @inheritDoc
 	 * @inheritDoc

+ 0 - 2
src/Output/QROutputAbstract.php

@@ -115,8 +115,6 @@ abstract class QROutputAbstract implements QROutputInterface{
 
 
 	/**
 	/**
 	 * @inheritDoc
 	 * @inheritDoc
-	 *
-	 * @return mixed
 	 */
 	 */
 	public function dump(string $file = null){
 	public function dump(string $file = null){
 		$file ??= $this->options->cachefile;
 		$file ??= $this->options->cachefile;

+ 16 - 1
src/QRCode.php

@@ -116,6 +116,7 @@ class QRCode{
 	 */
 	 */
 	public function __construct(SettingsContainerInterface $options = null){
 	public function __construct(SettingsContainerInterface $options = null){
 		$this->options              = $options ?? new QROptions;
 		$this->options              = $options ?? new QROptions;
+		// i hate this
 		$this->luminanceSourceClass = $this->options->useImagickIfAvailable
 		$this->luminanceSourceClass = $this->options->useImagickIfAvailable
 			? IMagickLuminanceSource::class
 			? IMagickLuminanceSource::class
 			: GDLuminanceSource::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 8.3.6 - Mixing modes
 	 * ISO/IEC 18004:2000 Annex H - Optimisation of bit stream length
 	 * 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
 	 * 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));
 		$this->addSegment(new Number($data));
 
 
 		return $this;
 		return $this;
 	}
 	}
 
 
 	/**
 	/**
+	 * Adds an alphanumeric data segment
+	 *
 	 * ISO/IEC 18004:2000 8.3.3 - Alphanumeric Mode
 	 * ISO/IEC 18004:2000 8.3.3 - Alphanumeric Mode
 	 */
 	 */
 	public function addAlphaNumSegment(string $data):self{
 	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
 	 * ISO/IEC 18004:2000 8.3.5 - Kanji Mode
 	 */
 	 */
 	public function addKanjiSegment(string $data):self{
 	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
 	 * ISO/IEC 18004:2000 8.3.4 - 8-bit Byte Mode
 	 */
 	 */
 	public function addByteSegment(string $data):self{
 	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
 	 * ISO/IEC 18004:2000 8.3.1 - Extended Channel Interpretation (ECI) Mode
 	 */
 	 */
 	public function addEciDesignator(int $encoding):self{
 	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
 	 * i hate this somehow but i'll leave it for now
 	 *
 	 *
 	 * @throws \chillerlan\QRCode\QRCodeException
 	 * @throws \chillerlan\QRCode\QRCodeException

+ 1 - 3
src/QROptionsTrait.php

@@ -53,7 +53,7 @@ trait QROptionsTrait{
 	protected int $eccLevel = EccLevel::L;
 	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
 	 * [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
 	 * enables Imagick for the QR Code reader if the extension is available
-	 *
-	 * @codeCoverageIgnore
 	 */
 	 */
 	protected function set_useImagickIfAvailable(bool $useImagickIfAvailable):void{
 	protected function set_useImagickIfAvailable(bool $useImagickIfAvailable):void{
 		$this->useImagickIfAvailable = $useImagickIfAvailable && extension_loaded('imagick');
 		$this->useImagickIfAvailable = $useImagickIfAvailable && extension_loaded('imagick');

+ 0 - 6
tests/Common/BitBufferTest.php

@@ -42,10 +42,4 @@ final class BitBufferTest extends TestCase{
 		$this::assertSame(4, $this->bitBuffer->getLength());
 		$this::assertSame(4, $this->bitBuffer->getLength());
 	}
 	}
 
 
-	public function testClear():void{
-		$this->bitBuffer->clear();
-		$this::assertSame([], $this->bitBuffer->getBuffer());
-		$this::assertSame(0, $this->bitBuffer->getLength());
-	}
-
 }
 }

+ 1 - 1
tests/QRCodeReaderTest.php

@@ -89,7 +89,7 @@ class QRCodeReaderTest extends TestCase{
 		$byte     = 'https://smiley.codes/qrcode/';
 		$byte     = 'https://smiley.codes/qrcode/';
 
 
 		$qrcode = (new QRCode($options))
 		$qrcode = (new QRCode($options))
-			->addNumberSegment($numeric)
+			->addNumericSegment($numeric)
 			->addAlphaNumSegment($alphanum)
 			->addAlphaNumSegment($alphanum)
 			->addKanjiSegment($kanji)
 			->addKanjiSegment($kanji)
 			->addByteSegment($byte)
 			->addByteSegment($byte)