Merge remote-tracking branch 'origin/stable'

This commit is contained in:
Dylan K. Taylor 2021-07-26 20:14:33 +01:00
commit 09eac0e129
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
15 changed files with 141 additions and 241 deletions

View File

@ -38,10 +38,10 @@ jobs:
matrix:
include:
- php: 8.0.7
config: phpstan.php8.neon
config: phpstan.neon.dist
image: ubuntu-20.04
- php: 7.4.20
config: phpstan.neon.dist
config: phpstan.php7.neon
image: ubuntu-20.04
steps:

View File

@ -5,6 +5,7 @@ includes:
- tests/phpstan/configs/impossible-generics.neon
- tests/phpstan/configs/l7-baseline.neon
- tests/phpstan/configs/l8-baseline.neon
- tests/phpstan/configs/php74-compat.neon
- tests/phpstan/configs/php-bugs.neon
- tests/phpstan/configs/phpstan-bugs.neon
- tests/phpstan/configs/phpunit-wiring-tests.neon
@ -56,3 +57,6 @@ parameters:
#we'll just fill it with 10 - it's very unlikely to encounter a callable with 10 parameters anyway.
anyCallable: 'callable(mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed) : mixed'
anyClosure: '\Closure(mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed) : mixed'
PhpSocket: '\Socket'
PhpCurlHandle: '\CurlHandle'
PhpOpenSSLAsymmetricKey: '\OpenSSLAsymmetricKey'

10
phpstan.php7.neon Normal file
View File

@ -0,0 +1,10 @@
includes:
- phpstan.neon.dist
- tests/phpstan/configs/php7.neon
parameters:
phpVersion: 70400
typeAliases:
PhpSocket: resource
PhpCurlHandle: resource
PhpOpenSSLAsymmetricKey: resource

View File

@ -1,4 +0,0 @@
includes:
- phpstan.neon.dist
- tests/phpstan/configs/php8.neon

View File

