From 747a38dd302e6a39d54bb01b440205b3dd24a32c Mon Sep 17 00:00:00 2001 From: smiley Date: Sun, 17 Nov 2024 00:23:34 +0100 Subject: [PATCH] :octocat: phpstan 2.0 --- composer.json | 4 +- phpstan-baseline.neon | 123 +++++++++++++++++--------- src/Detector/PerspectiveTransform.php | 3 - src/QRCode.php | 2 - tests/QRMaxLengthTrait.php | 1 - 5 files changed, 84 insertions(+), 49 deletions(-) diff --git a/composer.json b/composer.json index 5718505eb..90302cd2a 100644 --- a/composer.json +++ b/composer.json @@ -58,8 +58,8 @@ "phpbench/phpbench": "^1.3", "phpunit/phpunit": "^11.3", "phpmd/phpmd": "^2.15", - "phpstan/phpstan": "^1.12", - "phpstan/phpstan-deprecation-rules": "^1.2", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-deprecation-rules": "^2.0", "setasign/fpdf": "^1.8.2", "slevomat/coding-standard": "^8.15", "squizlabs/php_codesniffer": "^3.10" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index efe744fdf..7e242a83e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,206 +1,247 @@ parameters: ignoreErrors: - - message: "#^Property chillerlan\\\\QRCodeBenchmark\\\\DecoderBenchmark\\:\\:\\$imageBlob \\(string\\) does not accept GdImage\\|string\\.$#" + message: '#^Property chillerlan\\QRCodeBenchmark\\DecoderBenchmark\:\:\$imageBlob \(string\) does not accept GdImage\|string\.$#' + identifier: assign.propertyType count: 1 path: benchmark/DecoderBenchmark.php - - message: "#^Parameter \\#1 \\$segment of method chillerlan\\\\QRCode\\\\QRCode\\:\\:addSegment\\(\\) expects chillerlan\\\\QRCode\\\\Data\\\\QRDataModeInterface, object given\\.$#" + message: '#^Parameter \#1 \$segment of method chillerlan\\QRCode\\QRCode\:\:addSegment\(\) expects chillerlan\\QRCode\\Data\\QRDataModeInterface, object given\.$#' + identifier: argument.type count: 1 path: benchmark/QRCodeBenchmark.php - - message: "#^Parameter \\#2 \\$dataSegments of class chillerlan\\\\QRCode\\\\Data\\\\QRData constructor expects array\\, array\\ given\\.$#" + message: '#^Parameter \#2 \$dataSegments of class chillerlan\\QRCode\\Data\\QRData constructor expects array\, array\ given\.$#' + identifier: argument.type count: 2 path: benchmark/QRDataBenchmark.php - - message: "#^Parameter \\#1 \\$string of function strtolower expects string, int\\|string given\\.$#" + message: '#^Parameter \#1 \$string of function strtolower expects string, int\|string given\.$#' + identifier: argument.type count: 1 path: benchmark/generate-markdown.php - - message: "#^Offset 'name' does not exist on array\\\\.$#" + message: '#^Offset ''name'' does not exist on array\\.$#' + identifier: offsetAccess.notFound count: 1 path: benchmark/parse-common.php - - message: "#^Offset 'results' does not exist on array\\\\.$#" + message: '#^Offset ''results'' does not exist on array\\.$#' + identifier: offsetAccess.notFound count: 1 path: benchmark/parse-common.php - - message: "#^Offset 0 does not exist on array\\{\\}\\.$#" + message: '#^Offset 0 does not exist on array\{\}\.$#' + identifier: offsetAccess.notFound count: 1 path: benchmark/parse-common.php - - message: "#^Function chillerlan\\\\QRCodeBenchmark\\\\parseLine\\(\\) return type has no value type specified in iterable type array\\.$#" + message: '#^Function chillerlan\\QRCodeBenchmark\\parseLine\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: benchmark/parse-result.php - - message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|false given\\.$#" + message: '#^Parameter \#1 \$string of function trim expects string, string\|false given\.$#' + identifier: argument.type count: 1 path: benchmark/parse-result.php - - message: "#^Property chillerlan\\\\QRCode\\\\QROptions\\:\\:\\$eccLevel \\(int\\) does not accept string\\.$#" + message: '#^Property chillerlan\\QRCode\\QROptions\:\:\$eccLevel \(int\) does not accept string\.$#' + identifier: assign.propertyType count: 1 path: examples/custom_output.php - - message: "#^Parameter \\#1 \\$width of function imagecreatetruecolor expects int\\<1, max\\>, int given\\.$#" + message: '#^Parameter \#1 \$width of function imagecreatetruecolor expects int\<1, max\>, int given\.$#' + identifier: argument.type count: 1 path: examples/imageWithText.php - - message: "#^Parameter \\#2 \\$color of function imagecolortransparent expects int\\|null, int\\<0, max\\>\\|false given\\.$#" + message: '#^Parameter \#2 \$color of function imagecolortransparent expects int\|null, int\<0, max\>\|false given\.$#' + identifier: argument.type count: 1 path: examples/imageWithText.php - - message: "#^Parameter \\#2 \\$height of function imagecreatetruecolor expects int\\<1, max\\>, int given\\.$#" + message: '#^Parameter \#2 \$height of function imagecreatetruecolor expects int\<1, max\>, int given\.$#' + identifier: argument.type count: 1 path: examples/imageWithText.php - - message: "#^Parameter \\#6 \\$color of function imagechar expects int, int\\<0, max\\>\\|false given\\.$#" + message: '#^Parameter \#6 \$color of function imagechar expects int, int\<0, max\>\|false given\.$#' + identifier: argument.type count: 1 path: examples/imageWithText.php - - message: "#^Parameter \\#6 \\$color of function imagefilledrectangle expects int, int\\<0, max\\>\\|false given\\.$#" + message: '#^Parameter \#6 \$color of function imagefilledrectangle expects int, int\<0, max\>\|false given\.$#' + identifier: argument.type count: 1 path: examples/imageWithText.php - - message: "#^Parameter \\#1 \\(Intervention\\\\Image\\\\Interfaces\\\\ImageInterface\\|string\\) of echo cannot be converted to string\\.$#" + message: '#^Parameter \#1 \(Intervention\\Image\\Interfaces\\ImageInterface\|string\) of echo cannot be converted to string\.$#' + identifier: echo.nonString count: 1 path: examples/intervention-image.php - - message: "#^Method RandomDotsSVGOutput\\:\\:collectModules\\(\\) should return array\\ but returns array\\\\>\\.$#" + message: '#^Method RandomDotsSVGOutput\:\:collectModules\(\) should return array\ but returns array\\>\.$#' + identifier: return.type count: 1 path: examples/svgRandomColoredDots.php - - message: "#^Method RoundQuietzoneSVGoutput\\:\\:collectModules\\(\\) should return array\\ but returns array\\\\>\\.$#" + message: '#^Method RoundQuietzoneSVGoutput\:\:collectModules\(\) should return array\ but returns array\\>\.$#' + identifier: return.type count: 1 path: examples/svgRoundQuietzone.php - - message: "#^Parameter \\#1 \\$data of function imagecreatefromstring expects string, string\\|false given\\.$#" + message: '#^Parameter \#1 \$data of function imagecreatefromstring expects string, string\|false given\.$#' + identifier: argument.type count: 1 path: src/Common/GDLuminanceSource.php - - message: "#^Parameter \\#1 \\$gdImage of class chillerlan\\\\QRCode\\\\Common\\\\GDLuminanceSource constructor expects GdImage, GdImage\\|false given\\.$#" + message: '#^Parameter \#1 \$gdImage of class chillerlan\\QRCode\\Common\\GDLuminanceSource constructor expects GdImage, GdImage\|false given\.$#' + identifier: argument.type count: 2 path: src/Common/GDLuminanceSource.php - - message: "#^Parameter \\#2 \\$color of function imagecolorsforindex expects int, int\\<0, max\\>\\|false given\\.$#" + message: '#^Parameter \#2 \$color of function imagecolorsforindex expects int, int\<0, max\>\|false given\.$#' + identifier: argument.type count: 1 path: src/Common/GDLuminanceSource.php - - message: "#^Parameter \\#1 \\$maskPattern of class chillerlan\\\\QRCode\\\\Common\\\\MaskPattern constructor expects int, int\\|false given\\.$#" + message: '#^Parameter \#1 \$maskPattern of class chillerlan\\QRCode\\Common\\MaskPattern constructor expects int, int\|false given\.$#' + identifier: argument.type count: 1 path: src/Common/MaskPattern.php - - message: "#^Method chillerlan\\\\QRCode\\\\Common\\\\Version\\:\\:getRSBlocks\\(\\) return type has no value type specified in iterable type array\\.$#" + message: '#^Method chillerlan\\QRCode\\Common\\Version\:\:getRSBlocks\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: src/Common/Version.php - - message: "#^Parameter \\#1 \\$encoding of function mb_detect_order expects non\\-empty\\-list\\\\|non\\-falsy\\-string\\|null, array\\{string, 'UTF\\-8', 'GB2312', 'GB18030', 'CP936', 'EUC\\-CN', 'HZ'\\} given\\.$#" + message: '#^Parameter \#1 \$encoding of function mb_detect_order expects non\-empty\-list\\|non\-falsy\-string\|null, array\{string, ''UTF\-8'', ''GB2312'', ''GB18030'', ''CP936'', ''EUC\-CN'', ''HZ''\} given\.$#' + identifier: argument.type count: 1 path: src/Data/Hanzi.php - - message: "#^Parameter \\#1 \\$encoding of function mb_detect_order expects non\\-empty\\-list\\\\|non\\-falsy\\-string\\|null, array\\{string, 'UTF\\-8', 'SJIS', 'SJIS\\-2004'\\} given\\.$#" + message: '#^Parameter \#1 \$encoding of function mb_detect_order expects non\-empty\-list\\|non\-falsy\-string\|null, array\{string, ''UTF\-8'', ''SJIS'', ''SJIS\-2004''\} given\.$#' + identifier: argument.type count: 1 path: src/Data/Kanji.php - - message: "#^Parameter \\#1 \\$version of class chillerlan\\\\QRCode\\\\Data\\\\ReedSolomonEncoder constructor expects chillerlan\\\\QRCode\\\\Common\\\\Version, chillerlan\\\\QRCode\\\\Common\\\\Version\\|null given\\.$#" + message: '#^Parameter \#1 \$version of class chillerlan\\QRCode\\Data\\ReedSolomonEncoder constructor expects chillerlan\\QRCode\\Common\\Version, chillerlan\\QRCode\\Common\\Version\|null given\.$#' + identifier: argument.type count: 1 path: src/Data/QRMatrix.php - - message: "#^Parameter \\#2 \\$eccLevel of class chillerlan\\\\QRCode\\\\Data\\\\ReedSolomonEncoder constructor expects chillerlan\\\\QRCode\\\\Common\\\\EccLevel, chillerlan\\\\QRCode\\\\Common\\\\EccLevel\\|null given\\.$#" + message: '#^Parameter \#2 \$eccLevel of class chillerlan\\QRCode\\Data\\ReedSolomonEncoder constructor expects chillerlan\\QRCode\\Common\\EccLevel, chillerlan\\QRCode\\Common\\EccLevel\|null given\.$#' + identifier: argument.type count: 1 path: src/Data/QRMatrix.php - - message: "#^Parameter \\#1 \\$maskPattern of method chillerlan\\\\QRCode\\\\Data\\\\QRMatrix\\:\\:mask\\(\\) expects chillerlan\\\\QRCode\\\\Common\\\\MaskPattern, chillerlan\\\\QRCode\\\\Common\\\\MaskPattern\\|null given\\.$#" + message: '#^Parameter \#1 \$maskPattern of method chillerlan\\QRCode\\Data\\QRMatrix\:\:mask\(\) expects chillerlan\\QRCode\\Common\\MaskPattern, chillerlan\\QRCode\\Common\\MaskPattern\|null given\.$#' + identifier: argument.type count: 1 path: src/Decoder/BitMatrix.php - - message: "#^Parameter \\#1 \\$version of class chillerlan\\\\QRCode\\\\Data\\\\QRMatrix constructor expects chillerlan\\\\QRCode\\\\Common\\\\Version, chillerlan\\\\QRCode\\\\Common\\\\Version\\|null given\\.$#" + message: '#^Parameter \#1 \$version of class chillerlan\\QRCode\\Data\\QRMatrix constructor expects chillerlan\\QRCode\\Common\\Version, chillerlan\\QRCode\\Common\\Version\|null given\.$#' + identifier: argument.type count: 1 path: src/Decoder/BitMatrix.php - - message: "#^Parameter \\#2 \\$b of method chillerlan\\\\QRCode\\\\Decoder\\\\BitMatrix\\:\\:numBitsDiffering\\(\\) expects int, int\\|null given\\.$#" + message: '#^Parameter \#2 \$b of method chillerlan\\QRCode\\Decoder\\BitMatrix\:\:numBitsDiffering\(\) expects int, int\|null given\.$#' + identifier: argument.type count: 1 path: src/Decoder/BitMatrix.php - - message: "#^Parameter \\#2 \\$eccLevel of class chillerlan\\\\QRCode\\\\Data\\\\QRMatrix constructor expects chillerlan\\\\QRCode\\\\Common\\\\EccLevel, chillerlan\\\\QRCode\\\\Common\\\\EccLevel\\|null given\\.$#" + message: '#^Parameter \#2 \$eccLevel of class chillerlan\\QRCode\\Data\\QRMatrix constructor expects chillerlan\\QRCode\\Common\\EccLevel, chillerlan\\QRCode\\Common\\EccLevel\|null given\.$#' + identifier: argument.type count: 1 path: src/Decoder/BitMatrix.php - - message: "#^Property chillerlan\\\\QRCode\\\\Decoder\\\\Decoder\\:\\:\\$options is never read, only written\\.$#" + message: '#^Property chillerlan\\QRCode\\Decoder\\Decoder\:\:\$options is never read, only written\.$#' + identifier: property.onlyWritten count: 1 path: src/Decoder/Decoder.php - - message: "#^Method chillerlan\\\\QRCode\\\\Decoder\\\\ReedSolomonDecoder\\:\\:deinterleaveRawBytes\\(\\) return type has no value type specified in iterable type array\\.$#" + message: '#^Method chillerlan\\QRCode\\Decoder\\ReedSolomonDecoder\:\:deinterleaveRawBytes\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: src/Decoder/ReedSolomonDecoder.php - - message: "#^Parameter \\#1 \\$width of function imagecreatetruecolor expects int\\<1, max\\>, int given\\.$#" + message: '#^Parameter \#1 \$width of function imagecreatetruecolor expects int\<1, max\>, int given\.$#' + identifier: argument.type count: 1 path: src/Output/QRGdImage.php - - message: "#^Parameter \\#2 \\$height of function imagecreatetruecolor expects int\\<1, max\\>, int given\\.$#" + message: '#^Parameter \#2 \$height of function imagecreatetruecolor expects int\<1, max\>, int given\.$#' + identifier: argument.type count: 1 path: src/Output/QRGdImage.php - - message: "#^Method chillerlan\\\\QRCodeTest\\\\Common\\\\MaskPatternTest\\:\\:assertMask\\(\\) has parameter \\$expected with no value type specified in iterable type array\\.$#" + message: '#^Method chillerlan\\QRCodeTest\\Common\\MaskPatternTest\:\:assertMask\(\) has parameter \$expected with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: tests/Common/MaskPatternTest.php - - message: "#^Method chillerlan\\\\QRCodeTest\\\\Common\\\\MaskPatternTest\\:\\:maskPatternProvider\\(\\) return type has no value type specified in iterable type array\\.$#" + message: '#^Method chillerlan\\QRCodeTest\\Common\\MaskPatternTest\:\:maskPatternProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: tests/Common/MaskPatternTest.php - - message: "#^Method chillerlan\\\\QRCodeTest\\\\Common\\\\MaskPatternTest\\:\\:testMask\\(\\) has parameter \\$expected with no value type specified in iterable type array\\.$#" + message: '#^Method chillerlan\\QRCodeTest\\Common\\MaskPatternTest\:\:testMask\(\) has parameter \$expected with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: tests/Common/MaskPatternTest.php - - message: "#^Parameter \\#1 \\$string of static method chillerlan\\\\QRCode\\\\Data\\\\QRDataModeInterface\\:\\:validateString\\(\\) expects string, string\\|false given\\.$#" + message: '#^Parameter \#1 \$string of static method chillerlan\\QRCode\\Data\\QRDataModeInterface\:\:validateString\(\) expects string, string\|false given\.$#' + identifier: argument.type count: 1 path: tests/Data/DataInterfaceTestAbstract.php - - message: "#^Parameter \\#2 \\$to_encoding of function mb_convert_encoding expects string, string\\|null given\\.$#" + 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 \\$blob of method chillerlan\\\\QRCode\\\\QRCode\\:\\:readFromBlob\\(\\) expects string, GdImage\\|string given\\.$#" + message: '#^Parameter \#1 \$blob of method chillerlan\\QRCode\\QRCode\:\:readFromBlob\(\) expects string, GdImage\|string given\.$#' + identifier: argument.type count: 1 path: tests/Data/QRDataTest.php diff --git a/src/Detector/PerspectiveTransform.php b/src/Detector/PerspectiveTransform.php index 351f3c75f..07040115f 100644 --- a/src/Detector/PerspectiveTransform.php +++ b/src/Detector/PerspectiveTransform.php @@ -51,9 +51,6 @@ private function set( return $this; } - /** - * @SuppressWarnings(PHPMD.ExcessiveParameterList) - */ public function quadrilateralToQuadrilateral( float $x0, float $y0, float $x1, float $y1, float $x2, float $y2, float $x3, float $y3, float $x0p, float $y0p, float $x1p, float $y1p, float $x2p, float $y2p, float $x3p, float $y3p, diff --git a/src/QRCode.php b/src/QRCode.php index 318743ceb..7643c8bf1 100755 --- a/src/QRCode.php +++ b/src/QRCode.php @@ -6,8 +6,6 @@ * @author Smiley * @copyright 2015 Smiley * @license MIT - * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ declare(strict_types=1); diff --git a/tests/QRMaxLengthTrait.php b/tests/QRMaxLengthTrait.php index f8bf10871..93a41589a 100644 --- a/tests/QRMaxLengthTrait.php +++ b/tests/QRMaxLengthTrait.php @@ -102,7 +102,6 @@ public static function getMaxLengthForMode(int $mode, Version $version, EccLevel throw new QRCodeException('invalid $ecc'); } - /** @SuppressWarnings(PHPMD.UndefinedVariable) */ $maxlength = static::MAX_LENGTH[$ver][$dataMode][$ecc]; // Hanzi mode sets an additional 4 bit long subset identifier