From 4cb0b319c046f6cd22a35d604ba90cff2365cfcb Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 5 Nov 2019 11:16:22 +0000 Subject: [PATCH 1/6] load some non-class constants with composer this makes PHPStan happy and also makes working with PM code externally less of a pain in the ass. --- composer.json | 6 +++++- src/pocketmine/GlobalConstants.php | 30 ++++++++++++++++++++++++++++++ src/pocketmine/PocketMine.php | 6 ------ src/pocketmine/VersionInfo.php | 8 ++++++++ 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 src/pocketmine/GlobalConstants.php diff --git a/composer.json b/composer.json index cce152633..d9216be1a 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,11 @@ "autoload": { "psr-4": { "": ["src"] - } + }, + "files": [ + "src/pocketmine/GlobalConstants.php", + "src/pocketmine/VersionInfo.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/pocketmine/GlobalConstants.php b/src/pocketmine/GlobalConstants.php new file mode 100644 index 000000000..a9550cc43 --- /dev/null +++ b/src/pocketmine/GlobalConstants.php @@ -0,0 +1,30 @@ + Date: Tue, 5 Nov 2019 11:16:49 +0000 Subject: [PATCH 2/6] introduced baseline PHPStan configuration --- phpstan.neon | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 phpstan.neon diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 000000000..2f01e8fe9 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,158 @@ + + +parameters: + level: 1 + paths: + - src + #reportUnmatchedIgnoredErrors: false #no other way to silence platform-specific non-warnings + ignoreErrors: + - + message: "#^pocketmine\\\\Player\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\entity\\\\Human\\.$#" + path: src/pocketmine/Player.php + + - + message: "#^Function pocketmine\\\\critical_error not found while trying to analyse it \\- autoloading is probably not configured properly\\.$#" + count: 1 + path: src/pocketmine/PocketMine.php + + - + message: "#^Function pocketmine\\\\check_platform_dependencies not found while trying to analyse it \\- autoloading is probably not configured properly\\.$#" + count: 1 + path: src/pocketmine/PocketMine.php + + - + message: "#^Function pocketmine\\\\emit_performance_warnings not found while trying to analyse it \\- autoloading is probably not configured properly\\.$#" + count: 1 + path: src/pocketmine/PocketMine.php + + - + message: "#^Function pocketmine\\\\set_ini_entries not found while trying to analyse it \\- autoloading is probably not configured properly\\.$#" + count: 1 + path: src/pocketmine/PocketMine.php + + - + message: "#^Function pocketmine\\\\server not found while trying to analyse it \\- autoloading is probably not configured properly\\.$#" + count: 1 + path: src/pocketmine/PocketMine.php + + - + message: "#^Function check_platform_dependencies not found\\.$#" + count: 1 + path: src/pocketmine/PocketMine.php + + - + message: "#^Function critical_error not found\\.$#" + count: 6 + path: src/pocketmine/PocketMine.php + + - + message: "#^Function set_ini_entries not found\\.$#" + count: 1 + path: src/pocketmine/PocketMine.php + + - + message: "#^Function emit_performance_warnings not found\\.$#" + count: 1 + path: src/pocketmine/PocketMine.php + + - + message: "#^Function pocketmine\\\\server not found\\.$#" + count: 1 + path: src/pocketmine/PocketMine.php + + - + message: "#^Constant MIN_PHP_VERSION not found\\.$#" + count: 2 + path: src/pocketmine/PocketMine.php + + - + message: "#^pocketmine\\\\block\\\\[A-Za-z\\d]+\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\block\\\\Block\\.$#" + path: src/pocketmine/block + + - + message: "#^pocketmine\\\\block\\\\Block\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\level\\\\Position\\.$#" + count: 1 + path: src/pocketmine/block/Block.php + + - + message: "#^pocketmine\\\\inventory\\\\DoubleChestInventory\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\inventory\\\\ChestInventory\\.$#" + count: 1 + path: src/pocketmine/inventory/DoubleChestInventory.php + + - + message: "#^pocketmine\\\\inventory\\\\EnderChestInventory\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\inventory\\\\ChestInventory\\.$#" + count: 1 + path: src/pocketmine/inventory/EnderChestInventory.php + + - + message: "#^pocketmine\\\\item\\\\GoldenAppleEnchanted\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\item\\\\GoldenApple\\.$#" + count: 1 + path: src/pocketmine/item/GoldenAppleEnchanted.php + + - + message: "#^pocketmine\\\\item\\\\WrittenBook\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\item\\\\WritableBook\\.$#" + count: 1 + path: src/pocketmine/item/WrittenBook.php + + - + message: "#^Constructor of class pocketmine\\\\level\\\\generator\\\\hell\\\\Nether has an unused parameter \\$options\\.$#" + count: 1 + path: src/pocketmine/level/generator/hell/Nether.php + + - + message: "#^Constructor of class pocketmine\\\\level\\\\generator\\\\normal\\\\Normal has an unused parameter \\$options\\.$#" + count: 1 + path: src/pocketmine/level/generator/normal/Normal.php + + - + message: "#^Used constant pocketmine\\\\RESOURCE_PATH not found\\.$#" + count: 1 + path: src/pocketmine/network/mcpe/protocol/StartGamePacket.php + + - + message: "#^Instantiated class COM not found\\.$#" + count: 2 + path: src/pocketmine/network/upnp/UPnP.php + comment: "only available on Windows" + + - + message: "#^Constructor of class pocketmine\\\\scheduler\\\\TaskScheduler has an unused parameter \\$logger\\.$#" + count: 1 + path: src/pocketmine/scheduler/TaskScheduler.php + + - + message: "#^Variable \\$GLOBALS in isset\\(\\) always exists and is not nullable\\.$#" + path: src/pocketmine/MemoryManager.php + comment: "this isn't defined on threads (thanks pthreads)" + + - + message: "#^Constant pocketmine\\\\COMPOSER_AUTOLOADER_PATH not found\\.$#" + path: src/pocketmine + + - + message: "#^Constant pocketmine\\\\DATA not found\\.$#" + path: src/pocketmine + + - + message: "#^Constant pocketmine\\\\GIT_COMMIT not found\\.$#" + path: src/pocketmine + + - + message: "#^Constant pocketmine\\\\PATH not found\\.$#" + path: src/pocketmine + + - + message: "#^Constant pocketmine\\\\PLUGIN_PATH not found\\.$#" + path: src/pocketmine + + - + message: "#^Constant pocketmine\\\\RESOURCE_PATH not found\\.$#" + path: src/pocketmine + + - + message: "#^Constant pocketmine\\\\START_TIME not found\\.$#" + path: src/pocketmine + + - + message: "#^Constant pocketmine\\\\VERSION not found\\.$#" + path: src/pocketmine From a86bcd51105a748e1e28c1d79c9bc99476f5bd23 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 5 Nov 2019 19:39:04 +0000 Subject: [PATCH 3/6] travis.sh: don't redownload phpunit if it already locally exists --- tests/travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/travis.sh b/tests/travis.sh index 049ec0526..45d5672e4 100755 --- a/tests/travis.sh +++ b/tests/travis.sh @@ -21,7 +21,7 @@ if [ $? -ne 0 ]; then exit 1 fi -curl https://phar.phpunit.de/phpunit-7.phar --silent --location -o phpunit.phar +[ ! -f phpunit.phar ] && echo "Downloading PHPUnit..." && curl https://phar.phpunit.de/phpunit-7.phar --silent --location -o phpunit.phar "$PHP_BINARY" phpunit.phar --bootstrap vendor/autoload.php --fail-on-warning tests/phpunit || exit 1 #Run-the-server tests From 714f4dc023dde8e7455faa21ac135bb55ec34db2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 5 Nov 2019 19:42:37 +0000 Subject: [PATCH 4/6] fortify CI with PHPStan --- tests/travis.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/travis.sh b/tests/travis.sh index 45d5672e4..a58341493 100755 --- a/tests/travis.sh +++ b/tests/travis.sh @@ -21,6 +21,10 @@ if [ $? -ne 0 ]; then exit 1 fi +[ ! -f phpstan.phar ] && echo "Downloading PHPStan..." && curl -sSLO https://github.com/phpstan/phpstan/releases/download/0.11.19/phpstan.phar +"$PHP_BINARY" phpstan.phar analyze --no-progress --memory-limit=2G || exit 1 +echo "PHPStan scan succeeded" + [ ! -f phpunit.phar ] && echo "Downloading PHPUnit..." && curl https://phar.phpunit.de/phpunit-7.phar --silent --location -o phpunit.phar "$PHP_BINARY" phpunit.phar --bootstrap vendor/autoload.php --fail-on-warning tests/phpunit || exit 1 From c5d3e9be767c6227e7d269e97c63366fbb80cfa9 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 5 Nov 2019 20:21:36 +0000 Subject: [PATCH 5/6] phpstan: silence leveldb noise maybe there's a better way to do this, but I don't know it yet. --- phpstan.neon | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 2f01e8fe9..f5178b81c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,7 +4,7 @@ parameters: level: 1 paths: - src - #reportUnmatchedIgnoredErrors: false #no other way to silence platform-specific non-warnings + reportUnmatchedIgnoredErrors: false #no other way to silence platform-specific non-warnings ignoreErrors: - message: "#^pocketmine\\\\Player\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\entity\\\\Human\\.$#" @@ -156,3 +156,21 @@ parameters: - message: "#^Constant pocketmine\\\\VERSION not found\\.$#" path: src/pocketmine + - + message: "#^Used constant LEVELDB_ZLIB_RAW_COMPRESSION not found\\.$#" + path: src/pocketmine/level/format/io/leveldb/LevelDB.php + comment: "explicitly checked" + - + message: "#^Constant LEVELDB_ZLIB_RAW_COMPRESSION not found\\.$#" + path: src/pocketmine/level/format/io/leveldb/LevelDB.php + comment: "explicitly checked" + - + message: "#^Instantiated class LevelDB not found\\.$#" + path: src/pocketmine/level/format/io/leveldb/LevelDB.php + comment: "leveldb extension currently optional" + - + message: "#^Return typehint of method pocketmine\\\\level\\\\format\\\\io\\\\leveldb\\\\LevelDB\\:\\:createDB\\(\\) has invalid type LevelDB\\.$#" + path: src/pocketmine/level/format/io/leveldb/LevelDB.php + - + message: "#^Return typehint of method pocketmine\\\\level\\\\format\\\\io\\\\leveldb\\\\LevelDB\\:\\:getDatabase\\(\\) has invalid type LevelDB\\.$#" + path: src/pocketmine/level/format/io/leveldb/LevelDB.php From cac3c356a5a83cf6cada0269e86f8d8d11e80c52 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 6 Nov 2019 14:29:43 -0500 Subject: [PATCH 6/6] Painting: fix dropping multiple items when multiple blockupdates occur in the same tick test case: place sand on top of a line of signs, put a painting on the sand and break the supporting sign fixes #2774 for stable --- src/pocketmine/entity/object/Painting.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pocketmine/entity/object/Painting.php b/src/pocketmine/entity/object/Painting.php index 70e47307f..f60368519 100644 --- a/src/pocketmine/entity/object/Painting.php +++ b/src/pocketmine/entity/object/Painting.php @@ -90,6 +90,9 @@ class Painting extends Entity{ } public function kill() : void{ + if(!$this->isAlive()){ + return; + } parent::kill(); $drops = true;