Przeglądaj źródła

:octocat: dependency update & phpstan happy

smiley 6 miesięcy temu
rodzic
commit
d65911ada9

+ 1 - 22
.idea/inspectionProfiles/Project_Default.xml

@@ -1,27 +1,6 @@
 <component name="InspectionProjectProfileManager">
   <profile version="1.0">
     <option name="myName" value="Project Default" />
-    <inspection_tool class="JSAccessibilityCheck" enabled="true" level="WARNING" enabled_by_default="true" editorAttributes="WARNING_ATTRIBUTES" />
-    <inspection_tool class="MessDetectorValidationInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
-    <inspection_tool class="PhpAssignmentInConditionInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
-    <inspection_tool class="PhpCSValidationInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
-    <inspection_tool class="PhpComposerExtensionStubsInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
-    <inspection_tool class="PhpDivisionByZeroInspection" enabled="true" level="WARNING" enabled_by_default="true" />
     <inspection_tool class="PhpInternalEntityUsedInspection" enabled="true" level="INFO" enabled_by_default="true" />
-    <inspection_tool class="PhpMethodOrClassCallIsNotCaseSensitiveInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
-    <inspection_tool class="PhpMissingDocCommentInspection" enabled="true" level="INFO" enabled_by_default="true" />
-    <inspection_tool class="PhpMissingParentCallMagicInspection" enabled="false" level="WARNING" enabled_by_default="false">
-      <option name="ENABLE_FOR_SLEEP" value="false" />
-      <option name="ENABLE_FOR_WAKEUP" value="false" />
-    </inspection_tool>
-    <inspection_tool class="PhpMultipleClassesDeclarationsInOneFile" enabled="true" level="WARNING" enabled_by_default="true" />
-    <inspection_tool class="PhpStatementHasEmptyBodyInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
-    <inspection_tool class="PhpUsageOfSilenceOperatorInspection" enabled="true" level="STFU!" enabled_by_default="true" />
-    <inspection_tool class="PhpVoidFunctionResultUsedInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
-    <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
-      <option name="processCode" value="true" />
-      <option name="processLiterals" value="true" />
-      <option name="processComments" value="true" />
-    </inspection_tool>
   </profile>
-</component>
+</component>

+ 3 - 3
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.",

+ 6 - 3
phpcs.xml.dist

@@ -143,8 +143,6 @@
 	<rule ref="Generic.ControlStructures.InlineControlStructure"/>
 	<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
 	<!--<rule ref="Generic.Formatting.MultipleStatementAlignment"/>-->
-	<rule ref="Generic.Formatting.NoSpaceAfterCast"/>
-	<rule ref="Generic.Functions.CallTimePassByReference"/>
 	<rule ref="Generic.NamingConventions.InterfaceNameSuffix"/>
 	<rule ref="Generic.NamingConventions.TraitNameSuffix"/>
 	<rule ref="Generic.PHP.BacktickOperator"/>
@@ -179,7 +177,6 @@
 
 
 	<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
-	<rule ref="Squiz.Classes.DuplicateProperty"/>
 	<rule ref="Squiz.Classes.LowercaseClassKeywords"/>
 	<rule ref="Squiz.Classes.SelfMemberReference"/>
 	<rule ref="Squiz.Commenting.DocCommentAlignment"/>
@@ -237,6 +234,12 @@
 		<exclude-pattern>examples</exclude-pattern>
 	</rule>
 
+	<rule ref="Generic.Formatting.SpaceAfterCast">
+		<properties>
+			<property name="spacing" value="0"/>
+		</properties>
+	</rule>
+
 	<rule ref="Generic.Formatting.SpaceAfterNot">
 		<properties>
 			<property name="spacing" value="0" />

+ 24 - 0
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

+ 7 - 1
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;
 	}
 
 }

+ 7 - 1
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;
 	}
 
 }

+ 7 - 1
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;
 	}
 
 }

+ 6 - 0
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;

+ 4 - 0
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)