From 20cad01ca18d8117250a1319a4d496711880d243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Tue, 19 Nov 2024 12:14:33 -0300 Subject: [PATCH] Add PHPStan strict rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- composer.json | 6 +- phpstan-baseline.neon | 452 +++++++++++++++++++++++++++++++++++++++++- phpstan.neon.dist | 9 +- 3 files changed, 462 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index a30cc78..05829f4 100644 --- a/composer.json +++ b/composer.json @@ -37,8 +37,11 @@ }, "require-dev": { "phpmyadmin/coding-standard": "^3.0.0", + "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "^1.12", + "phpstan/phpstan-deprecation-rules": "^1.2", "phpstan/phpstan-phpunit": "^1.4", + "phpstan/phpstan-strict-rules": "^1.6", "phpunit/phpunit": "^8.5 || ^9.6 || ^10.5" }, "autoload": { @@ -54,7 +57,8 @@ "config":{ "sort-packages": true, "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true } } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2416aef..b77d939 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,130 @@ parameters: ignoreErrors: + - + message: "#^Cannot access offset 'DESC' on mixed\\.$#" + count: 3 + path: examples/create_shapefile.php + + - + message: "#^Cannot access offset 'ID' on mixed\\.$#" + count: 3 + path: examples/create_shapefile.php + + - + message: "#^Cannot access property \\$dbfData on mixed\\.$#" + count: 6 + path: examples/create_shapefile.php + + - + message: "#^Cannot access property \\$dbfData on mixed\\.$#" + count: 1 + path: examples/read.php + + - + message: "#^Cannot access property \\$shpData on mixed\\.$#" + count: 1 + path: examples/read.php + + - + message: "#^Foreach overwrites \\$i with its key variable\\.$#" + count: 1 + path: examples/read.php + + - + message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" + count: 2 + path: src/ShapeFile.php + + - + message: "#^Call to function is_array\\(\\) with array will always evaluate to true\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Cannot access offset string on mixed\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Cannot access property \\$dbfData on mixed\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Cannot access property \\$recordNumber on mixed\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Cannot call method getContentLength\\(\\) on mixed\\.$#" + count: 3 + path: src/ShapeFile.php + + - + message: "#^Cannot call method saveToFile\\(\\) on mixed\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Cannot call method updateDBFInfo\\(\\) on mixed\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:__construct\\(\\) has parameter \\$boundingBox with no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:getDBFHeader\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:getIndexFromDBFData\\(\\) should return int but returns \\(int\\|string\\)\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:loadDBFHeader\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:setDBFHeader\\(\\) has parameter \\$header with no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:updateBBox\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Only booleans are allowed in a negated boolean, resource\\|false given\\.$#" + count: 2 + path: src/ShapeFile.php + + - + message: "#^Only booleans are allowed in a negated boolean, resource\\|null given\\.$#" + count: 3 + path: src/ShapeFile.php + + - + message: "#^Only numeric types are allowed in \\+, int\\|null given on the left side\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Parameter \\#1 \\$character of function ord expects string, \\(string\\|false\\) given\\.$#" + count: 2 + path: src/ShapeFile.php + - message: "#^Parameter \\#1 \\$file of method PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:saveBBox\\(\\) expects resource, resource\\|null given\\.$#" count: 2 @@ -31,30 +156,70 @@ parameters: path: src/ShapeFile.php - - message: "#^Parameter \\#1 \\$str of function strtoupper expects string, mixed given\\.$#" + message: "#^Parameter \\#1 \\$haystack of function strpos expects string, \\(string\\|false\\) given\\.$#" count: 1 path: src/ShapeFile.php + - + message: "#^Parameter \\#1 \\$str of function strtoupper expects string, mixed given\\.$#" + count: 2 + path: src/ShapeFile.php + - message: "#^Parameter \\#1 \\$type of static method PhpMyAdmin\\\\ShapeFile\\\\Util\\:\\:nameShape\\(\\) expects int, int\\|false given\\.$#" count: 1 path: src/ShapeFile.php + - + message: "#^Parameter \\#1 \\$value of static method PhpMyAdmin\\\\ShapeFile\\\\Util\\:\\:packDouble\\(\\) expects float, mixed given\\.$#" + count: 1 + path: src/ShapeFile.php + - message: "#^Parameter \\#2 \\$length of function fread expects int\\<1, max\\>, int given\\.$#" count: 1 path: src/ShapeFile.php + - + message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:\\$boundingBox type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:\\$dbfFile \\(resource\\|null\\) does not accept mixed\\.$#" + count: 1 + path: src/ShapeFile.php + - message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:\\$dbfFile \\(resource\\|null\\) does not accept resource\\|false\\.$#" count: 2 path: src/ShapeFile.php + - + message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:\\$dbfHeader type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:\\$fileLength \\(int\\) does not accept \\(float\\|int\\)\\.$#" + count: 1 + path: src/ShapeFile.php + + - + message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:\\$records type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeFile.php + - message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:\\$shapeType \\(int\\|false\\) does not accept mixed\\.$#" count: 1 path: src/ShapeFile.php + - + message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:\\$shpFile \\(resource\\|null\\) does not accept mixed\\.$#" + count: 1 + path: src/ShapeFile.php + - message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\:\\:\\$shpFile \\(resource\\|null\\) does not accept resource\\|false\\.$#" count: 1 @@ -85,6 +250,136 @@ parameters: count: 1 path: src/ShapeFile.php + - + message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" + count: 4 + path: src/ShapeRecord.php + + - + message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" + count: 2 + path: src/ShapeRecord.php + + - + message: "#^Cannot access an offset on mixed\\.$#" + count: 4 + path: src/ShapeRecord.php + + - + message: "#^Cannot access offset 'points' on mixed\\.$#" + count: 15 + path: src/ShapeRecord.php + + - + message: "#^Cannot access offset 0 on mixed\\.$#" + count: 2 + path: src/ShapeRecord.php + + - + message: "#^Cannot access offset int on mixed\\.$#" + count: 12 + path: src/ShapeRecord.php + + - + message: "#^Cannot access offset int\\<\\-1, max\\> on mixed\\.$#" + count: 2 + path: src/ShapeRecord.php + + - + message: "#^Cannot access offset int\\<0, max\\> on mixed\\.$#" + count: 12 + path: src/ShapeRecord.php + + - + message: "#^Cannot access offset int\\<1, max\\> on mixed\\.$#" + count: 2 + path: src/ShapeRecord.php + + - + message: "#^Cannot access offset string on mixed\\.$#" + count: 4 + path: src/ShapeRecord.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:addPoint\\(\\) has parameter \\$point with no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:adjustBBox\\(\\) has parameter \\$point with no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:adjustPoint\\(\\) has parameter \\$point with no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:adjustPoint\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:fixPoint\\(\\) has parameter \\$point with no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:fixPoint\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:loadPoint\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:loadPointM\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:loadPointZ\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:savePoint\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:savePointM\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:savePointZ\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:updateDBFInfo\\(\\) has parameter \\$header with no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Parameter \\#1 \\$data of method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:savePoint\\(\\) expects array, mixed given\\.$#" + count: 2 + path: src/ShapeRecord.php + + - + message: "#^Parameter \\#1 \\$value of static method PhpMyAdmin\\\\ShapeFile\\\\Util\\:\\:packDouble\\(\\) expects float, mixed given\\.$#" + count: 11 + path: src/ShapeRecord.php + + - + message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#" + count: 16 + path: src/ShapeRecord.php + - message: "#^Parameter \\#2 \\$record_number of function dbase_get_record_with_names expects int, int\\|null given\\.$#" count: 1 @@ -95,6 +390,11 @@ parameters: count: 1 path: src/ShapeRecord.php + - + message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:\\$dbfData type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + - message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:\\$dbfFile \\(resource\\) in isset\\(\\) is not nullable\\.$#" count: 1 @@ -115,8 +415,158 @@ parameters: count: 1 path: src/ShapeRecord.php + - + message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:\\$shpData type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/ShapeRecord.php + + - + message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:\\$size \\(int\\) does not accept \\(float\\|int\\)\\.$#" + count: 1 + path: src/ShapeRecord.php + - message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:\\$size \\(int\\) does not accept mixed\\.$#" count: 1 path: src/ShapeRecord.php + - + message: "#^Casting to float something that's already float\\.$#" + count: 1 + path: src/Util.php + + - + message: "#^Method PhpMyAdmin\\\\ShapeFile\\\\Util\\:\\:nameShape\\(\\) should return string but returns mixed\\.$#" + count: 1 + path: src/Util.php + + - + message: "#^Property PhpMyAdmin\\\\ShapeFile\\\\Util\\:\\:\\$shapeNames type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/Util.php + + - + message: "#^Cannot access offset 'DESC' on mixed\\.$#" + count: 5 + path: tests/ShapeFileTest.php + + - + message: "#^Cannot access offset 'ID' on mixed\\.$#" + count: 5 + path: tests/ShapeFileTest.php + + - + message: "#^Cannot access offset 'numparts'\\|'numpoints' on mixed\\.$#" + count: 2 + path: tests/ShapeFileTest.php + + - + message: "#^Cannot access offset 'parts' on mixed\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Cannot access offset 0 on mixed\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Cannot access offset 1 on mixed\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Cannot access property \\$dbfData on mixed\\.$#" + count: 10 + path: tests/ShapeFileTest.php + + - + message: "#^Cannot access property \\$shpData on mixed\\.$#" + count: 3 + path: tests/ShapeFileTest.php + + - + message: "#^Cannot call method deletePoint\\(\\) on mixed\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" + count: 17 + path: tests/ShapeFileTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFileNotExists\\(\\)\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotEquals\\(\\)\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNull\\(\\)\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#" + count: 3 + path: tests/ShapeFileTest.php + + - + message: "#^Method PhpMyAdminTest\\\\ShapeFile\\\\ShapeFileTest\\:\\:provideErrorFiles\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Method PhpMyAdminTest\\\\ShapeFile\\\\ShapeFileTest\\:\\:provideFiles\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Method PhpMyAdminTest\\\\ShapeFile\\\\ShapeFileTest\\:\\:shapes\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Method PhpMyAdminTest\\\\ShapeFile\\\\ShapeFileTest\\:\\:testMeasureShapeSaveLoad\\(\\) has parameter \\$points with no value type specified in iterable type array\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Method PhpMyAdminTest\\\\ShapeFile\\\\ShapeFileTest\\:\\:testShapeSaveLoad\\(\\) has parameter \\$points with no value type specified in iterable type array\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Method PhpMyAdminTest\\\\ShapeFile\\\\ShapeFileTest\\:\\:testZetShapeSaveLoad\\(\\) has parameter \\$points with no value type specified in iterable type array\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Parameter \\#1 \\$point of method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:addPoint\\(\\) expects array, mixed given\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Parameter \\#2 \\$partIndex of method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:addPoint\\(\\) expects int, mixed given\\.$#" + count: 1 + path: tests/ShapeFileTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" + count: 2 + path: tests/UtilTest.php + + - + message: "#^Method PhpMyAdminTest\\\\ShapeFile\\\\UtilTest\\:\\:data\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: tests/UtilTest.php + diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 26a78ab..2c66486 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,9 +2,12 @@ includes: - phpstan-baseline.neon parameters: level: max - checkMissingIterableValueType: false paths: - src - tests - reportUnmatchedIgnoredErrors: true - inferPrivatePropertyTypeFromConstructor: true + - examples + checkBenevolentUnionTypes: true + checkUninitializedProperties: true + checkDynamicProperties: true + checkTooWideReturnTypesInProtectedAndPublicMethods: true + checkImplicitMixed: true