@ -97,7 +97,8 @@ final class JwtUtils{
}
/**
* @param resource $signingKey
* @param \OpenSSLAsymmetricKey|resource $signingKey
* @phpstan-param PhpOpenSSLAsymmetricKey $signingKey
*
* @throws JwtException
*/
@ -132,7 +133,8 @@ final class JwtUtils{
}
/**
* @param resource $signingKey
* @param \OpenSSLAsymmetricKey|resource $signingKey
* @phpstan-param PhpOpenSSLAsymmetricKey $signingKey
*
* @phpstan-param array<string, mixed> $header
* @phpstan-param array<string, mixed> $claims
@ -189,7 +191,8 @@ final class JwtUtils{
}
/**
* @param resource $opensslKey
* @param \OpenSSLAsymmetricKey|resource $opensslKey
* @phpstan-param PhpOpenSSLAsymmetricKey $opensslKey
*/
public static function emitDerPublicKey($opensslKey) : string{
$details = openssl_pkey_get_details($opensslKey);
@ -209,7 +212,8 @@ final class JwtUtils{
}
/**
* @return resource
* @return \OpenSSLAsymmetricKey|resource
* @phpstan-return PhpOpenSSLAsymmetricKey
*/
public static function parseDerPublicKey(string $derKey){
$signingKeyOpenSSL = openssl_pkey_get_public(sprintf("-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n", base64_encode($derKey)));

View File

@ -41,8 +41,10 @@ final class EncryptionUtils{
}
/**
* @param resource $localPriv
* @param resource $remotePub
* @param \OpenSSLAsymmetricKey|resource $localPriv
* @param \OpenSSLAsymmetricKey|resource $remotePub
* @phpstan-param PhpOpenSSLAsymmetricKey $localPriv
* @phpstan-param PhpOpenSSLAsymmetricKey $remotePub
*/
public static function generateSharedSecret($localPriv, $remotePub) : \GMP{
$hexSecret = openssl_pkey_derive($remotePub, $localPriv, 48);
@ -57,7 +59,8 @@ final class EncryptionUtils{
}
/**
* @param resource $serverPriv
* @param \OpenSSLAsymmetricKey|resource $serverPriv
* @phpstan-param PhpOpenSSLAsymmetricKey $serverPriv
*/
public static function generateServerHandshakeJwt($serverPriv, string $salt) : string{
$derPublicKey = JwtUtils::emitDerPublicKey($serverPriv);

View File

@ -38,7 +38,10 @@ class PrepareEncryptionTask extends AsyncTask{
private const TLS_KEY_ON_COMPLETION = "completion";
/** @var resource|null */
/**
* @var \OpenSSLAsymmetricKey|resource|null
* @phpstan-var PhpOpenSSLAsymmetricKey|null
*/
private static $SERVER_PRIVATE_KEY = null;
/** @var string */

View File

@ -63,7 +63,10 @@ final class DedicatedQueryNetworkInterface implements AdvancedNetworkInterface{
private $port;
/** @var \Logger */
private $logger;
/** @var resource */
/**
* @var \Socket|resource
* @phpstan-var PhpSocket
*/
private $socket;
/** @var Network */
private $network;

View File

@ -185,7 +185,7 @@ class Internet{
* @param \Closure|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle.
* @phpstan-param array<int, mixed> $extraOpts
* @phpstan-param list<string> $extraHeaders
* @phpstan-param (\Closure(resource) : void)|null $onSuccess
* @phpstan-param (\Closure(PhpCurlHandle) : void)|null $onSuccess
*
* @throws InternetException if a cURL error occurs
*/

View File

@ -41,7 +41,7 @@ parameters:
path: ../../../src/ServerConfigGroup.php
-
message: "#^Parameter \\#1 \\$str of function strtolower expects string, mixed given\\.$#"
message: "#^Parameter \\#1 \\$string of function strtolower expects string, mixed given\\.$#"
count: 1
path: ../../../src/ServerConfigGroup.php
@ -196,12 +196,12 @@ parameters:
path: ../../../src/timings/TimingsHandler.php
-
message: "#^Parameter \\#2 \\$start of function substr expects int, mixed given\\.$#"
message: "#^Parameter \\#2 \\$offset of function substr expects int, mixed given\\.$#"
count: 1
path: ../../../src/utils/Internet.php
-
message: "#^Parameter \\#3 \\$length of function substr expects int, mixed given\\.$#"
message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, mixed given\\.$#"
count: 1
path: ../../../src/utils/Internet.php
@ -226,7 +226,7 @@ parameters:
path: ../../../src/utils/Utils.php
-
message: "#^Parameter \\#2 \\$input1 of function array_map expects array, mixed given\\.$#"
message: "#^Parameter \\#2 \\$array of function array_map expects array, mixed given\\.$#"
count: 1
path: ../../../src/utils/Utils.php
@ -245,28 +245,3 @@ parameters:
count: 2
path: ../../../src/world/format/io/region/RegionWorldProvider.php
-
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
count: 1
path: ../../phpunit/block/BlockTest.php
-
message: "#^Cannot access offset \\(int\\|string\\) on mixed\\.$#"
count: 1
path: ../../phpunit/block/BlockTest.php
-
message: "#^Parameter \\#2 \\$array of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) expects array\\|ArrayAccess, mixed given\\.$#"
count: 1
path: ../../phpunit/block/BlockTest.php
-
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
count: 1
path: ../../phpunit/block/regenerate_consistency_check.php
-
message: "#^Cannot access offset \\(int\\|string\\) on mixed\\.$#"
count: 3
path: ../../phpunit/block/regenerate_consistency_check.php

View File

@ -16,12 +16,12 @@ parameters:
path: ../../../build/server-phar.php
-
message: "#^Parameter \\#1 \\$fp of function fclose expects resource, resource\\|false given\\.$#"
message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/MemoryManager.php
-
message: "#^Parameter \\#1 \\$fp of function fwrite expects resource, resource\\|false given\\.$#"
message: "#^Parameter \\#1 \\$stream of function fwrite expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/MemoryManager.php
@ -65,11 +65,6 @@ parameters:
count: 1
path: ../../../src/Server.php
-
message: "#^Cannot cast array\\<int, mixed\\>\\|string\\|false to int\\.$#"
count: 1
path: ../../../src/ServerConfigGroup.php
-
message: "#^Cannot cast array\\<int, mixed\\>\\|string\\|false to string\\.$#"
count: 1
@ -451,22 +446,22 @@ parameters:
path: ../../../src/command/defaults/PardonIpCommand.php
-
message: "#^Parameter \\#1 \\$fp of function fclose expects resource, resource\\|false given\\.$#"
message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#"
count: 2
path: ../../../src/command/defaults/TimingsCommand.php
-
message: "#^Parameter \\#1 \\$fp of function fseek expects resource, resource\\|false given\\.$#"
message: "#^Parameter \\#1 \\$stream of function fseek expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/command/defaults/TimingsCommand.php
-
message: "#^Parameter \\#1 \\$fp of function fwrite expects resource, resource\\|false given\\.$#"
message: "#^Parameter \\#1 \\$stream of function fwrite expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/command/defaults/TimingsCommand.php
-
message: "#^Parameter \\#1 \\$source of function stream_get_contents expects resource, resource\\|false given\\.$#"
message: "#^Parameter \\#1 \\$stream of function stream_get_contents expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/command/defaults/TimingsCommand.php
@ -561,7 +556,7 @@ parameters:
path: ../../../src/entity/projectile/Projectile.php
-
message: "#^Parameter \\#1 \\$argument of class ReflectionClass constructor expects class\\-string\\<T of object\\>\\|T of object, string given\\.$#"
message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\<T of object\\>\\|T of object, string given\\.$#"
count: 1
path: ../../../src/event/HandlerListManager.php
@ -576,7 +571,7 @@ parameters:
path: ../../../src/item/Item.php
-
message: "#^Parameter \\#2 \\$input1 of function array_map expects array, array\\|false given\\.$#"
message: "#^Parameter \\#2 \\$array of function array_map expects array, array\\|false given\\.$#"
count: 1
path: ../../../src/lang/Language.php
@ -691,7 +686,12 @@ parameters:
path: ../../../src/utils/Timezone.php
-
message: "#^Parameter \\#1 \\$timezone_identifier of function date_default_timezone_set expects string, string\\|false given\\.$#"
message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|false given\\.$#"
count: 1
path: ../../../src/utils/Timezone.php
-
message: "#^Parameter \\#1 \\$timezoneId of function date_default_timezone_set expects string, string\\|false given\\.$#"
count: 1
path: ../../../src/utils/Timezone.php

View File

@ -0,0 +1,67 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$fp of function fclose expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/MemoryManager.php
-
message: "#^Parameter \\#1 \\$fp of function fwrite expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/MemoryManager.php
-
message: "#^Parameter \\#1 \\$str of function strtolower expects string, mixed given\\.$#"
count: 1
path: ../../../src/ServerConfigGroup.php
-
message: "#^Parameter \\#1 \\$fp of function fclose expects resource, resource\\|false given\\.$#"
count: 2
path: ../../../src/command/defaults/TimingsCommand.php
-
message: "#^Parameter \\#1 \\$fp of function fseek expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/command/defaults/TimingsCommand.php
-
message: "#^Parameter \\#1 \\$fp of function fwrite expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/command/defaults/TimingsCommand.php
-
message: "#^Parameter \\#1 \\$source of function stream_get_contents expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/command/defaults/TimingsCommand.php
-
message: "#^Parameter \\#1 \\$argument of class ReflectionClass constructor expects class\\-string\\<T of object\\>\\|T of object, string given\\.$#"
count: 1
path: ../../../src/event/HandlerListManager.php
-
message: "#^Parameter \\#2 \\$input1 of function array_map expects array, array\\|false given\\.$#"
count: 1
path: ../../../src/lang/Language.php
-
message: "#^Parameter \\#2 \\$start of function substr expects int, mixed given\\.$#"
count: 1
path: ../../../src/utils/Internet.php
-
message: "#^Parameter \\#3 \\$length of function substr expects int, mixed given\\.$#"
count: 1
path: ../../../src/utils/Internet.php
-
message: "#^Parameter \\#1 \\$timezone_identifier of function date_default_timezone_set expects string, string\\|false given\\.$#"
count: 1
path: ../../../src/utils/Timezone.php
-
message: "#^Parameter \\#2 \\$input1 of function array_map expects array, mixed given\\.$#"
count: 1
path: ../../../src/utils/Utils.php

View File

@ -0,0 +1,12 @@
parameters:
ignoreErrors:
-
message: "#^Strict comparison using \\=\\=\\= between array\\<string, mixed\\> and false will always evaluate to false\\.$#"
count: 1
path: ../../../src/utils/Timezone.php
-
message: "#^Strict comparison using \\=\\=\\= between array and false will always evaluate to false\\.$#"
count: 1
path: ../../../src/utils/Utils.php

View File

@ -1,182 +0,0 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/MemoryManager.php
-
message: "#^Parameter \\#1 \\$stream of function fwrite expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/MemoryManager.php
-
message: "#^Parameter \\#1 \\$string of function strtolower expects string, mixed given\\.$#"
count: 1
path: ../../../src/ServerConfigGroup.php
-
message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#"
count: 2
path: ../../../src/command/defaults/TimingsCommand.php
-
message: "#^Parameter \\#1 \\$stream of function fseek expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/command/defaults/TimingsCommand.php
-
message: "#^Parameter \\#1 \\$stream of function fwrite expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/command/defaults/TimingsCommand.php
-
message: "#^Parameter \\#1 \\$stream of function stream_get_contents expects resource, resource\\|false given\\.$#"
count: 1
path: ../../../src/command/defaults/TimingsCommand.php
-
message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\<T of object\\>\\|T of object, string given\\.$#"
count: 1
path: ../../../src/event/HandlerListManager.php
-
message: "#^Parameter \\#2 \\$array of function array_map expects array, array\\|false given\\.$#"
count: 1
path: ../../../src/lang/Language.php
-
message: "#^Method pocketmine\\\\network\\\\mcpe\\\\JwtUtils\\:\\:parseDerPublicKey\\(\\) should return resource but returns OpenSSLAsymmetricKey\\.$#"
count: 1
path: ../../../src/network/mcpe/JwtUtils.php
-
message: "#^Parameter \\#1 \\$key of function openssl_pkey_get_details expects OpenSSLAsymmetricKey, resource given\\.$#"
count: 1
path: ../../../src/network/mcpe/JwtUtils.php
-
message: "#^Parameter \\#3 \\$private_key of function openssl_sign expects array\\|OpenSSLAsymmetricKey\\|OpenSSLCertificate\\|string, resource given\\.$#"
count: 1
path: ../../../src/network/mcpe/JwtUtils.php
-
message: "#^Parameter \\#3 \\$public_key of function openssl_verify expects array\\|OpenSSLAsymmetricKey\\|OpenSSLCertificate\\|string, resource given\\.$#"
count: 1
path: ../../../src/network/mcpe/JwtUtils.php
-
message: "#^Parameter \\#1 \\$key of function openssl_free_key expects OpenSSLAsymmetricKey, resource given\\.$#"
count: 1
path: ../../../src/network/mcpe/auth/ProcessLoginTask.php
-
message: "#^Parameter \\#1 \\$public_key of function openssl_pkey_derive expects array\\|OpenSSLAsymmetricKey\\|OpenSSLCertificate\\|string, resource given\\.$#"
count: 1
path: ../../../src/network/mcpe/encryption/EncryptionUtils.php
-
message: "#^Parameter \\#2 \\$private_key of function openssl_pkey_derive expects array\\|OpenSSLAsymmetricKey\\|OpenSSLCertificate\\|string, resource given\\.$#"
count: 1
path: ../../../src/network/mcpe/encryption/EncryptionUtils.php
-
message: "#^Parameter \\#1 \\$key of function openssl_free_key expects OpenSSLAsymmetricKey, resource given\\.$#"
count: 1
path: ../../../src/network/mcpe/encryption/PrepareEncryptionTask.php
-
message: "#^Parameter \\#1 \\$key of function openssl_pkey_get_details expects OpenSSLAsymmetricKey, OpenSSLAsymmetricKey\\|resource given\\.$#"
count: 1
path: ../../../src/network/mcpe/encryption/PrepareEncryptionTask.php
-
message: "#^Parameter \\#1 \\$localPriv of static method pocketmine\\\\network\\\\mcpe\\\\encryption\\\\EncryptionUtils\\:\\:generateSharedSecret\\(\\) expects resource, OpenSSLAsymmetricKey given\\.$#"
count: 1
path: ../../../src/network/mcpe/encryption/PrepareEncryptionTask.php
-
message: "#^Parameter \\#1 \\$serverPriv of static method pocketmine\\\\network\\\\mcpe\\\\encryption\\\\EncryptionUtils\\:\\:generateServerHandshakeJwt\\(\\) expects resource, OpenSSLAsymmetricKey given\\.$#"
count: 1
path: ../../../src/network/mcpe/encryption/PrepareEncryptionTask.php
-
message: "#^Static property pocketmine\\\\network\\\\mcpe\\\\encryption\\\\PrepareEncryptionTask\\:\\:\\$SERVER_PRIVATE_KEY \\(resource\\|null\\) does not accept OpenSSLAsymmetricKey\\.$#"
count: 1
path: ../../../src/network/mcpe/encryption/PrepareEncryptionTask.php
-
message: "#^Parameter \\#1 \\$socket of function socket_bind expects Socket, resource given\\.$#"
count: 1
path: ../../../src/network/query/DedicatedQueryNetworkInterface.php
-
message: "#^Parameter \\#1 \\$socket of function socket_close expects Socket, resource given\\.$#"
count: 1
path: ../../../src/network/query/DedicatedQueryNetworkInterface.php
-
message: "#^Parameter \\#1 \\$socket of function socket_last_error expects Socket\\|null, resource given\\.$#"
count: 3
path: ../../../src/network/query/DedicatedQueryNetworkInterface.php
-
message: "#^Parameter \\#1 \\$socket of function socket_recvfrom expects Socket, resource given\\.$#"
count: 1
path: ../../../src/network/query/DedicatedQueryNetworkInterface.php
-
message: "#^Parameter \\#1 \\$socket of function socket_sendto expects Socket, resource given\\.$#"
count: 1
path: ../../../src/network/query/DedicatedQueryNetworkInterface.php
-
message: "#^Parameter \\#1 \\$socket of function socket_set_nonblock expects Socket, resource given\\.$#"
count: 1
path: ../../../src/network/query/DedicatedQueryNetworkInterface.php
-
message: "#^Property pocketmine\\\\network\\\\query\\\\DedicatedQueryNetworkInterface\\:\\:\\$socket \\(resource\\) does not accept Socket\\.$#"
count: 1
path: ../../../src/network/query/DedicatedQueryNetworkInterface.php
-
message: "#^Parameter \\#1 \\$ of closure expects resource, CurlHandle given\\.$#"
count: 1
path: ../../../src/utils/Internet.php
-
message: "#^Parameter \\#2 \\$offset of function substr expects int, mixed given\\.$#"
count: 1
path: ../../../src/utils/Internet.php
-
message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, mixed given\\.$#"
count: 1
path: ../../../src/utils/Internet.php
-
message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|false given\\.$#"
count: 1
path: ../../../src/utils/Timezone.php
-
message: "#^Parameter \\#1 \\$timezoneId of function date_default_timezone_set expects string, string\\|false given\\.$#"
count: 1
path: ../../../src/utils/Timezone.php
-
message: "#^Strict comparison using \\=\\=\\= between array\\<string, mixed\\> and false will always evaluate to false\\.$#"
count: 1
path: ../../../src/utils/Timezone.php
-
message: "#^Parameter \\#2 \\$array of function array_map expects array, mixed given\\.$#"
count: 1
path: ../../../src/utils/Utils.php
-
message: "#^Strict comparison using \\=\\=\\= between array and false will always evaluate to false\\.$#"
count: 1
path: ../../../src/utils/Utils.php

View File

@ -30,6 +30,11 @@ parameters:
count: 1
path: ../../../src/entity/projectile/Projectile.php
-
message: "#^Parameter \\#1 \\$read of function socket_select expects array\\<resource\\>\\|null, array\\<int, Socket\\> given\\.$#"
count: 1
path: ../../../src/network/query/DedicatedQueryNetworkInterface.php
-
message: "#^Parameter \\#1 \\$ of closure expects TValue, TValue given\\.$#"
count: 2