From 974d08efd62c52c1c8ac92cb1b67ac157908fd71 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 9 Oct 2021 20:09:42 +0100 Subject: [PATCH] Bump PHP minimum requirement to 8.0 PHPStan failed on 7.4 after updating to 0.12.99, and I figured it was less hassle to just do this than fix the build. In any case, we stopped shipping 7.4 months ago, and warned at 3.22 release that 7.4 support would soon be dropped. --- .github/workflows/main.yml | 19 ++-- .github/workflows/update-php-versions.php | 2 - BUILDING.md | 6 +- composer.json | 4 +- composer.lock | 6 +- phpstan.neon.dist | 3 - phpstan.php7.neon | 9 -- src/pocketmine/PocketMine.php | 2 +- src/pocketmine/network/rcon/RCON.php | 15 +-- src/pocketmine/network/rcon/RCONInstance.php | 37 ++---- src/pocketmine/utils/Internet.php | 2 +- src/pocketmine/utils/Timezone.php | 3 - src/pocketmine/utils/Utils.php | 3 +- tests/phpstan/configs/php7.neon | 112 ------------------- tests/phpstan/configs/php74-compat.neon | 11 -- 15 files changed, 29 insertions(+), 205 deletions(-) delete mode 100644 phpstan.php7.neon delete mode 100644 tests/phpstan/configs/php7.neon delete mode 100644 tests/phpstan/configs/php74-compat.neon diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ae5ecd62f..79f39f899 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: image: [ubuntu-20.04] - php: [7.4.24, 8.0.11] + php: [8.0.11] steps: - uses: actions/checkout@v2 #needed for build.sh @@ -36,13 +36,8 @@ jobs: strategy: fail-fast: false matrix: - include: - - php: 8.0.11 - config: phpstan.neon.dist - image: ubuntu-20.04 - - php: 7.4.24 - config: phpstan.php7.neon - image: ubuntu-20.04 + image: [ubuntu-20.04] + php: [8.0.11] steps: - uses: actions/checkout@v2 @@ -82,7 +77,7 @@ jobs: run: php composer.phar install --prefer-dist --no-interaction - name: Run PHPStan - run: ./vendor/bin/phpstan analyze --no-progress --memory-limit=2G -c ${{ matrix.config }} + run: ./vendor/bin/phpstan analyze --no-progress --memory-limit=2G phpunit: name: PHPUnit tests @@ -92,7 +87,7 @@ jobs: fail-fast: false matrix: image: [ubuntu-20.04] - php: [7.4.24, 8.0.11] + php: [8.0.11] steps: - uses: actions/checkout@v2 @@ -142,7 +137,7 @@ jobs: fail-fast: false matrix: image: [ubuntu-20.04] - php: [7.4.24, 8.0.11] + php: [8.0.11] steps: - uses: actions/checkout@v2 @@ -194,7 +189,7 @@ jobs: fail-fast: false matrix: image: [ubuntu-20.04] - php: [7.4.24, 8.0.11] + php: [8.0.11] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/update-php-versions.php b/.github/workflows/update-php-versions.php index 8b24812c8..0ba7382cf 100644 --- a/.github/workflows/update-php-versions.php +++ b/.github/workflows/update-php-versions.php @@ -22,8 +22,6 @@ declare(strict_types=1); const VERSIONS = [ - "7.3", - "7.4", "8.0" ]; diff --git a/BUILDING.md b/BUILDING.md index 1c5aa8e59..37b7a4a8f 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -2,13 +2,13 @@ ## Pre-requisites - A bash shell (git bash is sufficient for Windows) - [`git`](https://git-scm.com) available in your shell -- PHP 7.4 or newer available in your shell +- PHP 8.0 or newer available in your shell - [`composer`](https://getcomposer.org) available in your shell ## Custom PHP binaries Because PocketMine-MP requires several non-standard PHP extensions and configuration, PMMP provides scripts to build custom binaries for running PocketMine-MP, as well as prebuilt binaries. -- [Prebuilt binaries](https://jenkins.pmmp.io/job/PHP-7.4-Aggregate) +- [Prebuilt binaries](https://jenkins.pmmp.io/job/PHP-8.0-Aggregate) - [Compile scripts](https://github.com/pmmp/php-build-scripts) are provided as a submodule in the path `build/php` If you use a custom binary, you'll need to replace `composer` usages in this guide with `path/to/your/php path/to/your/composer.phar`. @@ -38,7 +38,7 @@ There is a bug in PHP that might cause an error which looks like this: ``` Fatal error: Uncaught BadMethodCallException: unable to create temporary file in PocketMine-MP/build/server-phar.php:119 ``` -You can work around it by setting `ulimit -n` to some bigger number, e.g. `8192`, or by updating your PHP version to at least 7.4.16 or 8.0.3. +You can work around it by setting `ulimit -n` to some bigger number, e.g. `8192`, or by updating your PHP version to at least 8.0.3. ## Running PocketMine-MP from source code Run `src/pocketmine/PocketMine.php` using your preferred PHP binary. diff --git a/composer.json b/composer.json index 911b036f5..262d67a10 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "homepage": "https://pmmp.io", "license": "LGPL-3.0", "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "php-64bit": "*", "ext-ctype": "*", "ext-curl": "*", @@ -60,7 +60,7 @@ }, "config": { "platform": { - "php": "7.4.0" + "php": "8.0.0" }, "sort-packages": true }, diff --git a/composer.lock b/composer.lock index 68576adf1..838f72322 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f3f0ef9944d96c5b71b7e32aac5118cd", + "content-hash": "cfba71d2ad0dd961ed00520b5d52e4d7", "packages": [ { "name": "adhocore/json-comment", @@ -2755,7 +2755,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "php-64bit": "*", "ext-ctype": "*", "ext-curl": "*", @@ -2778,7 +2778,7 @@ }, "platform-dev": [], "platform-overrides": { - "php": "7.4.0" + "php": "8.0.0" }, "plugin-api-version": "2.1.0" } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index f2fd04b9b..0dee95aa2 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -5,7 +5,6 @@ includes: - tests/phpstan/configs/l7-baseline.neon - tests/phpstan/configs/l8-baseline.neon - tests/phpstan/configs/php-bugs.neon - - tests/phpstan/configs/php74-compat.neon - tests/phpstan/configs/phpstan-bugs.neon - tests/phpstan/configs/phpunit-wiring-tests.neon - tests/phpstan/configs/pthreads-bugs.neon @@ -51,5 +50,3 @@ parameters: #we'll just fill it with 10 - it's very unlikely to encounter a callable with 10 parameters anyway. anyCallable: 'callable(never, never, never, never, never, never, never, never, never, never) : mixed' anyClosure: '\Closure(never, never, never, never, never, never, never, never, never, never) : mixed' - PhpSocket: '\Socket' - PhpCurlHandle: '\CurlHandle' diff --git a/phpstan.php7.neon b/phpstan.php7.neon deleted file mode 100644 index e16e7b8c3..000000000 --- a/phpstan.php7.neon +++ /dev/null @@ -1,9 +0,0 @@ -includes: - - phpstan.neon.dist - - tests/phpstan/configs/php7.neon - -parameters: - phpVersion: 70400 - typeAliases: - PhpSocket: resource - PhpCurlHandle: resource diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index f425d7267..fd648140d 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -36,7 +36,7 @@ namespace pocketmine { require_once __DIR__ . '/VersionInfo.php'; - const MIN_PHP_VERSION = "7.4.0"; + const MIN_PHP_VERSION = "8.0.0"; /** * @param string $message diff --git a/src/pocketmine/network/rcon/RCON.php b/src/pocketmine/network/rcon/RCON.php index 87ccab802..13dec46cb 100644 --- a/src/pocketmine/network/rcon/RCON.php +++ b/src/pocketmine/network/rcon/RCON.php @@ -57,24 +57,15 @@ use const SOL_TCP; class RCON{ /** @var Server */ private $server; - /** - * @var \Socket|resource - * @phpstan-var PhpSocket - */ + /** @var \Socket */ private $socket; /** @var RCONInstance */ private $instance; - /** - * @var \Socket|resource - * @phpstan-var PhpSocket - */ + /** @var \Socket */ private $ipcMainSocket; - /** - * @var resource - * @phpstan-var PhpSocket - */ + /** @var \Socket */ private $ipcThreadSocket; public function __construct(Server $server, string $password, int $port = 19132, string $interface = "0.0.0.0", int $maxClients = 50){ diff --git a/src/pocketmine/network/rcon/RCONInstance.php b/src/pocketmine/network/rcon/RCONInstance.php index 42212f6d3..ab60c745f 100644 --- a/src/pocketmine/network/rcon/RCONInstance.php +++ b/src/pocketmine/network/rcon/RCONInstance.php @@ -60,10 +60,7 @@ class RCONInstance extends Thread{ /** @var bool */ private $stop; - /** - * @var \Socket|resource - * @phpstan-var PhpSocket - */ + /** @var \Socket */ private $socket; /** @var string */ private $password; @@ -71,21 +68,12 @@ class RCONInstance extends Thread{ private $maxClients; /** @var \ThreadedLogger */ private $logger; - /** - * @var \Socket|resource - * @phpstan-var PhpSocket - */ + /** @var \Socket */ private $ipcSocket; /** @var SleeperNotifier|null */ private $notifier; - /** - * @param \Socket|resource $socket - * @param \Socket|resource $ipcSocket - * @phpstan-param PhpSocket $socket - * @phpstan-param PhpSocket $ipcSocket - */ - public function __construct($socket, string $password, int $maxClients, \ThreadedLogger $logger, $ipcSocket, ?SleeperNotifier $notifier){ + public function __construct(\Socket $socket, string $password, int $maxClients, \ThreadedLogger $logger, \Socket $ipcSocket, ?SleeperNotifier $notifier){ $this->stop = false; $this->cmd = ""; $this->response = ""; @@ -100,12 +88,9 @@ class RCONInstance extends Thread{ } /** - * @param \Socket|resource $client - * @phpstan-param PhpSocket $client - * * @return int|false */ - private function writePacket($client, int $requestID, int $packetType, string $payload){ + private function writePacket(\Socket $client, int $requestID, int $packetType, string $payload){ $pk = Binary::writeLInt($requestID) . Binary::writeLInt($packetType) . $payload @@ -114,15 +99,13 @@ class RCONInstance extends Thread{ } /** - * @param \Socket|resource $client * @param int $requestID reference parameter * @param int $packetType reference parameter * @param string $payload reference parameter - * @phpstan-param PhpSocket $client * * @return bool */ - private function readPacket($client, ?int &$requestID, ?int &$packetType, ?string &$payload){ + private function readPacket(\Socket $client, ?int &$requestID, ?int &$packetType, ?string &$payload){ $d = @socket_read($client, 4); socket_getpeername($client, $ip, $port); @@ -176,8 +159,8 @@ class RCONInstance extends Thread{ $this->registerClassLoader(); /** - * @var \Socket[]|resource[] $clients - * @phpstan-var array $clients + * @var \Socket[] $clients + * @phpstan-var array $clients */ $clients = []; /** @var bool[] $authenticated */ @@ -277,11 +260,7 @@ class RCONInstance extends Thread{ } } - /** - * @param \Socket|resource $client - * @phpstan-param PhpSocket $client - */ - private function disconnectClient($client) : void{ + private function disconnectClient(\Socket $client) : void{ socket_getpeername($client, $ip, $port); @socket_set_option($client, SOL_SOCKET, SO_LINGER, ["l_onoff" => 1, "l_linger" => 1]); @socket_shutdown($client, 2); diff --git a/src/pocketmine/utils/Internet.php b/src/pocketmine/utils/Internet.php index 5bdd65881..5c3f06329 100644 --- a/src/pocketmine/utils/Internet.php +++ b/src/pocketmine/utils/Internet.php @@ -197,7 +197,7 @@ class Internet{ * @param callable|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle. * @phpstan-param array $extraOpts * @phpstan-param list $extraHeaders - * @phpstan-param (callable(PhpCurlHandle) : void)|null $onSuccess + * @phpstan-param (callable(\CurlHandle) : void)|null $onSuccess * * @return array a plain array of three [result body : string, headers : string[][], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values * @phpstan-return array{string, list>, int} diff --git a/src/pocketmine/utils/Timezone.php b/src/pocketmine/utils/Timezone.php index 8d883e582..08a7c78bf 100644 --- a/src/pocketmine/utils/Timezone.php +++ b/src/pocketmine/utils/Timezone.php @@ -201,9 +201,6 @@ abstract class Timezone{ } $parsed = date_parse($offset); - if($parsed === false){ - return false; - } $offset = $parsed['hour'] * 3600 + $parsed['minute'] * 60 + $parsed['second']; //After date_parse is done, put the sign back diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index 1b81ad3b8..c92fc373a 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -454,7 +454,7 @@ class Utils{ * @param callable|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle. * @phpstan-param array $extraOpts * @phpstan-param list $extraHeaders - * @phpstan-param (callable(PhpCurlHandle) : void)|null $onSuccess + * @phpstan-param (callable(\CurlHandle) : void)|null $onSuccess * * @return array a plain array of three [result body : string, headers : string[][], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values * @phpstan-return array{string, list>, int} @@ -642,7 +642,6 @@ class Utils{ preg_match_all('/(*ANYCRLF)^[\t ]*(?:\* )?@([a-zA-Z]+)(?:[\t ]+(.+?))?[\t ]*$/m', $rawDocComment, $matches); $result = array_combine($matches[1], $matches[2]); - if($result === false) throw new AssumptionFailedError("array_combine() doesn't return false with two equal-sized arrays"); return $result; } diff --git a/tests/phpstan/configs/php7.neon b/tests/phpstan/configs/php7.neon deleted file mode 100644 index f02766677..000000000 --- a/tests/phpstan/configs/php7.neon +++ /dev/null @@ -1,112 +0,0 @@ -parameters: - ignoreErrors: - - - message: "#^Parameter \\#1 \\$fp of function fclose expects resource, resource\\|false given\\.$#" - count: 1 - path: ../../../src/pocketmine/MemoryManager.php - - - - message: "#^Parameter \\#1 \\$fp of function fwrite expects resource, resource\\|false given\\.$#" - count: 1 - path: ../../../src/pocketmine/MemoryManager.php - - - - message: "#^Parameter \\#1 \\$str of function base64_decode expects string, mixed given\\.$#" - count: 6 - path: ../../../src/pocketmine/Player.php - - - - message: "#^Parameter \\#1 \\$input of function array_filter expects array, array\\\\|false given\\.$#" - count: 1 - path: ../../../src/pocketmine/Server.php - - - - message: "#^Parameter \\#1 \\$str of function strtolower expects string, mixed given\\.$#" - count: 1 - path: ../../../src/pocketmine/Server.php - - - - message: "#^Parameter \\#1 \\$number of function round expects float, mixed given\\.$#" - count: 1 - path: ../../../src/pocketmine/command/defaults/StatusCommand.php - - - - message: "#^Parameter \\#1 \\$fp of function fclose expects resource, resource\\|false given\\.$#" - count: 2 - path: ../../../src/pocketmine/command/defaults/TimingsCommand.php - - - - message: "#^Parameter \\#1 \\$fp of function fseek expects resource, resource\\|false given\\.$#" - count: 1 - path: ../../../src/pocketmine/command/defaults/TimingsCommand.php - - - - message: "#^Parameter \\#1 \\$source of function stream_get_contents expects resource, resource\\|false given\\.$#" - count: 1 - path: ../../../src/pocketmine/command/defaults/TimingsCommand.php - - - - message: "#^Parameter \\#1 \\$argument of class ReflectionClass constructor expects class\\-string\\\\|T of object, string given\\.$#" - count: 1 - path: ../../../src/pocketmine/event/HandlerList.php - - - - message: "#^Parameter \\#2 \\$input1 of function array_map expects array, array\\|false given\\.$#" - count: 1 - path: ../../../src/pocketmine/lang/BaseLang.php - - - - message: "#^Parameter \\#2 \\$str of function explode expects string, mixed given\\.$#" - count: 1 - path: ../../../src/pocketmine/level/format/io/leveldb/LevelDB.php - - - - message: "#^Parameter \\#1 \\$input of function array_filter expects array, array\\\\|false given\\.$#" - count: 1 - path: ../../../src/pocketmine/level/format/io/region/McRegion.php - - - - message: "#^Parameter \\#1 \\$str of function str_split expects string, string\\|false given\\.$#" - count: 1 - path: ../../../src/pocketmine/network/mcpe/VerifyLoginTask.php - - - - message: "#^Parameter \\#1 \\$str of function mb_strtoupper expects string, mixed given\\.$#" - count: 1 - path: ../../../src/pocketmine/plugin/PluginDescription.php - - - - message: "#^Parameter \\#1 \\$variable_representation of function unserialize expects string, mixed given\\.$#" - count: 1 - path: ../../../src/pocketmine/scheduler/AsyncTask.php - - - - message: "#^Parameter \\#1 \\$str of function strtolower expects string, mixed given\\.$#" - count: 1 - path: ../../../src/pocketmine/updater/AutoUpdater.php - - - - message: "#^Parameter \\#2 \\$timestamp of function date expects int, mixed given\\.$#" - count: 1 - path: ../../../src/pocketmine/updater/AutoUpdater.php - - - - message: "#^Parameter \\#2 \\$start of function substr expects int, mixed given\\.$#" - count: 1 - path: ../../../src/pocketmine/utils/Internet.php - - - - message: "#^Parameter \\#3 \\$length of function substr expects int, mixed given\\.$#" - count: 1 - path: ../../../src/pocketmine/utils/Internet.php - - - - message: "#^Parameter \\#2 \\$input1 of function array_map expects array, mixed given\\.$#" - count: 1 - path: ../../../src/pocketmine/utils/Utils.php - - - - message: "#^Method ReflectionMethod\\:\\:getClosure\\(\\) invoked with 0 parameters, 1 required\\.$#" - count: 1 - path: ../../phpunit/network/mcpe/StupidJsonDecodeTest.php - diff --git a/tests/phpstan/configs/php74-compat.neon b/tests/phpstan/configs/php74-compat.neon deleted file mode 100644 index c5aaf4443..000000000 --- a/tests/phpstan/configs/php74-compat.neon +++ /dev/null @@ -1,11 +0,0 @@ -parameters: - ignoreErrors: - - - message: "#^Strict comparison using \\=\\=\\= between array\\ and false will always evaluate to false\\.$#" - count: 1 - path: ../../../src/pocketmine/utils/Timezone.php - - - - message: "#^Strict comparison using \\=\\=\\= between array and false will always evaluate to false\\.$#" - count: 1 - path: ../../../src/pocketmine/utils/Utils.php