Merge branch 'minor-next' into major-next

This commit is contained in:
Dylan K. Taylor 2025-02-18 01:26:08 +00:00
commit c637d852e2
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
7 changed files with 29 additions and 75 deletions

View File

@ -52,7 +52,7 @@
"symfony/filesystem": "~6.4.0" "symfony/filesystem": "~6.4.0"
}, },
"require-dev": { "require-dev": {
"phpstan/phpstan": "2.1.4", "phpstan/phpstan": "2.1.5",
"phpstan/phpstan-phpunit": "^2.0.0", "phpstan/phpstan-phpunit": "^2.0.0",
"phpstan/phpstan-strict-rules": "^2.0.0", "phpstan/phpstan-strict-rules": "^2.0.0",
"phpunit/phpunit": "^10.5.24" "phpunit/phpunit": "^10.5.24"

12
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "663122b8f03ef5ec6718a419923a0851", "content-hash": "d63e9f0240056c52c10113b305010130",
"packages": [ "packages": [
{ {
"name": "adhocore/json-comment", "name": "adhocore/json-comment",
@ -1386,16 +1386,16 @@
}, },
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",
"version": "2.1.4", "version": "2.1.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "8f99e18eb775dbaf6460c95fa0b65312da9c746a" "reference": "451b17f9665481ee502adc39be987cb71067ece2"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/8f99e18eb775dbaf6460c95fa0b65312da9c746a", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/451b17f9665481ee502adc39be987cb71067ece2",
"reference": "8f99e18eb775dbaf6460c95fa0b65312da9c746a", "reference": "451b17f9665481ee502adc39be987cb71067ece2",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1440,7 +1440,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2025-02-10T08:25:21+00:00" "time": "2025-02-13T12:49:56+00:00"
}, },
{ {
"name": "phpstan/phpstan-phpunit", "name": "phpstan/phpstan-phpunit",

View File

@ -704,7 +704,7 @@ class Server{
public function removeOp(string $name) : void{ public function removeOp(string $name) : void{
$lowercaseName = strtolower($name); $lowercaseName = strtolower($name);
foreach($this->operators->getAll() as $operatorName => $_){ foreach(Utils::promoteKeys($this->operators->getAll()) as $operatorName => $_){
$operatorName = (string) $operatorName; $operatorName = (string) $operatorName;
if($lowercaseName === strtolower($operatorName)){ if($lowercaseName === strtolower($operatorName)){
$this->operators->remove($operatorName); $this->operators->remove($operatorName);

View File

@ -29,8 +29,12 @@ use pocketmine\nbt\TreeRoot;
use pocketmine\utils\BinaryStream; use pocketmine\utils\BinaryStream;
use pocketmine\utils\DestructorCallbackTrait; use pocketmine\utils\DestructorCallbackTrait;
use pocketmine\utils\ObjectSet; use pocketmine\utils\ObjectSet;
use function array_shift;
use function count;
use function implode;
use function ksort;
use function spl_object_id; use function spl_object_id;
use function usort; use const SORT_STRING;
class CraftingManager{ class CraftingManager{
use DestructorCallbackTrait; use DestructorCallbackTrait;
@ -100,6 +104,7 @@ class CraftingManager{
/** /**
* Function used to arrange Shapeless Recipe ingredient lists into a consistent order. * Function used to arrange Shapeless Recipe ingredient lists into a consistent order.
* @deprecated
*/ */
public static function sort(Item $i1, Item $i2) : int{ public static function sort(Item $i1, Item $i2) : int{
//Use spaceship operator to compare each property, then try the next one if they are equivalent. //Use spaceship operator to compare each property, then try the next one if they are equivalent.
@ -108,45 +113,30 @@ class CraftingManager{
return $retval; return $retval;
} }
/** private static function hashOutput(Item $output) : string{
* @param Item[] $items $write = new BinaryStream();
* $write->putVarInt($output->getStateId());
* @return Item[] $write->put((new LittleEndianNbtSerializer())->write(new TreeRoot($output->getNamedTag())));
* @phpstan-return list<Item>
*/
private static function pack(array $items) : array{
$result = [];
foreach($items as $item){ return $write->getBuffer();
foreach($result as $otherItem){
if($item->canStackWith($otherItem)){
$otherItem->setCount($otherItem->getCount() + $item->getCount());
continue 2;
}
}
//No matching item found
$result[] = clone $item;
}
return $result;
} }
/** /**
* @param Item[] $outputs * @param Item[] $outputs
*/ */
private static function hashOutputs(array $outputs) : string{ private static function hashOutputs(array $outputs) : string{
$outputs = self::pack($outputs); if(count($outputs) === 1){
usort($outputs, [self::class, "sort"]); return self::hashOutput(array_shift($outputs));
$result = new BinaryStream(); }
$unique = [];
foreach($outputs as $o){ foreach($outputs as $o){
//count is not written because the outputs might be from multiple repetitions of a single recipe //count is not written because the outputs might be from multiple repetitions of a single recipe
//this reduces the accuracy of the hash, but it won't matter in most cases. //this reduces the accuracy of the hash, but it won't matter in most cases.
$result->putVarInt($o->getStateId()); $hash = self::hashOutput($o);
$result->put((new LittleEndianNbtSerializer())->write(new TreeRoot($o->getNamedTag()))); $unique[$hash] = $hash;
} }
ksort($unique, SORT_STRING);
return $result->getBuffer(); return implode("", $unique);
} }
/** /**

View File

@ -587,7 +587,7 @@ final class Utils{
* @phpstan-param \Closure(TMemberType) : void $validator * @phpstan-param \Closure(TMemberType) : void $validator
*/ */
public static function validateArrayValueType(array $array, \Closure $validator) : void{ public static function validateArrayValueType(array $array, \Closure $validator) : void{
foreach($array as $k => $v){ foreach(Utils::promoteKeys($array) as $k => $v){
try{ try{
$validator($v); $validator($v);
}catch(\TypeError $e){ }catch(\TypeError $e){

View File

@ -48,12 +48,6 @@ parameters:
count: 1 count: 1
path: ../../../src/VersionInfo.php path: ../../../src/VersionInfo.php
-
message: '#^Method pocketmine\\VersionInfo\:\:GIT_HASH\(\) should return string but returns mixed\.$#'
identifier: return.type
count: 1
path: ../../../src/VersionInfo.php
- -
message: '#^Static property pocketmine\\VersionInfo\:\:\$gitHash \(string\|null\) does not accept mixed\.$#' message: '#^Static property pocketmine\\VersionInfo\:\:\$gitHash \(string\|null\) does not accept mixed\.$#'
identifier: assign.propertyType identifier: assign.propertyType
@ -918,24 +912,6 @@ parameters:
count: 1 count: 1
path: ../../../src/plugin/PluginDescription.php path: ../../../src/plugin/PluginDescription.php
-
message: '#^Parameter \#1 \$haystack of function stripos expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: ../../../src/plugin/PluginDescription.php
-
message: '#^Parameter \#2 \$subject of function preg_match expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: ../../../src/plugin/PluginDescription.php
-
message: '#^Parameter \#3 \$subject of function str_replace expects array\<string\>\|string, mixed given\.$#'
identifier: argument.type
count: 1
path: ../../../src/plugin/PluginDescription.php
- -
message: '#^Property pocketmine\\plugin\\PluginDescription\:\:\$authors \(array\<string\>\) does not accept list\<mixed\>\.$#' message: '#^Property pocketmine\\plugin\\PluginDescription\:\:\$authors \(array\<string\>\) does not accept list\<mixed\>\.$#'
identifier: assign.propertyType identifier: assign.propertyType
@ -966,12 +942,6 @@ parameters:
count: 1 count: 1
path: ../../../src/resourcepacks/ZippedResourcePack.php path: ../../../src/resourcepacks/ZippedResourcePack.php
-
message: '#^Method pocketmine\\resourcepacks\\ZippedResourcePack\:\:getSha256\(\) should return string but returns string\|false\.$#'
identifier: return.type
count: 1
path: ../../../src/resourcepacks/ZippedResourcePack.php
- -
message: '#^Property pocketmine\\resourcepacks\\ZippedResourcePack\:\:\$fileResource \(resource\) does not accept resource\|false\.$#' message: '#^Property pocketmine\\resourcepacks\\ZippedResourcePack\:\:\$fileResource \(resource\) does not accept resource\|false\.$#'
identifier: assign.propertyType identifier: assign.propertyType
@ -1009,7 +979,7 @@ parameters:
path: ../../../src/utils/Config.php path: ../../../src/utils/Config.php
- -
message: '#^Parameter \#1 \$config of static method pocketmine\\utils\\Config\:\:writeProperties\(\) expects array\<int\|string, bool\|float\|int\|string\>, array\<int\|string, mixed\> given\.$#' message: '#^Parameter \#1 \$config of static method pocketmine\\utils\\Config\:\:writeProperties\(\) expects array\<int\|string, bool\|float\|int\|string\>, array\<mixed\> given\.$#'
identifier: argument.type identifier: argument.type
count: 1 count: 1
path: ../../../src/utils/Config.php path: ../../../src/utils/Config.php

View File

@ -114,12 +114,6 @@ parameters:
count: 1 count: 1
path: ../../../src/crash/CrashDump.php path: ../../../src/crash/CrashDump.php
-
message: '#^Call to function assert\(\) with false and ''unknown hit type'' will always evaluate to false\.$#'
identifier: function.impossibleType
count: 1
path: ../../../src/entity/projectile/Projectile.php
- -
message: '#^Property pocketmine\\item\\WritableBookBase\:\:\$pages \(list\<pocketmine\\item\\WritableBookPage\>\) does not accept non\-empty\-array\<int, pocketmine\\item\\WritableBookPage\>\.$#' message: '#^Property pocketmine\\item\\WritableBookBase\:\:\$pages \(list\<pocketmine\\item\\WritableBookPage\>\) does not accept non\-empty\-array\<int, pocketmine\\item\\WritableBookPage\>\.$#'
identifier: assign.propertyType identifier: assign.propertyType