PHPStan 1.9 features

This commit is contained in:
Dylan K. Taylor 2022-11-04 20:23:34 +00:00
parent bfd1b2c635
commit 2fdc46c165
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
13 changed files with 40 additions and 1 deletions

View File

@ -398,7 +398,7 @@ class MemoryManager{
do{ do{
$continue = false; $continue = false;
foreach($objects as $hash => $object){ foreach(Utils::stringifyKeys($objects) as $hash => $object){
if(!is_object($object)){ if(!is_object($object)){
continue; continue;
} }
@ -483,6 +483,11 @@ class MemoryManager{
* @param object[] $objects reference parameter * @param object[] $objects reference parameter
* @param int[] $refCounts reference parameter * @param int[] $refCounts reference parameter
* *
* @phpstan-param array<string, object> $objects
* @phpstan-param array<string, int> $refCounts
* @phpstan-param-out array<string, object> $objects
* @phpstan-param-out array<string, int> $refCounts
*
* @return mixed * @return mixed
*/ */
private static function continueDump($from, array &$objects, array &$refCounts, int $recursion, int $maxNesting, int $maxStringSize){ private static function continueDump($from, array &$objects, array &$refCounts, int $recursion, int $maxNesting, int $maxStringSize){

View File

@ -84,6 +84,7 @@ class Leaves extends Transparent{
/** /**
* @param true[] $visited reference parameter * @param true[] $visited reference parameter
* @phpstan-param array<int, true> $visited * @phpstan-param array<int, true> $visited
* @phpstan-param-out array<int, true> $visited
*/ */
protected function findLog(Vector3 $pos, array &$visited = [], int $distance = 0) : bool{ protected function findLog(Vector3 $pos, array &$visited = [], int $distance = 0) : bool{
$index = World::blockHash($pos->x, $pos->y, $pos->z); $index = World::blockHash($pos->x, $pos->y, $pos->z);

View File

@ -134,6 +134,8 @@ class InventoryTransaction{
/** /**
* @param Item[] $needItems * @param Item[] $needItems
* @param Item[] $haveItems * @param Item[] $haveItems
* @phpstan-param-out Item[] $needItems
* @phpstan-param-out Item[] $haveItems
* *
* @throws TransactionValidationException * @throws TransactionValidationException
*/ */

View File

@ -169,6 +169,7 @@ final class ItemTranslator{
} }
/** /**
* @phpstan-param-out bool $isComplexMapping
* @return int[] * @return int[]
* @phpstan-return array{int, int} * @phpstan-return array{int, int}
* @throws TypeConversionException * @throws TypeConversionException

View File

@ -150,6 +150,7 @@ class UPnP{
throw new UPnPException("Failed to recognize the port number from the router's url: {$location}"); throw new UPnPException("Failed to recognize the port number from the router's url: {$location}");
} }
$urlPort = $url['port']; $urlPort = $url['port'];
$err = "";
$response = Internet::getURL($location, 3, [], $err); $response = Internet::getURL($location, 3, [], $err);
if($response === null){ if($response === null){
throw new UPnPException("Unable to access XML: {$err}"); throw new UPnPException("Unable to access XML: {$err}");

View File

@ -316,6 +316,9 @@ class PluginManager{
/** /**
* @param string[][] $dependencyLists * @param string[][] $dependencyLists
* @param Plugin[] $loadedPlugins * @param Plugin[] $loadedPlugins
*
* @phpstan-param array<string, list<string>> $dependencyLists
* @phpstan-param-out array<string, list<string>> $dependencyLists
*/ */
private function checkDepsForTriage(string $pluginName, string $dependencyType, array &$dependencyLists, array $loadedPlugins, PluginLoadTriage $triage) : void{ private function checkDepsForTriage(string $pluginName, string $dependencyType, array &$dependencyLists, array $loadedPlugins, PluginLoadTriage $triage) : void{
if(isset($dependencyLists[$pluginName])){ if(isset($dependencyLists[$pluginName])){

View File

@ -496,6 +496,7 @@ class Config{
* @param mixed[] $data reference parameter * @param mixed[] $data reference parameter
* @phpstan-param array<string, mixed> $default * @phpstan-param array<string, mixed> $default
* @phpstan-param array<string, mixed> $data * @phpstan-param array<string, mixed> $data
* @phpstan-param-out array<string, mixed> $data
*/ */
private function fillDefaults(array $default, &$data) : int{ private function fillDefaults(array $default, &$data) : int{
$changed = 0; $changed = 0;

View File

@ -139,10 +139,14 @@ class Internet{
* GETs an URL using cURL * GETs an URL using cURL
* NOTE: This is a blocking operation and can take a significant amount of time. It is inadvisable to use this method on the main thread. * NOTE: This is a blocking operation and can take a significant amount of time. It is inadvisable to use this method on the main thread.
* *
* @phpstan-template TErrorVar of mixed
*
* @param int $timeout default 10 * @param int $timeout default 10
* @param string[] $extraHeaders * @param string[] $extraHeaders
* @param string|null $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. * @param string|null $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation.
* @phpstan-param list<string> $extraHeaders * @phpstan-param list<string> $extraHeaders
* @phpstan-param TErrorVar $err
* @phpstan-param-out TErrorVar|string $err
*/ */
public static function getURL(string $page, int $timeout = 10, array $extraHeaders = [], &$err = null) : ?InternetRequestResult{ public static function getURL(string $page, int $timeout = 10, array $extraHeaders = [], &$err = null) : ?InternetRequestResult{
try{ try{
@ -157,11 +161,15 @@ class Internet{
* POSTs data to an URL * POSTs data to an URL
* NOTE: This is a blocking operation and can take a significant amount of time. It is inadvisable to use this method on the main thread. * NOTE: This is a blocking operation and can take a significant amount of time. It is inadvisable to use this method on the main thread.
* *
* @phpstan-template TErrorVar of mixed
*
* @param string[]|string $args * @param string[]|string $args
* @param string[] $extraHeaders * @param string[] $extraHeaders
* @param string|null $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occurred during the operation. * @param string|null $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occurred during the operation.
* @phpstan-param string|array<string, string> $args * @phpstan-param string|array<string, string> $args
* @phpstan-param list<string> $extraHeaders * @phpstan-param list<string> $extraHeaders
* @phpstan-param TErrorVar $err
* @phpstan-param-out TErrorVar|string $err
*/ */
public static function postURL(string $page, $args, int $timeout = 10, array $extraHeaders = [], &$err = null) : ?InternetRequestResult{ public static function postURL(string $page, $args, int $timeout = 10, array $extraHeaders = [], &$err = null) : ?InternetRequestResult{
try{ try{

View File

@ -152,6 +152,8 @@ final class Process{
* @param string $command Command to execute * @param string $command Command to execute
* @param string|null $stdout Reference parameter to write stdout to * @param string|null $stdout Reference parameter to write stdout to
* @param string|null $stderr Reference parameter to write stderr to * @param string|null $stderr Reference parameter to write stderr to
* @phpstan-param-out string $stdout
* @phpstan-param-out string $stderr
* *
* @return int process exit code * @return int process exit code
*/ */

View File

@ -396,6 +396,9 @@ class World implements ChunkManager{
/** /**
* @phpstan-param BlockPosHash $hash * @phpstan-param BlockPosHash $hash
* @phpstan-param-out int $x
* @phpstan-param-out int $y
* @phpstan-param-out int $z
*/ */
public static function getBlockXYZ(int $hash, ?int &$x, ?int &$y, ?int &$z) : void{ public static function getBlockXYZ(int $hash, ?int &$x, ?int &$y, ?int &$z) : void{
[$baseX, $baseY, $baseZ] = morton3d_decode($hash); [$baseX, $baseY, $baseZ] = morton3d_decode($hash);
@ -410,6 +413,8 @@ class World implements ChunkManager{
/** /**
* @phpstan-param ChunkPosHash $hash * @phpstan-param ChunkPosHash $hash
* @phpstan-param-out int $x
* @phpstan-param-out int $z
*/ */
public static function getXZ(int $hash, ?int &$x, ?int &$z) : void{ public static function getXZ(int $hash, ?int &$x, ?int &$z) : void{
[$x, $z] = morton2d_decode($hash); [$x, $z] = morton2d_decode($hash);
@ -1764,6 +1769,7 @@ class World implements ChunkManager{
* It'll try to lower the durability if Item is a tool, and set it to Air if broken. * It'll try to lower the durability if Item is a tool, and set it to Air if broken.
* *
* @param Item $item reference parameter (if null, can break anything) * @param Item $item reference parameter (if null, can break anything)
* @phpstan-param-out Item $item
*/ */
public function useBreakOn(Vector3 $vector, Item &$item = null, ?Player $player = null, bool $createParticles = false) : bool{ public function useBreakOn(Vector3 $vector, Item &$item = null, ?Player $player = null, bool $createParticles = false) : bool{
$vector = $vector->floor(); $vector = $vector->floor();

View File

@ -191,6 +191,11 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
return PalettedBlockArray::fromData($bitsPerBlock, $words, $palette); return PalettedBlockArray::fromData($bitsPerBlock, $words, $palette);
} }
/**
* @phpstan-param-out int $x
* @phpstan-param-out int $y
* @phpstan-param-out int $z
*/
protected static function deserializeExtraDataKey(int $chunkVersion, int $key, ?int &$x, ?int &$y, ?int &$z) : void{ protected static function deserializeExtraDataKey(int $chunkVersion, int $key, ?int &$x, ?int &$y, ?int &$z) : void{
if($chunkVersion >= ChunkVersion::v1_0_0){ if($chunkVersion >= ChunkVersion::v1_0_0){
$x = ($key >> 12) & 0xf; $x = ($key >> 12) & 0xf;

View File

@ -276,6 +276,8 @@ class RegionLoader{
/** /**
* @param int $x reference parameter * @param int $x reference parameter
* @param int $z reference parameter * @param int $z reference parameter
* @phpstan-param-out int $x
* @phpstan-param-out int $z
*/ */
protected static function getChunkCoords(int $offset, ?int &$x, ?int &$z) : void{ protected static function getChunkCoords(int $offset, ?int &$x, ?int &$z) : void{
$x = $offset & 0x1f; $x = $offset & 0x1f;

View File

@ -92,6 +92,8 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
/** /**
* @param int $regionX reference parameter * @param int $regionX reference parameter
* @param int $regionZ reference parameter * @param int $regionZ reference parameter
* @phpstan-param-out int $regionX
* @phpstan-param-out int $regionZ
*/ */
public static function getRegionIndex(int $chunkX, int $chunkZ, &$regionX, &$regionZ) : void{ public static function getRegionIndex(int $chunkX, int $chunkZ, &$regionX, &$regionZ) : void{
$regionX = $chunkX >> 5; $regionX = $chunkX >> 5;