mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-11-23 03:12:29 +00:00
:octocat: fix PHPCS config, add Slevomat rules
This commit is contained in:
+2
-12
@@ -27,7 +27,9 @@ final class AlphaNum extends QRDataModeAbstract{
|
||||
* @var int[]
|
||||
*/
|
||||
private const CHAR_TO_ORD = [
|
||||
// phpcs:ignore
|
||||
'0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7,
|
||||
// phpcs:ignore
|
||||
'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,
|
||||
'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31,
|
||||
@@ -47,21 +49,12 @@ final class AlphaNum extends QRDataModeAbstract{
|
||||
'+', '-', '.', '/', ':',
|
||||
];
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public const DATAMODE = Mode::ALPHANUM;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLengthInBits():int{
|
||||
return (int)ceil($this->getCharCount() * (11 / 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function validateString(string $string):bool{
|
||||
|
||||
if($string === ''){
|
||||
@@ -77,9 +70,6 @@ final class AlphaNum extends QRDataModeAbstract{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function write(BitBuffer $bitBuffer, int $versionNumber):static{
|
||||
$len = $this->getCharCount();
|
||||
|
||||
|
||||
@@ -21,28 +21,16 @@ use function chr, ord;
|
||||
*/
|
||||
final class Byte extends QRDataModeAbstract{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public const DATAMODE = Mode::BYTE;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLengthInBits():int{
|
||||
return ($this->getCharCount() * 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function validateString(string $string):bool{
|
||||
return $string !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function write(BitBuffer $bitBuffer, int $versionNumber):static{
|
||||
$len = $this->getCharCount();
|
||||
|
||||
|
||||
+2
-7
@@ -22,9 +22,6 @@ use function mb_convert_encoding, mb_detect_encoding, mb_internal_encoding, spri
|
||||
*/
|
||||
final class ECI extends QRDataModeAbstract{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public const DATAMODE = Mode::ECI;
|
||||
|
||||
/**
|
||||
@@ -34,6 +31,7 @@ final class ECI extends QRDataModeAbstract{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @throws \chillerlan\QRCode\Data\QRCodeDataException
|
||||
* @noinspection PhpMissingParentConstructorInspection
|
||||
*/
|
||||
public function __construct(int $encoding){
|
||||
@@ -45,9 +43,6 @@ final class ECI extends QRDataModeAbstract{
|
||||
$this->encoding = $encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLengthInBits():int{
|
||||
|
||||
if($this->encoding < 128){
|
||||
@@ -107,7 +102,7 @@ final class ECI extends QRDataModeAbstract{
|
||||
$id = ((($firstByte & 0b00011111) << 16) | $bitBuffer->read(16));
|
||||
}
|
||||
else{
|
||||
throw new QRCodeDataException(sprintf('error decoding ECI value first byte: %08b', $firstByte)); // @codeCoverageIgnore
|
||||
throw new QRCodeDataException(sprintf('error decoding ECI value first byte: %08b', $firstByte));// @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return new ECICharset($id);
|
||||
|
||||
@@ -43,28 +43,16 @@ final class Hanzi extends QRDataModeAbstract{
|
||||
*/
|
||||
public const GB2312_SUBSET = 0b0001;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public const DATAMODE = Mode::HANZI;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getCharCount():int{
|
||||
return mb_strlen($this->data, self::ENCODING);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLengthInBits():int{
|
||||
return ($this->getCharCount() * 13);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function convertEncoding(string $string):string{
|
||||
mb_detect_order([mb_internal_encoding(), 'UTF-8', 'GB2312', 'GB18030', 'CP936', 'EUC-CN', 'HZ']);
|
||||
|
||||
|
||||
@@ -36,28 +36,16 @@ final class Kanji extends QRDataModeAbstract{
|
||||
*/
|
||||
public const ENCODING = 'SJIS';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public const DATAMODE = Mode::KANJI;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getCharCount():int{
|
||||
return mb_strlen($this->data, self::ENCODING);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLengthInBits():int{
|
||||
return ($this->getCharCount() * 13);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function convertEncoding(string $string):string{
|
||||
mb_detect_order([mb_internal_encoding(), 'UTF-8', 'SJIS', 'SJIS-2004']);
|
||||
|
||||
|
||||
+10
-14
@@ -35,21 +35,12 @@ final class Number extends QRDataModeAbstract{
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
];
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public const DATAMODE = Mode::NUMBER;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLengthInBits():int{
|
||||
return (int)ceil($this->getCharCount() * (10 / 3));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function validateString(string $string):bool{
|
||||
|
||||
if($string === ''){
|
||||
@@ -65,9 +56,6 @@ final class Number extends QRDataModeAbstract{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function write(BitBuffer $bitBuffer, int $versionNumber):static{
|
||||
$len = $this->getCharCount();
|
||||
|
||||
@@ -102,12 +90,20 @@ final class Number extends QRDataModeAbstract{
|
||||
|
||||
/**
|
||||
* get the code for the given numeric string
|
||||
*
|
||||
* @throws \chillerlan\QRCode\Data\QRCodeDataException
|
||||
*/
|
||||
private function parseInt(string $string):int{
|
||||
$num = 0;
|
||||
|
||||
foreach(unpack('C*', $string) as $chr){
|
||||
$num = ($num * 10 + $chr - 48);
|
||||
$ords = unpack('C*', $string);
|
||||
|
||||
if($ords === false){
|
||||
throw new QRCodeDataException('unpack() error');
|
||||
}
|
||||
|
||||
foreach($ords as $ord){
|
||||
$num = ($num * 10 + $ord - 48);
|
||||
}
|
||||
|
||||
return $num;
|
||||
|
||||
+2
-2
@@ -208,7 +208,7 @@ final class QRData{
|
||||
/**
|
||||
* creates a BitBuffer and writes the string data to it
|
||||
*
|
||||
* @throws \chillerlan\QRCode\QRCodeException on data overflow
|
||||
* @throws \chillerlan\QRCode\Data\QRCodeDataException on data overflow
|
||||
*/
|
||||
private function writeBitBuffer():void{
|
||||
$MAX_BITS = $this->eccLevel->getMaxBitsForVersion($this->version);
|
||||
@@ -220,7 +220,7 @@ final class QRData{
|
||||
// overflow, likely caused due to invalid version setting
|
||||
if($this->bitBuffer->getLength() > $MAX_BITS){
|
||||
throw new QRCodeDataException(
|
||||
sprintf('code length overflow. (%d > %d bit)', $this->bitBuffer->getLength(), $MAX_BITS)
|
||||
sprintf('code length overflow. (%d > %d bit)', $this->bitBuffer->getLength(), $MAX_BITS),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,9 +44,6 @@ abstract class QRDataModeAbstract implements QRDataModeInterface{
|
||||
return strlen($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function convertEncoding(string $string):string{
|
||||
return $string;
|
||||
}
|
||||
|
||||
@@ -392,6 +392,7 @@ class QRMatrix{
|
||||
|
||||
foreach($pos as $c){
|
||||
$this
|
||||
// phpcs:ignore
|
||||
->setArea( $c[0] , $c[1] , 7, 7, true, $this::M_FINDER)
|
||||
->setArea(($c[0] + 1), ($c[1] + 1), 5, 5, false, $this::M_FINDER)
|
||||
->setArea(($c[0] + 2), ($c[1] + 2), 3, 3, true, $this::M_FINDER_DOT)
|
||||
@@ -422,6 +423,7 @@ class QRMatrix{
|
||||
|
||||
for($c = 0; $c < 3; $c++){
|
||||
for($i = 0; $i < 8; $i++){
|
||||
// phpcs:ignore
|
||||
$this->set( $h[$c][0] , ($h[$c][1] + $i), false, $this::M_SEPARATOR);
|
||||
$this->set(($v[$c][0] - $i), $v[$c][1] , false, $this::M_SEPARATOR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user