diff --git a/src/Data/AlphaNum.php b/src/Data/AlphaNum.php
index 95070a16f..c6d34e76f 100644
--- a/src/Data/AlphaNum.php
+++ b/src/Data/AlphaNum.php
@@ -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)));
}
}
diff --git a/src/Data/Kanji.php b/src/Data/Kanji.php
index 139b7d1a1..9faf4fc54 100644
--- a/src/Data/Kanji.php
+++ b/src/Data/Kanji.php
@@ -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));
}
}
diff --git a/src/Data/Number.php b/src/Data/Number.php
index a6ba0545a..976536462 100644
--- a/src/Data/Number.php
+++ b/src/Data/Number.php
@@ -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;
}
diff --git a/src/Data/QRDataAbstract.php b/src/Data/QRDataAbstract.php
index 307802c53..d4c66936d 100644
--- a/src/Data/QRDataAbstract.php
+++ b/src/Data/QRDataAbstract.php
@@ -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.
diff --git a/src/Helpers/Polynomial.php b/src/Helpers/Polynomial.php
index e0032f95c..abe11d0cc 100644
--- a/src/Helpers/Polynomial.php
+++ b/src/Helpers/Polynomial.php
@@ -14,7 +14,7 @@ namespace chillerlan\QRCode\Helpers;
use chillerlan\QRCode\QRCodeException;
-use function array_fill, count;
+use function array_fill, count, sprintf;
/**
* @link http://www.thonky.com/qr-code-tutorial/error-correction-coding
@@ -158,7 +158,7 @@ class Polynomial{
public function glog(int $n):int{
if($n < 1){
- throw new QRCodeException('log('.$n.')');
+ throw new QRCodeException(sprintf('log(%s)', $n));
}
return Polynomial::table[$n][1];
diff --git a/src/Output/QRImage.php b/src/Output/QRImage.php
index e5d62f677..4d8576117 100644
--- a/src/Output/QRImage.php
+++ b/src/Output/QRImage.php
@@ -17,7 +17,7 @@ use Exception;
use function array_values, base64_encode, call_user_func, count, imagecolorallocate, imagecolortransparent,
imagecreatetruecolor, imagedestroy, imagefilledrectangle, imagegif, imagejpeg, imagepng, in_array,
- is_array, ob_end_clean, ob_get_contents, ob_start, range;
+ is_array, ob_end_clean, ob_get_contents, ob_start, range, sprintf;
/**
* Converts the matrix into GD images, raw or base64 output
@@ -91,7 +91,7 @@ class QRImage extends QROutputAbstract{
$imageData = $this->dumpImage($file);
if((bool)$this->options->imageBase64){
- $imageData = 'data:image/'.$this->options->outputType.';base64,'.base64_encode($imageData);
+ $imageData = sprintf('data:image/%s;base64,%s', $this->options->outputType, base64_encode($imageData));
}
return $imageData;
diff --git a/src/Output/QRMarkup.php b/src/Output/QRMarkup.php
index db79ae2ae..4472d34c0 100644
--- a/src/Output/QRMarkup.php
+++ b/src/Output/QRMarkup.php
@@ -116,7 +116,7 @@ class QRMarkup extends QROutputAbstract{
if($count > 0){
$len = $count;
- $path .= 'M' .$start. ' ' .$y. ' h'.$len.' v1 h-'.$len.'Z ';
+ $path .= sprintf('M%s %s h%s v1 h-%sZ ', $start, $y, $len, $len);
// reset count
$count = 0;
@@ -128,7 +128,7 @@ class QRMarkup extends QROutputAbstract{
}
if(!empty($path)){
- $svg .= '';
+ $svg .= sprintf('', $M_TYPE, $this->options->cssClass, $value, $this->options->svgOpacity, $path);
}
}
diff --git a/src/Output/QROutputAbstract.php b/src/Output/QROutputAbstract.php
index 6dab31659..05c909e82 100644
--- a/src/Output/QROutputAbstract.php
+++ b/src/Output/QROutputAbstract.php
@@ -15,7 +15,7 @@ namespace chillerlan\QRCode\Output;
use chillerlan\QRCode\{Data\QRMatrix, QRCode};
use chillerlan\Settings\SettingsContainerInterface;
-use function call_user_func, dirname, file_put_contents, get_called_class, in_array, is_writable;
+use function call_user_func, dirname, file_put_contents, get_called_class, in_array, is_writable, sprintf;
/**
* common output abstract
@@ -103,7 +103,7 @@ abstract class QROutputAbstract implements QROutputInterface{
protected function saveToFile(string $data, string $file):bool{
if(!is_writable(dirname($file))){
- throw new QRCodeOutputException('Could not write data to cache file: '.$file);
+ throw new QRCodeOutputException(sprintf('Could not write data to cache file: %s', $file));
}
return (bool)file_put_contents($file, $data);
diff --git a/src/QROptionsTrait.php b/src/QROptionsTrait.php
index 8f8d72f35..40d935feb 100644
--- a/src/QROptionsTrait.php
+++ b/src/QROptionsTrait.php
@@ -12,7 +12,7 @@
namespace chillerlan\QRCode;
-use function array_values, count, is_array, is_numeric, max, min;
+use function array_values, count, is_array, is_numeric, max, min, sprintf;
trait QROptionsTrait{
@@ -284,7 +284,7 @@ trait QROptionsTrait{
protected function set_eccLevel(int $eccLevel):void{
if(!isset(QRCode::ECC_MODES[$eccLevel])){
- throw new QRCodeException('Invalid error correct level: '.$eccLevel);
+ throw new QRCodeException(sprintf('Invalid error correct level: %s', $eccLevel));
}
$this->eccLevel = $eccLevel;