Use some PHP typed properties

This commit is contained in:
the-djmaze 2022-11-03 14:54:52 +01:00
parent 39a827aa2e
commit d3b65afb35
3 changed files with 34 additions and 31 deletions

View file

@ -28,12 +28,15 @@ class QRCode
ERROR_CORRECT_LEVEL_Q = 3, // 25% ERROR_CORRECT_LEVEL_Q = 3, // 25%
ERROR_CORRECT_LEVEL_H = 2; // 30% ERROR_CORRECT_LEVEL_H = 2; // 30%
protected protected int $typeNumber = 1;
$typeNumber = 1,
$modules, protected array $modules;
$moduleCount,
$errorCorrectLevel = self::ERROR_CORRECT_LEVEL_H, protected int $moduleCount;
$qrDataList = [];
protected int $errorCorrectLevel = self::ERROR_CORRECT_LEVEL_H;
protected array $qrDataList = [];
public function __toString() : string public function __toString() : string
{ {
@ -91,7 +94,7 @@ class QRCode
return $this; return $this;
} }
public function addData($data, int $mode = 0) : void public function addData(string $data, int $mode = 0) : void
{ {
$this->qrDataList[] = new QRData($data, $mode); $this->qrDataList[] = new QRData($data, $mode);
} }
@ -246,7 +249,7 @@ class QRCode
$this->modules[$this->moduleCount - 8][8] = !$test; $this->modules[$this->moduleCount - 8][8] = !$test;
} }
protected function mapData(&$data, int $maskPattern) : void protected function mapData(array &$data, int $maskPattern) : void
{ {
$inc = -1; $inc = -1;
$row = $this->moduleCount - 1; $row = $this->moduleCount - 1;
@ -283,7 +286,7 @@ class QRCode
} }
} }
protected static function createBytes(&$buffer, &$rsBlocks) : array protected static function createBytes(QRBitBuffer $buffer, array &$rsBlocks) : array
{ {
$offset = 0; $offset = 0;
$maxDcCount = 0; $maxDcCount = 0;
@ -347,7 +350,7 @@ class QRCode
return $data; return $data;
} }
protected static function createData(int $typeNumber, int $errorCorrectLevel, $dataArray) : array protected static function createData(int $typeNumber, int $errorCorrectLevel, array $dataArray) : array
{ {
$rsBlocks = QRRSBlock::getRSBlocks($typeNumber, $errorCorrectLevel); $rsBlocks = QRRSBlock::getRSBlocks($typeNumber, $errorCorrectLevel);
$buffer = new QRBitBuffer(); $buffer = new QRBitBuffer();
@ -415,7 +418,7 @@ class QRCode
$this->makeImpl(false, $this->getBestMaskPattern()); $this->makeImpl(false, $this->getBestMaskPattern());
} }
public static function getMinimumQRCode($data, int $errorCorrectLevel) : self public static function getMinimumQRCode(string $data, int $errorCorrectLevel) : self
{ {
$qr = new QRCode(); $qr = new QRCode();
$qr->setErrorCorrectLevel($errorCorrectLevel); $qr->setErrorCorrectLevel($errorCorrectLevel);
@ -658,7 +661,7 @@ abstract class QRUtil {
return $lostPoint + \intval(\abs(100 * $darkCount / $moduleCount / $moduleCount - 50) * 10 / 5); return $lostPoint + \intval(\abs(100 * $darkCount / $moduleCount / $moduleCount - 50) * 10 / 5);
} }
static function getBCHTypeInfo($data) static function getBCHTypeInfo(int $data)
{ {
$d = $data << 10; $d = $data << 10;
$g15 = static::getBCHDigit(self::G15); $g15 = static::getBCHDigit(self::G15);
@ -672,7 +675,7 @@ abstract class QRUtil {
return (($data << 10) | $d) ^ self::G15_MASK; return (($data << 10) | $d) ^ self::G15_MASK;
} }
static function getBCHTypeNumber($data) static function getBCHTypeNumber(int $data)
{ {
$d = $data << 12; $d = $data << 12;
$g18 = static::getBCHDigit(self::G18); $g18 = static::getBCHDigit(self::G18);
@ -686,7 +689,7 @@ abstract class QRUtil {
return ($data << 12) | $d; return ($data << 12) | $d;
} }
protected static function getBCHDigit($data) : int protected static function getBCHDigit(int $data) : int
{ {
$digit = 0; $digit = 0;
while ($data != 0) { while ($data != 0) {
@ -703,8 +706,9 @@ abstract class QRUtil {
class QRRSBlock { class QRRSBlock {
protected $totalCount; protected int $totalCount;
protected $dataCount;
protected int $dataCount;
static $QR_RS_BLOCK_TABLE = [ static $QR_RS_BLOCK_TABLE = [
@ -1017,17 +1021,17 @@ class QRData
MODE_8BIT_BYTE = 4, MODE_8BIT_BYTE = 4,
MODE_KANJI = 8; MODE_KANJI = 8;
protected protected string $data;
$data,
$mode;
public function __construct($data, int $mode = 0) protected int $mode;
public function __construct(string $data, int $mode = 0)
{ {
$this->data = $data; $this->data = $data;
$this->mode = $mode ?: static::detectMode($data); $this->mode = $mode ?: static::detectMode($data);
} }
public function getData() public function getData() : string
{ {
return $this->data; return $this->data;
} }
@ -1044,7 +1048,7 @@ class QRData
return $this->mode; return $this->mode;
} }
public function getLengthInBits($type) : int public function getLengthInBits(int $type) : int
{ {
if (1 > $type || 40 < $type) { if (1 > $type || 40 < $type) {
throw new \OutOfBoundsException("Invalid type: {$type}"); throw new \OutOfBoundsException("Invalid type: {$type}");
@ -1089,7 +1093,7 @@ class QRData
} }
} }
public function write(&$buffer) : void public function write(QRBitBuffer $buffer) : void
{ {
$i = 0; $i = 0;
$data = $this->data; $data = $this->data;
@ -1247,9 +1251,9 @@ abstract class QRMath
class QRPolynomial { class QRPolynomial {
protected $num; protected array $num;
public function __construct($num, $shift = 0) public function __construct(array $num, int $shift = 0)
{ {
$offset = 0; $offset = 0;
$limit = \count($num); $limit = \count($num);
@ -1272,7 +1276,7 @@ class QRPolynomial {
return \count($this->num); return \count($this->num);
} }
public function multiply($e) : self public function multiply(self $e) : self
{ {
$tl = $this->getLength(); $tl = $this->getLength();
$el = $e->getLength(); $el = $e->getLength();
@ -1286,7 +1290,7 @@ class QRPolynomial {
return new static($num); return new static($num);
} }
public function mod($e) : self public function mod(self $e) : self
{ {
$tl = $this->getLength(); $tl = $this->getLength();
$el = $e->getLength(); $el = $e->getLength();
@ -1338,7 +1342,7 @@ class QRBitBuffer {
} }
} }
public function putBit($bit) : void public function putBit(bool $bit) : void
{ {
$bufIndex = (int)\floor($this->length / 8); $bufIndex = (int)\floor($this->length / 8);
if (\count($this->buffer) <= $bufIndex) { if (\count($this->buffer) <= $bufIndex) {

View file

@ -4,8 +4,7 @@ namespace SnappyMail;
abstract class SASL abstract class SASL
{ {
public public bool $base64 = false;
$base64 = false;
abstract public function authenticate(string $authcid, string $passphrase, ?string $authzid = null) : string; abstract public function authenticate(string $authcid, string $passphrase, ?string $authzid = null) : string;

View file

@ -5,7 +5,7 @@ namespace SnappyMail;
class TAR class TAR
{ {
public public
$toc, $alias,
$filename; $filename;
const dec = array( const dec = array(