summaryrefslogtreecommitdiff
path: root/vendor/chillerlan/php-qrcode/src/Data/Number.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/chillerlan/php-qrcode/src/Data/Number.php')
-rw-r--r--vendor/chillerlan/php-qrcode/src/Data/Number.php35
1 files changed, 15 insertions, 20 deletions
diff --git a/vendor/chillerlan/php-qrcode/src/Data/Number.php b/vendor/chillerlan/php-qrcode/src/Data/Number.php
index 3936d12c3..0a905b13e 100644
--- a/vendor/chillerlan/php-qrcode/src/Data/Number.php
+++ b/vendor/chillerlan/php-qrcode/src/Data/Number.php
@@ -4,7 +4,7 @@
*
* @filesource Number.php
* @created 26.11.2015
- * @package QRCode
+ * @package chillerlan\QRCode\Data
* @author Smiley <[email protected]>
* @copyright 2015 Smiley
* @license MIT
@@ -14,22 +14,19 @@ namespace chillerlan\QRCode\Data;
use chillerlan\QRCode\QRCode;
-use function ord, sprintf, substr;
+use function ord, sprintf, str_split, substr;
/**
- * Numeric mode: decimal digits 0 through 9
+ * Numeric mode: decimal digits 0 to 9
+ *
+ * ISO/IEC 18004:2000 Section 8.3.2
+ * ISO/IEC 18004:2000 Section 8.4.2
*/
-class Number extends QRDataAbstract{
+final class Number extends QRDataAbstract{
- /**
- * @inheritdoc
- */
- protected $datamode = QRCode::DATA_NUMBER;
+ protected int $datamode = QRCode::DATA_NUMBER;
- /**
- * @inheritdoc
- */
- protected $lengthBits = [10, 12, 14];
+ protected array $lengthBits = [10, 12, 14];
/**
* @inheritdoc
@@ -56,20 +53,18 @@ class Number extends QRDataAbstract{
}
/**
- * @param string $string
+ * get the code for the given numeric string
*
- * @return int
- * @throws \chillerlan\QRCode\Data\QRCodeDataException
+ * @throws \chillerlan\QRCode\Data\QRCodeDataException on an illegal character occurence
*/
protected function parseInt(string $string):int{
$num = 0;
- $len = strlen($string);
- for($i = 0; $i < $len; $i++){
- $c = ord($string[$i]);
+ foreach(str_split($string) as $chr){
+ $c = ord($chr);
- if(!in_array($string[$i], $this::NUMBER_CHAR_MAP, true)){
- throw new QRCodeDataException(sprintf('illegal char: "%s" [%d]', $string[$i], $c));
+ if(!isset($this::CHAR_MAP_NUMBER[$chr])){
+ throw new QRCodeDataException(sprintf('illegal char: "%s" [%d]', $chr, $c));
}
$c = $c - 48; // ord('0')