mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-10-18 17:55:34 +00:00
🚿 sprintf'd some things
This commit is contained in:
@@ -14,7 +14,7 @@ namespace chillerlan\QRCode\Data;
|
||||
|
||||
use chillerlan\QRCode\QRCode;
|
||||
|
||||
use function array_search, ord;
|
||||
use function array_search, ord, sprintf;
|
||||
|
||||
/**
|
||||
* Alphanumeric mode: 0 to 9, A to Z, space, $ % * + - . / :
|
||||
@@ -59,7 +59,7 @@ class AlphaNum extends QRDataAbstract{
|
||||
return $i;
|
||||
}
|
||||
|
||||
throw new QRCodeDataException('illegal char: "'.$chr.'" ['.ord($chr).']');
|
||||
throw new QRCodeDataException(sprintf('illegal char: "%s" [%d]', $chr, ord($chr)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@ namespace chillerlan\QRCode\Data;
|
||||
|
||||
use chillerlan\QRCode\QRCode;
|
||||
|
||||
use function mb_strlen, ord, strlen;
|
||||
use function mb_strlen, ord, sprintf, strlen;
|
||||
|
||||
/**
|
||||
* Kanji mode: double-byte characters from the Shift JIS character set
|
||||
@@ -57,7 +57,7 @@ class Kanji extends QRDataAbstract{
|
||||
$c -= 0xC140;
|
||||
}
|
||||
else{
|
||||
throw new QRCodeDataException('illegal char at '.($i + 1).' ['.$c.']');
|
||||
throw new QRCodeDataException(sprintf('illegal char at %d [%d]', $i + 1, $c));
|
||||
}
|
||||
|
||||
$this->bitBuffer->put((($c >> 8) & 0xff) * 0xC0 + ($c & 0xff), 13);
|
||||
@@ -65,7 +65,7 @@ class Kanji extends QRDataAbstract{
|
||||
}
|
||||
|
||||
if($i < $len){
|
||||
throw new QRCodeDataException('illegal char at '.($i + 1));
|
||||
throw new QRCodeDataException(sprintf('illegal char at %d', $i + 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-5
@@ -14,7 +14,7 @@ namespace chillerlan\QRCode\Data;
|
||||
|
||||
use chillerlan\QRCode\QRCode;
|
||||
|
||||
use function substr;
|
||||
use function ord, sprintf, substr;
|
||||
|
||||
/**
|
||||
* Numeric mode: decimal digits 0 through 9
|
||||
@@ -68,14 +68,13 @@ class Number extends QRDataAbstract{
|
||||
|
||||
$len = strlen($string);
|
||||
for($i = 0; $i < $len; $i++){
|
||||
$c = \ord($string[$i]);
|
||||
$c = ord($string[$i]);
|
||||
|
||||
if(!in_array($string[$i], $this::NUMBER_CHAR_MAP, true)){
|
||||
throw new QRCodeDataException('illegal char: "'.$string[$i].'" ['.$c.']');
|
||||
throw new QRCodeDataException(sprintf('illegal char: "%s" [%d]', $string[$i], $c));
|
||||
}
|
||||
|
||||
$c = $c - \ord('0');
|
||||
|
||||
$c = $c - 48; // ord('0')
|
||||
$num = $num * 10 + $c;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ use chillerlan\QRCode\{QRCode, QRCodeException};
|
||||
use chillerlan\QRCode\Helpers\{BitBuffer, Polynomial};
|
||||
use chillerlan\Settings\SettingsContainerInterface;
|
||||
|
||||
use function array_fill, array_merge, count, max, range, strlen;
|
||||
use function array_fill, array_merge, count, max, mb_convert_encoding, mb_detect_encoding, range, sprintf, strlen;
|
||||
|
||||
/**
|
||||
* Processes the binary data and maps it on a matrix which is then being returned
|
||||
@@ -106,7 +106,7 @@ abstract class QRDataAbstract implements QRDataInterface{
|
||||
public function setData(string $data):QRDataInterface{
|
||||
|
||||
if($this->datamode === QRCode::DATA_KANJI){
|
||||
$data = \mb_convert_encoding($data, 'SJIS', \mb_detect_encoding($data));
|
||||
$data = mb_convert_encoding($data, 'SJIS', mb_detect_encoding($data));
|
||||
}
|
||||
|
||||
$this->strlen = $this->getLength($data);
|
||||
@@ -160,7 +160,7 @@ abstract class QRDataAbstract implements QRDataInterface{
|
||||
}
|
||||
}
|
||||
|
||||
throw new QRCodeDataException('invalid version number: '.$this->version);
|
||||
throw new QRCodeDataException(sprintf('invalid version number: %d', $this->version));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,7 +192,7 @@ abstract class QRDataAbstract implements QRDataInterface{
|
||||
}
|
||||
}
|
||||
|
||||
throw new QRCodeDataException('data exceeds '.$maxlength.' characters');
|
||||
throw new QRCodeDataException(sprintf('data exceeds %d characters', $maxlength));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,7 +227,7 @@ abstract class QRDataAbstract implements QRDataInterface{
|
||||
|
||||
// there was an error writing the BitBuffer data, which is... unlikely.
|
||||
if($this->bitBuffer->length > $MAX_BITS){
|
||||
throw new QRCodeException('code length overflow. ('.$this->bitBuffer->length.' > '.$MAX_BITS.'bit)'); // @codeCoverageIgnore
|
||||
throw new QRCodeException(sprintf('code length overflow. (%d > %d bit)', $this->bitBuffer->length, $MAX_BITS)); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// end code.
|
||||
|
||||
Reference in New Issue
Block a user