diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 170897410..c8556a7fd 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,12 +1,14 @@ includes: + - tests/phpstan/configs/debug-const-checks.neon - tests/phpstan/configs/gc-hacks.neon - tests/phpstan/configs/optional-com-dotnet.neon - tests/phpstan/configs/optional-leveldb.neon - tests/phpstan/configs/phpstan-bugs.neon - tests/phpstan/configs/pthreads-bugs.neon + - tests/phpstan/configs/runtime-type-checks.neon parameters: - level: 3 + level: 4 autoload_files: - tests/phpstan/bootstrap.php - src/pocketmine/PocketMine.php diff --git a/tests/phpstan/configs/debug-const-checks.neon b/tests/phpstan/configs/debug-const-checks.neon new file mode 100644 index 000000000..bfe2fa5c6 --- /dev/null +++ b/tests/phpstan/configs/debug-const-checks.neon @@ -0,0 +1,21 @@ +parameters: + ignoreErrors: + - + message: "#^If condition is always true\\.$#" + count: 1 + path: ../../../src/pocketmine/Server.php + + - + message: "#^Ternary operator condition is always true\\.$#" + count: 1 + path: ../../../src/pocketmine/Server.php + + - + message: "#^If condition is always false\\.$#" + count: 1 + path: ../../../src/pocketmine/updater/AutoUpdater.php + + - + message: "#^Negated boolean expression is always false\\.$#" + count: 1 + path: ../../../src/pocketmine/updater/AutoUpdater.php diff --git a/tests/phpstan/configs/phpstan-bugs.neon b/tests/phpstan/configs/phpstan-bugs.neon index 6e3312bd8..2efbbb37b 100644 --- a/tests/phpstan/configs/phpstan-bugs.neon +++ b/tests/phpstan/configs/phpstan-bugs.neon @@ -25,3 +25,47 @@ parameters: message: "#^Offset \\(int\\|string\\) does not exist on array\\(\\)\\.$#" count: 1 path: ../../../src/pocketmine/MemoryManager.php + + - + message: "#^Comparison operation \"\\>\\=\" between 0 and 2 is always false\\.$#" + count: 1 + path: ../../../src/pocketmine/block/Liquid.php + + - + #adjacentSources comparison FP + message: "#^If condition is always false\\.$#" + count: 1 + path: ../../../src/pocketmine/block/Liquid.php + + - + #$class::NETWORK_ID false positive + message: "#^Strict comparison using \\!\\=\\= between \\-1 and \\-1 will always evaluate to false\\.$#" + count: 1 + path: ../../../src/pocketmine/entity/Entity.php + + - + message: "#^Call to function assert\\(\\) with false and 'unknown hit type' will always evaluate to false\\.$#" + count: 1 + path: ../../../src/pocketmine/entity/projectile/Projectile.php + + - + message: "#^Strict comparison using \\=\\=\\= between int\\ and 4 will always evaluate to false\\.$#" + count: 1 + path: ../../../src/pocketmine/level/Level.php + + - + message: "#^Instanceof between int and PharFileInfo will always evaluate to false\\.$#" + count: 1 + path: ../../../src/pocketmine/plugin/PharPluginLoader.php + + - + #ReflectionFunction::getClosureThis() should be nullable + message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#" + count: 1 + path: ../../../src/pocketmine/utils/Utils.php + + - + #ReflectionFunction::getClosureScopeClass() should be nullable + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: ../../../src/pocketmine/utils/Utils.php diff --git a/tests/phpstan/configs/runtime-type-checks.neon b/tests/phpstan/configs/runtime-type-checks.neon new file mode 100644 index 000000000..7d48cacd9 --- /dev/null +++ b/tests/phpstan/configs/runtime-type-checks.neon @@ -0,0 +1,31 @@ +parameters: + ignoreErrors: + - + #::add() / ::remove() thread parameter + message: "#^If condition is always true\\.$#" + count: 2 + path: ../../../src/pocketmine/ThreadManager.php + + - + #::get() tags parameter + message: "#^If condition is always false\\.$#" + count: 1 + path: ../../../src/pocketmine/item/ItemFactory.php + + - + #::get() tags parameter + message: "#^Strict comparison using \\!\\=\\= between null and null will always evaluate to false\\.$#" + count: 1 + path: ../../../src/pocketmine/item/ItemFactory.php + + - + #::get() tags parameter + message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#" + count: 1 + path: ../../../src/pocketmine/item/ItemFactory.php + + - + #->sendBlocks() blocks parameter + message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#" + count: 2 + path: ../../../src/pocketmine/level/Level.php