diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 14c92c133..565a0381f 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -1,27 +1,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/composer.json b/composer.json
index a326c7b2f..2c829eb76 100644
--- a/composer.json
+++ b/composer.json
@@ -58,11 +58,11 @@
"phpbench/phpbench": "^1.4",
"phpunit/phpunit": "^11.5",
"phpmd/phpmd": "^2.15",
- "phpstan/phpstan": "^2.1.13",
+ "phpstan/phpstan": "^2.1.17",
"phpstan/phpstan-deprecation-rules": "^2.0",
"setasign/fpdf": "^1.8.6",
- "slevomat/coding-standard": "^8.15",
- "squizlabs/php_codesniffer": "^3.12"
+ "slevomat/coding-standard": "^8.19",
+ "squizlabs/php_codesniffer": "^3.13"
},
"suggest": {
"chillerlan/php-authenticator": "Yet another Google authenticator! Also creates URIs for mobile apps.",
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index da85100c6..955a8d288 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -143,8 +143,6 @@
-
-
@@ -179,7 +177,6 @@
-
@@ -237,6 +234,12 @@
examples
+
+
+
+
+
+
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index b1e51f079..7204ccc93 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -240,12 +240,36 @@ parameters:
count: 1
path: tests/Data/DataInterfaceTestAbstract.php
+ -
+ message: '#^Parameter \#1 \$data of class chillerlan\\QRCode\\Data\\Byte constructor expects string, string\|false given\.$#'
+ identifier: argument.type
+ count: 1
+ path: tests/Data/ECITest.php
+
-
message: '#^Parameter \#2 \$to_encoding of function mb_convert_encoding expects string, string\|null given\.$#'
identifier: argument.type
count: 1
path: tests/Data/ECITest.php
+ -
+ message: '#^Parameter \#1 \$string of function bin2hex expects string, string\|false given\.$#'
+ identifier: argument.type
+ count: 1
+ path: tests/Data/HanziTest.php
+
+ -
+ message: '#^Anonymous function should return string but returns string\|false\.$#'
+ identifier: return.type
+ count: 1
+ path: tests/Data/KanjiTest.php
+
+ -
+ message: '#^Parameter \#1 \$string of function bin2hex expects string, string\|false given\.$#'
+ identifier: argument.type
+ count: 1
+ path: tests/Data/KanjiTest.php
+
-
message: '#^Parameter \#1 \$blob of method chillerlan\\QRCode\\QRCode\:\:readFromBlob\(\) expects string, GdImage\|string given\.$#'
identifier: argument.type
diff --git a/src/Data/ECI.php b/src/Data/ECI.php
index 35a4e88ad..fd51ce6c2 100644
--- a/src/Data/ECI.php
+++ b/src/Data/ECI.php
@@ -151,7 +151,13 @@ final class ECI extends QRDataModeAbstract{
}
}
- return mb_convert_encoding($data, mb_internal_encoding(), $encoding);
+ $encoded = mb_convert_encoding($data, mb_internal_encoding(), $encoding);
+
+ if($encoded === false){
+ throw new QRCodeDataException('mb_convert_encoding() error'); // @codeCoverageIgnore
+ }
+
+ return $encoded;
}
}
diff --git a/src/Data/Hanzi.php b/src/Data/Hanzi.php
index a3ff758d9..5ed78be8c 100644
--- a/src/Data/Hanzi.php
+++ b/src/Data/Hanzi.php
@@ -188,7 +188,13 @@ final class Hanzi extends QRDataModeAbstract{
$length--;
}
- return mb_convert_encoding(implode('', $buffer), mb_internal_encoding(), self::ENCODING);
+ $encoded = mb_convert_encoding(implode('', $buffer), mb_internal_encoding(), self::ENCODING);
+
+ if($encoded === false){
+ throw new QRCodeDataException('mb_convert_encoding() error'); // @codeCoverageIgnore
+ }
+
+ return $encoded;
}
}
diff --git a/src/Data/Kanji.php b/src/Data/Kanji.php
index bd3054cf4..6c959d872 100644
--- a/src/Data/Kanji.php
+++ b/src/Data/Kanji.php
@@ -174,7 +174,13 @@ final class Kanji extends QRDataModeAbstract{
$length--;
}
- return mb_convert_encoding(implode('', $buffer), mb_internal_encoding(), self::ENCODING);
+ $encoded = mb_convert_encoding(implode('', $buffer), mb_internal_encoding(), self::ENCODING);
+
+ if($encoded === false){
+ throw new QRCodeDataException('mb_convert_encoding() error'); // @codeCoverageIgnore
+ }
+
+ return $encoded;
}
}
diff --git a/src/Decoder/Decoder.php b/src/Decoder/Decoder.php
index 0fab160b9..3661b682c 100644
--- a/src/Decoder/Decoder.php
+++ b/src/Decoder/Decoder.php
@@ -33,6 +33,12 @@ final class Decoder{
private EccLevel|null $eccLevel = null;
private MaskPattern|null $maskPattern = null;
private BitBuffer $bitBuffer;
+ /** @noinspection PhpPropertyOnlyWrittenInspection (currently unused) */
+ private SettingsContainerInterface|QROptions $options;
+ private Version|null $version = null;
+ private EccLevel|null $eccLevel = null;
+ private MaskPattern|null $maskPattern = null;
+ private BitBuffer $bitBuffer;
public function __construct(SettingsContainerInterface|QROptions $options = new QROptions){
$this->options = $options;
diff --git a/src/QRCode.php b/src/QRCode.php
index 7643c8bf1..43fc6b23b 100755
--- a/src/QRCode.php
+++ b/src/QRCode.php
@@ -262,6 +262,10 @@ class QRCode{
if($eciCharsetName !== null){
$data = mb_convert_encoding($data, $eciCharsetName, mb_internal_encoding());
+ if($data === false){
+ throw new QRCodeException('mb_convert_encoding() error'); // @codeCoverageIgnore
+ }
+
return $this
->addEciDesignator($eciCharset->getID())
->addByteSegment($data)