🚿 docblocks (WIP)

This commit is contained in:
codemasher
2021-11-18 13:32:46 +01:00
parent f7e5e2e806
commit 6a5be44ea4
18 changed files with 126 additions and 20 deletions
+9
View File
@@ -89,6 +89,9 @@ final class ECICharset{
private int $charsetID;
/**
*
*/
public function __construct(int $charsetID){
if(!array_key_exists($charsetID, self::MB_ENCODINGS)){
@@ -98,10 +101,16 @@ final class ECICharset{
$this->charsetID = $charsetID;
}
/**
*
*/
public function getID():int{
return $this->charsetID;
}
/**
*
*/
public function getName():?string{
return self::MB_ENCODINGS[$this->charsetID];
}
+9
View File
@@ -65,15 +65,24 @@ final class FormatInformation{
private int $errorCorrectionLevel;
private int $dataMask;
/**
*
*/
public function __construct(int $formatInfo){
$this->errorCorrectionLevel = ($formatInfo >> 3) & 0x03; // Bits 3,4
$this->dataMask = ($formatInfo & 0x07); // Bottom 3 bits
}
/**
*
*/
public function getErrorCorrectionLevel():EccLevel{
return new EccLevel($this->errorCorrectionLevel);
}
/**
*
*/
public function getDataMask():MaskPattern{
return new MaskPattern($this->dataMask);
}
-13
View File
@@ -117,9 +117,7 @@ final class GenericGFPoly{
}
/**
* @param \chillerlan\QRCode\Common\GenericGFPoly $other
*
* @return \chillerlan\QRCode\Common\GenericGFPoly
*/
public function multiply(GenericGFPoly $other):self{
@@ -139,8 +137,6 @@ final class GenericGFPoly{
}
/**
* @param \chillerlan\QRCode\Common\GenericGFPoly $other
*
* @return \chillerlan\QRCode\Common\GenericGFPoly[] [quotient, remainder]
*/
public function divide(GenericGFPoly $other):array{
@@ -167,9 +163,7 @@ final class GenericGFPoly{
}
/**
* @param int $scalar
*
* @return \chillerlan\QRCode\Common\GenericGFPoly
*/
public function multiplyInt(int $scalar):self{
@@ -191,10 +185,7 @@ final class GenericGFPoly{
}
/**
* @param int $degree
* @param int $coefficient
*
* @return \chillerlan\QRCode\Common\GenericGFPoly
*/
public function multiplyByMonomial(int $degree, int $coefficient):self{
@@ -216,9 +207,7 @@ final class GenericGFPoly{
}
/**
* @param \chillerlan\QRCode\Common\GenericGFPoly $other
*
* @return \chillerlan\QRCode\Common\GenericGFPoly
*/
public function mod(GenericGFPoly $other):self{
@@ -236,9 +225,7 @@ final class GenericGFPoly{
}
/**
* @param \chillerlan\QRCode\Common\GenericGFPoly $other
*
* @return \chillerlan\QRCode\Common\GenericGFPoly
*/
public function addOrSubtract(GenericGFPoly $other):self{
+3
View File
@@ -164,6 +164,9 @@ final class ReedSolomonDecoder{
return $result;
}
/**
*
*/
private function findErrorMagnitudes(GenericGFPoly $errorEvaluator, array $errorLocations):array{
// This is directly applying Forney's Formula
$s = count($errorLocations);
-1
View File
@@ -330,5 +330,4 @@ final class Version{
return self::TOTAL_CODEWORDS[$this->version];
}
}
+3
View File
@@ -24,6 +24,9 @@ final class Kanji extends QRDataModeAbstract{
protected static int $datamode = Mode::DATA_KANJI;
/**
*
*/
public function __construct(string $data){
parent::__construct($data);
+6
View File
@@ -47,6 +47,9 @@ final class Binarizer{
private LuminanceSource $source;
/**
*
*/
public function __construct(LuminanceSource $source){
$this->source = $source;
}
@@ -154,6 +157,9 @@ final class Binarizer{
return $this->getHistogramBlackMatrix($width, $height);
}
/**
*
*/
public function getHistogramBlackMatrix(int $width, int $height):BitMatrix{
$matrix = new BitMatrix(max($width, $height));
+6
View File
@@ -15,12 +15,18 @@ use chillerlan\QRCode\Common\{MaskPattern, Version};
use InvalidArgumentException;
use function array_fill, count;
/**
*
*/
final class BitMatrix{
private int $dimension;
private int $rowSize;
private array $bits;
/**
*
*/
public function __construct(int $dimension){
$this->dimension = $dimension;
$this->rowSize = ((int)(($this->dimension + 0x1f) / 0x20));
+9
View File
@@ -61,6 +61,9 @@ final class BitMatrixParser{
$this->bitMatrix->mirror();
}
/**
*
*/
private function copyBit(int $i, int $j, int $versionBits):int{
$bit = $this->mirror
@@ -335,6 +338,9 @@ final class BitMatrixParser{
return null;
}
/**
*
*/
public static function uRShift(int $a, int $b):int{
if($b === 0){
@@ -344,6 +350,9 @@ final class BitMatrixParser{
return ($a >> $b) & ~((1 << (8 * PHP_INT_SIZE - 1)) >> ($b - 1));
}
/**
*
*/
private static function numBitsDiffering(int $a, int $b):int{
// a now has a 1 bit exactly where its bit differs with b's
$a ^= $b;
+21
View File
@@ -29,6 +29,9 @@ final class DecoderResult{
private int $structuredAppendParity;
private int $structuredAppendSequenceNumber;
/**
*
*/
public function __construct(
array $rawBytes,
string $text,
@@ -59,26 +62,44 @@ final class DecoderResult{
return $this->text;
}
/**
*
*/
public function __toString():string{
return $this->text;
}
/**
*
*/
public function getVersion():Version{
return $this->version;
}
/**
*
*/
public function getEccLevel():EccLevel{
return $this->eccLevel;
}
/**
*
*/
public function hasStructuredAppend():bool{
return $this->structuredAppendParity >= 0 && $this->structuredAppendSequenceNumber >= 0;
}
/**
*
*/
public function getStructuredAppendParity():int{
return $this->structuredAppendParity;
}
/**
*
*/
public function getStructuredAppendSequenceNumber():int{
return $this->structuredAppendSequenceNumber;
}
+3
View File
@@ -52,6 +52,9 @@ final class GDLuminanceSource extends LuminanceSource{
$this->setLuminancePixels();
}
/**
*
*/
private function setLuminancePixels():void{
for($j = 0; $j < $this->height; $j++){
for($i = 0; $i < $this->width; $i++){
+3
View File
@@ -39,6 +39,9 @@ final class IMagickLuminanceSource extends LuminanceSource{
$this->setLuminancePixels();
}
/**
*
*/
private function setLuminancePixels():void{
$this->imagick->setImageColorspace(Imagick::COLORSPACE_GRAY);
$pixels = $this->imagick->exportImagePixels(1, 1, $this->width, $this->height, 'RGB', Imagick::PIXEL_CHAR);
+3
View File
@@ -29,6 +29,9 @@ abstract class LuminanceSource{
protected int $width;
protected int $height;
/**
*
*/
public function __construct(int $width, int $height){
$this->width = $width;
$this->height = $height;
+12
View File
@@ -24,12 +24,18 @@ final class FinderPattern extends ResultPoint{
private int $count;
/**
*
*/
public function __construct(float $posX, float $posY, float $estimatedModuleSize, int $count = null){
parent::__construct($posX, $posY, $estimatedModuleSize);
$this->count = $count ?? 1;
}
/**
*
*/
public function getCount():int{
return $this->count;
}
@@ -66,6 +72,9 @@ final class FinderPattern extends ResultPoint{
);
}
/**
*
*/
private static function squaredDistance(float $aX, float $aY, float $bX, float $bY):float{
$xDiff = $aX - $bX;
$yDiff = $aY - $bY;
@@ -73,6 +82,9 @@ final class FinderPattern extends ResultPoint{
return $xDiff * $xDiff + $yDiff * $yDiff;
}
/**
*
*/
public static function distance(float $aX, float $aY, float $bX, float $bY):float{
return sqrt(self::squaredDistance($aX, $aY, $bX, $bY));
}
-6
View File
@@ -187,8 +187,6 @@ final class FinderPatternFinder{
* figures the location of the center of this run.
*
* @param int[] $stateCount
*
* @return float
*/
private function centerFromEnd(array $stateCount, int $end):float{
return (float)(($end - $stateCount[4] - $stateCount[3]) - $stateCount[2] / 2.0);
@@ -196,8 +194,6 @@ final class FinderPatternFinder{
/**
* @param int[] $stateCount
*
* @return bool
*/
private function foundPatternCross(array $stateCount):bool{
// Allow less than 50% variance from 1-1-3-1-1 proportions
@@ -206,8 +202,6 @@ final class FinderPatternFinder{
/**
* @param int[] $stateCount
*
* @return bool
*/
private function foundPatternDiagonal(array $stateCount):bool{
// Allow less than 75% variance from 1-1-3-1-1 proportions
+21
View File
@@ -32,6 +32,9 @@ final class PerspectiveTransform{
private float $a32;
private float $a33;
/**
*
*/
private function set(
float $a11, float $a21, float $a31,
float $a12, float $a22, float $a32,
@@ -50,6 +53,9 @@ final class PerspectiveTransform{
return $this;
}
/**
*
*/
public function quadrilateralToQuadrilateral(
float $x0, float $y0, float $x1, float $y1, float $x2, float $y2, float $x3, float $y3,
float $x0p, float $y0p, float $x1p, float $y1p, float $x2p, float $y2p, float $x3p, float $y3p
@@ -59,6 +65,9 @@ final class PerspectiveTransform{
->times($this->quadrilateralToSquare($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3));
}
/**
*
*/
private function quadrilateralToSquare(
float $x0, float $y0, float $x1, float $y1,
float $x2, float $y2, float $x3, float $y3
@@ -69,6 +78,9 @@ final class PerspectiveTransform{
->buildAdjoint();
}
/**
*
*/
private function buildAdjoint():self{
// Adjoint is the transpose of the cofactor matrix:
return $this->set(
@@ -84,6 +96,9 @@ final class PerspectiveTransform{
);
}
/**
*
*/
private function squareToQuadrilateral(
float $x0, float $y0, float $x1, float $y1,
float $x2, float $y2, float $x3, float $y3
@@ -111,6 +126,9 @@ final class PerspectiveTransform{
);
}
/**
*
*/
private function times(PerspectiveTransform $other):self{
return $this->set(
$this->a11 * $other->a11 + $this->a21 * $other->a12 + $this->a31 * $other->a13,
@@ -125,6 +143,9 @@ final class PerspectiveTransform{
);
}
/**
*
*/
public function transformPoints(array &$xValues, array &$yValues = null):void{
$max = count($xValues);
+12
View File
@@ -25,20 +25,32 @@ abstract class ResultPoint{
protected float $y;
protected float $estimatedModuleSize;
/**
*
*/
public function __construct(float $x, float $y, float $estimatedModuleSize){
$this->x = $x;
$this->y = $y;
$this->estimatedModuleSize = $estimatedModuleSize;
}
/**
*
*/
public function getX():float{
return $this->x;
}
/**
*
*/
public function getY():float{
return $this->y;
}
/**
*
*/
public function getEstimatedModuleSize():float{
return $this->estimatedModuleSize;
}
+6
View File
@@ -17,10 +17,16 @@ use Imagick, InvalidArgumentException;
use chillerlan\QRCode\Decoder\{Decoder, DecoderResult, GDLuminanceSource, IMagickLuminanceSource};
use function extension_loaded, file_exists, file_get_contents, imagecreatefromstring, is_file, is_readable;
/**
*
*/
final class QRCodeReader{
private bool $useImagickIfAvailable;
/**
*
*/
public function __construct(bool $useImagickIfAvailable = true){
$this->useImagickIfAvailable = $useImagickIfAvailable && extension_loaded('imagick');
}