Modernize property declarations in src/utils

This commit is contained in:
Dylan K. Taylor 2022-04-28 13:12:12 +01:00
parent de12b701ac
commit 0e7e776862
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
7 changed files with 34 additions and 71 deletions

View File

@ -74,23 +74,19 @@ class Config{
* @var mixed[] * @var mixed[]
* @phpstan-var array<string, mixed> * @phpstan-var array<string, mixed>
*/ */
private $config = []; private array $config = [];
/** /**
* @var mixed[] * @var mixed[]
* @phpstan-var array<string, mixed> * @phpstan-var array<string, mixed>
*/ */
private $nestedCache = []; private array $nestedCache = [];
/** @var string */ private string $file;
private $file; private int $type = Config::DETECT;
/** @var int */ private int $jsonOptions = JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING;
private $type = Config::DETECT;
/** @var int */
private $jsonOptions = JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING;
/** @var bool */ private bool $changed = false;
private $changed = false;
/** @var int[] */ /** @var int[] */
public static $formats = [ public static $formats = [

View File

@ -61,12 +61,12 @@ use const SCANDIR_SORT_NONE;
final class Filesystem{ final class Filesystem{
/** @var resource[] */ /** @var resource[] */
private static $lockFileHandles = []; private static array $lockFileHandles = [];
/** /**
* @var string[] * @var string[]
* @phpstan-var array<string, string> * @phpstan-var array<string, string>
*/ */
private static $cleanedPaths = [ private static array $cleanedPaths = [
\pocketmine\PATH => self::CLEAN_PATH_SRC_PREFIX \pocketmine\PATH => self::CLEAN_PATH_SRC_PREFIX
]; ];

View File

@ -24,26 +24,15 @@ declare(strict_types=1);
namespace pocketmine\utils; namespace pocketmine\utils;
final class InternetRequestResult{ final class InternetRequestResult{
/**
* @var string[][]
* @phpstan-var list<array<string, string>>
*/
private $headers;
/** @var string */
private $body;
/** @var int */
private $code;
/** /**
* @param string[][] $headers * @param string[][] $headers
* @phpstan-param list<array<string, string>> $headers * @phpstan-param list<array<string, string>> $headers
*/ */
public function __construct(array $headers, string $body, int $code){ public function __construct(
$this->headers = $headers; private array $headers,
$this->body = $body; private string $body,
$this->code = $code; private int $code
} ){}
/** /**
* @return string[][] * @return string[][]

View File

@ -35,17 +35,10 @@ class Random{
public const Z = 521288629; public const Z = 521288629;
public const W = 88675123; public const W = 88675123;
/** @var int */ private int $x;
private $x; private int $y;
private int $z;
/** @var int */ private int $w;
private $y;
/** @var int */
private $z;
/** @var int */
private $w;
/** @var int */ /** @var int */
protected $seed; protected $seed;

View File

@ -60,8 +60,7 @@ abstract class Terminal{
public static string $COLOR_WHITE = ""; public static string $COLOR_WHITE = "";
public static string $COLOR_MINECOIN_GOLD = ""; public static string $COLOR_MINECOIN_GOLD = "";
/** @var bool|null */ private static ?bool $formattingCodes = null;
private static $formattingCodes = null;
public static function hasFormattingCodes() : bool{ public static function hasFormattingCodes() : bool{
if(self::$formattingCodes === null){ if(self::$formattingCodes === null){

View File

@ -105,10 +105,8 @@ final class Utils{
public const OS_BSD = "bsd"; public const OS_BSD = "bsd";
public const OS_UNKNOWN = "other"; public const OS_UNKNOWN = "other";
/** @var string|null */ private static ?string $os;
private static $os; private static ?UuidInterface $serverUniqueId = null;
/** @var UuidInterface|null */
private static $serverUniqueId = null;
/** /**
* Returns a readable identifier for the given Closure, including file and line. * Returns a readable identifier for the given Closure, including file and line.

View File

@ -30,28 +30,16 @@ use function preg_match;
* Manages PocketMine-MP version strings, and compares them * Manages PocketMine-MP version strings, and compares them
*/ */
class VersionString{ class VersionString{
/** @var string */ private int $major;
private $baseVersion; private int $minor;
/** @var string */ private int $patch;
private $suffix; private string $suffix;
/** @var int */
private $major;
/** @var int */
private $minor;
/** @var int */
private $patch;
/** @var int */
private $build;
/** @var bool */
private $development = false;
public function __construct(string $baseVersion, bool $isDevBuild = false, int $buildNumber = 0){
$this->baseVersion = $baseVersion;
$this->development = $isDevBuild;
$this->build = $buildNumber;
public function __construct(
private string $baseVersion,
private bool $isDevBuild = false,
private int $buildNumber = 0
){
preg_match('/^(\d+)\.(\d+)\.(\d+)(?:-(.*))?$/', $this->baseVersion, $matches); preg_match('/^(\d+)\.(\d+)\.(\d+)(?:-(.*))?$/', $this->baseVersion, $matches);
if(count($matches) < 4){ if(count($matches) < 4){
throw new \InvalidArgumentException("Invalid base version \"$baseVersion\", should contain at least 3 version digits"); throw new \InvalidArgumentException("Invalid base version \"$baseVersion\", should contain at least 3 version digits");
@ -77,10 +65,10 @@ class VersionString{
public function getFullVersion(bool $build = false) : string{ public function getFullVersion(bool $build = false) : string{
$retval = $this->baseVersion; $retval = $this->baseVersion;
if($this->development){ if($this->isDevBuild){
$retval .= "+dev"; $retval .= "+dev";
if($build && $this->build > 0){ if($build && $this->buildNumber > 0){
$retval .= "." . $this->build; $retval .= "." . $this->buildNumber;
} }
} }
@ -104,11 +92,11 @@ class VersionString{
} }
public function getBuild() : int{ public function getBuild() : int{
return $this->build; return $this->buildNumber;
} }
public function isDev() : bool{ public function isDev() : bool{
return $this->development; return $this->isDevBuild;
} }
public function __toString() : string{ public function __toString() : string{