mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-11-29 07:22:03 +00:00
:octocat: switch phan for phpstan (see #277)
This commit is contained in:
+15
-20
@@ -11,7 +11,7 @@
|
||||
namespace chillerlan\QRCode\Data;
|
||||
|
||||
use chillerlan\QRCode\Common\{BitBuffer, Mode};
|
||||
use function array_flip, ceil, intdiv, str_split, substr, unpack;
|
||||
use function ceil, intdiv, str_split, substr, unpack;
|
||||
|
||||
/**
|
||||
* Numeric mode: decimal digits 0 to 9
|
||||
@@ -28,6 +28,13 @@ final class Number extends QRDataModeAbstract{
|
||||
'0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private const ORD_TO_NUMBER = [
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
];
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -112,19 +119,7 @@ final class Number extends QRDataModeAbstract{
|
||||
* @throws \chillerlan\QRCode\Data\QRCodeDataException
|
||||
*/
|
||||
public static function decodeSegment(BitBuffer $bitBuffer, int $versionNumber):string{
|
||||
$length = $bitBuffer->read(self::getLengthBits($versionNumber));
|
||||
$charmap = array_flip(self::NUMBER_TO_ORD);
|
||||
|
||||
// @todo
|
||||
$toNumericChar = function(int $ord) use ($charmap):string{
|
||||
|
||||
if(isset($charmap[$ord])){
|
||||
return $charmap[$ord];
|
||||
}
|
||||
|
||||
throw new QRCodeDataException('invalid character value: '.$ord);
|
||||
};
|
||||
|
||||
$length = $bitBuffer->read(self::getLengthBits($versionNumber));
|
||||
$result = '';
|
||||
// Read three digits at a time
|
||||
while($length >= 3){
|
||||
@@ -139,9 +134,9 @@ final class Number extends QRDataModeAbstract{
|
||||
throw new QRCodeDataException('error decoding numeric value');
|
||||
}
|
||||
|
||||
$result .= $toNumericChar(intdiv($threeDigitsBits, 100));
|
||||
$result .= $toNumericChar(intdiv($threeDigitsBits, 10) % 10);
|
||||
$result .= $toNumericChar($threeDigitsBits % 10);
|
||||
$result .= self::ORD_TO_NUMBER[intdiv($threeDigitsBits, 100)];
|
||||
$result .= self::ORD_TO_NUMBER[(intdiv($threeDigitsBits, 10) % 10)];
|
||||
$result .= self::ORD_TO_NUMBER[($threeDigitsBits % 10)];
|
||||
|
||||
$length -= 3;
|
||||
}
|
||||
@@ -158,8 +153,8 @@ final class Number extends QRDataModeAbstract{
|
||||
throw new QRCodeDataException('error decoding numeric value');
|
||||
}
|
||||
|
||||
$result .= $toNumericChar(intdiv($twoDigitsBits, 10));
|
||||
$result .= $toNumericChar($twoDigitsBits % 10);
|
||||
$result .= self::ORD_TO_NUMBER[intdiv($twoDigitsBits, 10)];
|
||||
$result .= self::ORD_TO_NUMBER[($twoDigitsBits % 10)];
|
||||
}
|
||||
elseif($length === 1){
|
||||
// One digit left over to read
|
||||
@@ -173,7 +168,7 @@ final class Number extends QRDataModeAbstract{
|
||||
throw new QRCodeDataException('error decoding numeric value');
|
||||
}
|
||||
|
||||
$result .= $toNumericChar($digitBits);
|
||||
$result .= self::ORD_TO_NUMBER[$digitBits];
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
Reference in New Issue
Block a user