More PHP 7.1 nullables

This commit is contained in:
Dylan K. Taylor 2019-02-22 12:55:34 +00:00
parent 73a565355b
commit c26544475e
28 changed files with 50 additions and 50 deletions

View File

@ -609,7 +609,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
* *
* @return PermissionAttachment * @return PermissionAttachment
*/ */
public function addAttachment(Plugin $plugin, string $name = null, bool $value = null) : PermissionAttachment{ public function addAttachment(Plugin $plugin, ?string $name = null, ?bool $value = null) : PermissionAttachment{
return $this->perm->addAttachment($plugin, $name, $value); return $this->perm->addAttachment($plugin, $name, $value);
} }
@ -910,7 +910,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
return false; return false;
} }
protected function unloadChunk(int $x, int $z, Level $level = null){ protected function unloadChunk(int $x, int $z, ?Level $level = null){
$level = $level ?? $this->level; $level = $level ?? $this->level;
$index = Level::chunkHash($x, $z); $index = Level::chunkHash($x, $z);
if(isset($this->usedChunks[$index])){ if(isset($this->usedChunks[$index])){
@ -3132,7 +3132,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
return $result; return $result;
} }
public function sendPosition(Vector3 $pos, float $yaw = null, float $pitch = null, int $mode = MovePlayerPacket::MODE_NORMAL, array $targets = null){ public function sendPosition(Vector3 $pos, ?float $yaw = null, ?float $pitch = null, int $mode = MovePlayerPacket::MODE_NORMAL, ?array $targets = null){
$yaw = $yaw ?? $this->yaw; $yaw = $yaw ?? $this->yaw;
$pitch = $pitch ?? $this->pitch; $pitch = $pitch ?? $this->pitch;
@ -3156,7 +3156,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function teleport(Vector3 $pos, float $yaw = null, float $pitch = null) : bool{ public function teleport(Vector3 $pos, ?float $yaw = null, ?float $pitch = null) : bool{
if(parent::teleport($pos, $yaw, $pitch)){ if(parent::teleport($pos, $yaw, $pitch)){
$this->removeAllWindows(); $this->removeAllWindows();
@ -3298,7 +3298,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
* @throws \InvalidArgumentException if a forceID which is already in use is specified * @throws \InvalidArgumentException if a forceID which is already in use is specified
* @throws \InvalidStateException if trying to add a window without forceID when no slots are free * @throws \InvalidStateException if trying to add a window without forceID when no slots are free
*/ */
public function addWindow(Inventory $inventory, int $forceId = null, bool $isPermanent = false) : int{ public function addWindow(Inventory $inventory, ?int $forceId = null, bool $isPermanent = false) : int{
if(($id = $this->getWindowId($inventory)) !== ContainerIds::NONE){ if(($id = $this->getWindowId($inventory)) !== ContainerIds::NONE){
return $id; return $id;
} }

View File

@ -1333,7 +1333,7 @@ class Server{
* *
* @return int * @return int
*/ */
public function broadcastMessage($message, array $recipients = null) : int{ public function broadcastMessage($message, ?array $recipients = null) : int{
if(!is_array($recipients)){ if(!is_array($recipients)){
return $this->broadcast($message, self::BROADCAST_CHANNEL_USERS); return $this->broadcast($message, self::BROADCAST_CHANNEL_USERS);
} }
@ -1363,7 +1363,7 @@ class Server{
* *
* @return int * @return int
*/ */
public function broadcastTip(string $tip, array $recipients = null) : int{ public function broadcastTip(string $tip, ?array $recipients = null) : int{
$recipients = $recipients ?? $this->selectPermittedPlayers(self::BROADCAST_CHANNEL_USERS); $recipients = $recipients ?? $this->selectPermittedPlayers(self::BROADCAST_CHANNEL_USERS);
/** @var Player[] $recipients */ /** @var Player[] $recipients */
@ -1380,7 +1380,7 @@ class Server{
* *
* @return int * @return int
*/ */
public function broadcastPopup(string $popup, array $recipients = null) : int{ public function broadcastPopup(string $popup, ?array $recipients = null) : int{
$recipients = $recipients ?? $this->selectPermittedPlayers(self::BROADCAST_CHANNEL_USERS); $recipients = $recipients ?? $this->selectPermittedPlayers(self::BROADCAST_CHANNEL_USERS);
/** @var Player[] $recipients */ /** @var Player[] $recipients */
@ -1401,7 +1401,7 @@ class Server{
* *
* @return int * @return int
*/ */
public function broadcastTitle(string $title, string $subtitle = "", int $fadeIn = -1, int $stay = -1, int $fadeOut = -1, array $recipients = null) : int{ public function broadcastTitle(string $title, string $subtitle = "", int $fadeIn = -1, int $stay = -1, int $fadeOut = -1, ?array $recipients = null) : int{
$recipients = $recipients ?? $this->selectPermittedPlayers(self::BROADCAST_CHANNEL_USERS); $recipients = $recipients ?? $this->selectPermittedPlayers(self::BROADCAST_CHANNEL_USERS);
/** @var Player[] $recipients */ /** @var Player[] $recipients */
@ -1916,7 +1916,7 @@ class Server{
* @param string $xboxUserId * @param string $xboxUserId
* @param Player[]|null $players * @param Player[]|null $players
*/ */
public function updatePlayerListData(UUID $uuid, int $entityId, string $name, Skin $skin, string $xboxUserId = "", array $players = null){ public function updatePlayerListData(UUID $uuid, int $entityId, string $name, Skin $skin, string $xboxUserId = "", ?array $players = null){
$pk = new PlayerListPacket(); $pk = new PlayerListPacket();
$pk->type = PlayerListPacket::TYPE_ADD; $pk->type = PlayerListPacket::TYPE_ADD;
@ -1929,7 +1929,7 @@ class Server{
* @param UUID $uuid * @param UUID $uuid
* @param Player[]|null $players * @param Player[]|null $players
*/ */
public function removePlayerListData(UUID $uuid, array $players = null){ public function removePlayerListData(UUID $uuid, ?array $players = null){
$pk = new PlayerListPacket(); $pk = new PlayerListPacket();
$pk->type = PlayerListPacket::TYPE_REMOVE; $pk->type = PlayerListPacket::TYPE_REMOVE;
$pk->entries[] = PlayerListEntry::createRemovalEntry($uuid); $pk->entries[] = PlayerListEntry::createRemovalEntry($uuid);

View File

@ -39,7 +39,7 @@ abstract class Thread extends \Thread{
return $this->classLoader; return $this->classLoader;
} }
public function setClassLoader(\ClassLoader $loader = null){ public function setClassLoader(?\ClassLoader $loader = null){
$this->composerAutoloaderPath = \pocketmine\COMPOSER_AUTOLOADER_PATH; $this->composerAutoloaderPath = \pocketmine\COMPOSER_AUTOLOADER_PATH;
if($loader === null){ if($loader === null){

View File

@ -39,7 +39,7 @@ abstract class Worker extends \Worker{
return $this->classLoader; return $this->classLoader;
} }
public function setClassLoader(\ClassLoader $loader = null){ public function setClassLoader(?\ClassLoader $loader = null){
$this->composerAutoloaderPath = \pocketmine\COMPOSER_AUTOLOADER_PATH; $this->composerAutoloaderPath = \pocketmine\COMPOSER_AUTOLOADER_PATH;
if($loader === null){ if($loader === null){

View File

@ -79,7 +79,7 @@ abstract class Command{
* @param string $usageMessage * @param string $usageMessage
* @param string[] $aliases * @param string[] $aliases
*/ */
public function __construct(string $name, string $description = "", string $usageMessage = null, array $aliases = []){ public function __construct(string $name, string $description = "", ?string $usageMessage = null, array $aliases = []){
$this->name = $name; $this->name = $name;
$this->setLabel($name); $this->setLabel($name);
$this->setDescription($description); $this->setDescription($description);

View File

@ -39,7 +39,7 @@ interface CommandMap{
* *
* @return bool * @return bool
*/ */
public function register(string $fallbackPrefix, Command $command, string $label = null) : bool; public function register(string $fallbackPrefix, Command $command, ?string $label = null) : bool;
/** /**
* @param CommandSender $sender * @param CommandSender $sender

View File

@ -71,7 +71,7 @@ class ConsoleCommandSender implements CommandSender{
* *
* @return PermissionAttachment * @return PermissionAttachment
*/ */
public function addAttachment(Plugin $plugin, string $name = null, bool $value = null) : PermissionAttachment{ public function addAttachment(Plugin $plugin, ?string $name = null, ?bool $value = null) : PermissionAttachment{
return $this->perm->addAttachment($plugin, $name, $value); return $this->perm->addAttachment($plugin, $name, $value);
} }

View File

@ -151,7 +151,7 @@ class SimpleCommandMap implements CommandMap{
* *
* @return bool * @return bool
*/ */
public function register(string $fallbackPrefix, Command $command, string $label = null) : bool{ public function register(string $fallbackPrefix, Command $command, ?string $label = null) : bool{
if($label === null){ if($label === null){
$label = $command->getName(); $label = $command->getName();
} }

View File

@ -141,7 +141,7 @@ class ParticleCommand extends VanillaCommand{
* *
* @return Particle|null * @return Particle|null
*/ */
private function getParticle(string $name, int $data = null){ private function getParticle(string $name, ?int $data = null){
switch($name){ switch($name){
case "explode": case "explode":
return new ExplodeParticle(); return new ExplodeParticle();

View File

@ -38,7 +38,7 @@ class EntityEffectAddEvent extends EntityEffectEvent{
* @param EffectInstance $effect * @param EffectInstance $effect
* @param EffectInstance $oldEffect * @param EffectInstance $oldEffect
*/ */
public function __construct(Entity $entity, EffectInstance $effect, EffectInstance $oldEffect = null){ public function __construct(Entity $entity, EffectInstance $effect, ?EffectInstance $oldEffect = null){
parent::__construct($entity, $effect); parent::__construct($entity, $effect);
$this->oldEffect = $oldEffect; $this->oldEffect = $oldEffect;
} }

View File

@ -52,7 +52,7 @@ class PlayerChatEvent extends PlayerEvent implements Cancellable{
* @param string $format * @param string $format
* @param Player[] $recipients * @param Player[] $recipients
*/ */
public function __construct(Player $player, string $message, string $format = "chat.type.text", array $recipients = null){ public function __construct(Player $player, string $message, string $format = "chat.type.text", ?array $recipients = null){
$this->player = $player; $this->player = $player;
$this->message = $message; $this->message = $message;

View File

@ -57,7 +57,7 @@ abstract class BaseInventory implements Inventory{
* @param int $size * @param int $size
* @param string $title * @param string $title
*/ */
public function __construct(array $items = [], int $size = null, string $title = null){ public function __construct(array $items = [], ?int $size = null, ?string $title = null){
$this->slots = new \SplFixedArray($size ?? $this->getDefaultSize()); $this->slots = new \SplFixedArray($size ?? $this->getDefaultSize());
$this->title = $title ?? $this->getName(); $this->title = $title ?? $this->getName();

View File

@ -33,7 +33,7 @@ abstract class ContainerInventory extends BaseInventory{
/** @var Vector3 */ /** @var Vector3 */
protected $holder; protected $holder;
public function __construct(Vector3 $holder, array $items = [], int $size = null, string $title = null){ public function __construct(Vector3 $holder, array $items = [], ?int $size = null, ?string $title = null){
$this->holder = $holder; $this->holder = $holder;
parent::__construct($items, $size, $title); parent::__construct($items, $size, $title);
} }

View File

@ -38,7 +38,7 @@ class ItemBlock extends Item{
* @param int $meta usually 0-15 (placed blocks may only have meta values 0-15) * @param int $meta usually 0-15 (placed blocks may only have meta values 0-15)
* @param int|null $itemId * @param int|null $itemId
*/ */
public function __construct(int $blockId, int $meta = 0, int $itemId = null){ public function __construct(int $blockId, int $meta = 0, ?int $itemId = null){
if($blockId < 0){ //extended blocks if($blockId < 0){ //extended blocks
if($itemId === null){ if($itemId === null){
$itemId = $blockId; $itemId = $blockId;

View File

@ -94,7 +94,7 @@ class Language{
* *
* @throws LanguageNotFoundException * @throws LanguageNotFoundException
*/ */
public function __construct(string $lang, string $path = null, string $fallback = self::FALLBACK_LANGUAGE){ public function __construct(string $lang, ?string $path = null, string $fallback = self::FALLBACK_LANGUAGE){
$this->langName = strtolower($lang); $this->langName = strtolower($lang);
if($path === null){ if($path === null){
@ -129,7 +129,7 @@ class Language{
* *
* @return string * @return string
*/ */
public function translateString(string $str, array $params = [], string $onlyPrefix = null) : string{ public function translateString(string $str, array $params = [], ?string $onlyPrefix = null) : string{
$baseText = $this->get($str); $baseText = $this->get($str);
$baseText = $this->parseTranslation(($baseText !== null and ($onlyPrefix === null or strpos($str, $onlyPrefix) === 0)) ? $baseText : $str, $onlyPrefix); $baseText = $this->parseTranslation(($baseText !== null and ($onlyPrefix === null or strpos($str, $onlyPrefix) === 0)) ? $baseText : $str, $onlyPrefix);
@ -179,7 +179,7 @@ class Language{
* *
* @return string * @return string
*/ */
protected function parseTranslation(string $text, string $onlyPrefix = null) : string{ protected function parseTranslation(string $text, ?string $onlyPrefix = null) : string{
$newString = ""; $newString = "";
$replaceString = null; $replaceString = null;

View File

@ -478,7 +478,7 @@ class Level implements ChunkManager, Metadatable{
$this->closed = true; $this->closed = true;
} }
public function addSound(Vector3 $pos, Sound $sound, array $players = null){ public function addSound(Vector3 $pos, Sound $sound, ?array $players = null){
$pk = $sound->encode($pos); $pk = $sound->encode($pos);
if(!is_array($pk)){ if(!is_array($pk)){
$pk = [$pk]; $pk = [$pk];
@ -494,7 +494,7 @@ class Level implements ChunkManager, Metadatable{
} }
} }
public function addParticle(Vector3 $pos, Particle $particle, array $players = null){ public function addParticle(Vector3 $pos, Particle $particle, ?array $players = null){
$pk = $particle->encode($pos); $pk = $particle->encode($pos);
if(!is_array($pk)){ if(!is_array($pk)){
$pk = [$pk]; $pk = [$pk];
@ -1626,7 +1626,7 @@ class Level implements ChunkManager, Metadatable{
* *
* @return ItemEntity|null * @return ItemEntity|null
*/ */
public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, int $delay = 10){ public function dropItem(Vector3 $source, Item $item, ?Vector3 $motion = null, int $delay = 10){
$motion = $motion ?? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1); $motion = $motion ?? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1);
$itemTag = $item->nbtSerialize(); $itemTag = $item->nbtSerialize();
$itemTag->setName("Item"); $itemTag->setName("Item");
@ -1686,7 +1686,7 @@ class Level implements ChunkManager, Metadatable{
* *
* @return bool * @return bool
*/ */
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{
$target = $this->getBlock($vector); $target = $this->getBlock($vector);
$affectedBlocks = $target->getAffectedBlocks(); $affectedBlocks = $target->getAffectedBlocks();
@ -1788,7 +1788,7 @@ class Level implements ChunkManager, Metadatable{
* *
* @return bool * @return bool
*/ */
public function useItemOn(Vector3 $vector, Item &$item, int $face, Vector3 $clickVector = null, Player $player = null, bool $playSound = false) : bool{ public function useItemOn(Vector3 $vector, Item &$item, int $face, ?Vector3 $clickVector = null, ?Player $player = null, bool $playSound = false) : bool{
$blockClicked = $this->getBlock($vector); $blockClicked = $this->getBlock($vector);
$blockReplace = $blockClicked->getSide($face); $blockReplace = $blockClicked->getSide($face);
@ -1928,7 +1928,7 @@ class Level implements ChunkManager, Metadatable{
* *
* @return Entity[] * @return Entity[]
*/ */
public function getCollidingEntities(AxisAlignedBB $bb, Entity $entity = null) : array{ public function getCollidingEntities(AxisAlignedBB $bb, ?Entity $entity = null) : array{
$nearby = []; $nearby = [];
if($entity === null or $entity->canCollide){ if($entity === null or $entity->canCollide){
@ -1960,7 +1960,7 @@ class Level implements ChunkManager, Metadatable{
* *
* @return Entity[] * @return Entity[]
*/ */
public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null) : array{ public function getNearbyEntities(AxisAlignedBB $bb, ?Entity $entity = null) : array{
$nearby = []; $nearby = [];
$minX = ((int) floor($bb->minX - 2)) >> 4; $minX = ((int) floor($bb->minX - 2)) >> 4;

View File

@ -259,7 +259,7 @@ class LevelManager{
* @return bool * @return bool
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function generateLevel(string $name, int $seed = null, string $generator = Normal::class, array $options = [], bool $backgroundGeneration = true) : bool{ public function generateLevel(string $name, ?int $seed = null, string $generator = Normal::class, array $options = [], bool $backgroundGeneration = true) : bool{
if(trim($name) === "" or $this->isLevelGenerated($name)){ if(trim($name) === "" or $this->isLevelGenerated($name)){
return false; return false;
} }

View File

@ -40,7 +40,7 @@ class Location extends Position{
* @param float $pitch * @param float $pitch
* @param Level $level * @param Level $level
*/ */
public function __construct($x = 0, $y = 0, $z = 0, $yaw = 0.0, $pitch = 0.0, Level $level = null){ public function __construct($x = 0, $y = 0, $z = 0, $yaw = 0.0, $pitch = 0.0, ?Level $level = null){
$this->yaw = $yaw; $this->yaw = $yaw;
$this->pitch = $pitch; $this->pitch = $pitch;
parent::__construct($x, $y, $z, $level); parent::__construct($x, $y, $z, $level);
@ -54,7 +54,7 @@ class Location extends Position{
* *
* @return Location * @return Location
*/ */
public static function fromObject(Vector3 $pos, Level $level = null, $yaw = 0.0, $pitch = 0.0) : Location{ public static function fromObject(Vector3 $pos, ?Level $level = null, $yaw = 0.0, $pitch = 0.0) : Location{
return new Location($pos->x, $pos->y, $pos->z, $yaw, $pitch, $level ?? (($pos instanceof Position) ? $pos->level : null)); return new Location($pos->x, $pos->y, $pos->z, $yaw, $pitch, $level ?? (($pos instanceof Position) ? $pos->level : null));
} }

View File

@ -37,12 +37,12 @@ class Position extends Vector3{
* @param int $z * @param int $z
* @param Level $level * @param Level $level
*/ */
public function __construct($x = 0, $y = 0, $z = 0, Level $level = null){ public function __construct($x = 0, $y = 0, $z = 0, ?Level $level = null){
parent::__construct($x, $y, $z); parent::__construct($x, $y, $z);
$this->setLevel($level); $this->setLevel($level);
} }
public static function fromObject(Vector3 $pos, Level $level = null){ public static function fromObject(Vector3 $pos, ?Level $level = null){
return new Position($pos->x, $pos->y, $pos->z, $level); return new Position($pos->x, $pos->y, $pos->z, $level);
} }

View File

@ -118,7 +118,7 @@ class BanList{
* *
* @return BanEntry * @return BanEntry
*/ */
public function addBan(string $target, string $reason = null, \DateTime $expires = null, string $source = null) : BanEntry{ public function addBan(string $target, ?string $reason = null, ?\DateTime $expires = null, ?string $source = null) : BanEntry{
$entry = new BanEntry($target); $entry = new BanEntry($target);
$entry->setSource($source ?? $entry->getSource()); $entry->setSource($source ?? $entry->getSource());
$entry->setExpires($expires); $entry->setExpires($expires);

View File

@ -35,7 +35,7 @@ abstract class DefaultPermissions{
* *
* @return Permission * @return Permission
*/ */
public static function registerPermission(Permission $perm, Permission $parent = null) : Permission{ public static function registerPermission(Permission $perm, ?Permission $parent = null) : Permission{
if($parent instanceof Permission){ if($parent instanceof Permission){
$parent->getChildren()[$perm->getName()] = true; $parent->getChildren()[$perm->getName()] = true;

View File

@ -52,7 +52,7 @@ interface Permissible extends ServerOperator{
* *
* @return PermissionAttachment * @return PermissionAttachment
*/ */
public function addAttachment(Plugin $plugin, string $name = null, bool $value = null) : PermissionAttachment; public function addAttachment(Plugin $plugin, ?string $name = null, ?bool $value = null) : PermissionAttachment;
/** /**
* @param PermissionAttachment $attachment * @param PermissionAttachment $attachment

View File

@ -111,7 +111,7 @@ class PermissibleBase implements Permissible{
* *
* @return PermissionAttachment * @return PermissionAttachment
*/ */
public function addAttachment(Plugin $plugin, string $name = null, bool $value = null) : PermissionAttachment{ public function addAttachment(Plugin $plugin, ?string $name = null, ?bool $value = null) : PermissionAttachment{
if(!$plugin->isEnabled()){ if(!$plugin->isEnabled()){
throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled"); throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled");
} }

View File

@ -60,7 +60,7 @@ class Permission{
* @param string $defaultValue * @param string $defaultValue
* @param bool[] $children * @param bool[] $children
*/ */
public function __construct(string $name, string $description = null, string $defaultValue = null, array $children = []){ public function __construct(string $name, ?string $description = null, ?string $defaultValue = null, array $children = []){
$this->name = $name; $this->name = $name;
$this->description = $description ?? ""; $this->description = $description ?? "";
$this->defaultValue = $defaultValue ?? self::$DEFAULT_PERMISSION; $this->defaultValue = $defaultValue ?? self::$DEFAULT_PERMISSION;

View File

@ -137,7 +137,7 @@ class PluginManager{
* *
* @return Plugin|null * @return Plugin|null
*/ */
public function loadPlugin(string $path, array $loaders = null) : ?Plugin{ public function loadPlugin(string $path, ?array $loaders = null) : ?Plugin{
foreach($loaders ?? $this->fileAssociations as $loader){ foreach($loaders ?? $this->fileAssociations as $loader){
if($loader->canLoadPlugin($path)){ if($loader->canLoadPlugin($path)){
$description = $loader->getPluginDescription($path); $description = $loader->getPluginDescription($path);
@ -193,7 +193,7 @@ class PluginManager{
* *
* @return Plugin[] * @return Plugin[]
*/ */
public function loadPlugins(string $directory, array $newLoaders = null){ public function loadPlugins(string $directory, ?array $newLoaders = null){
if(!is_dir($directory)){ if(!is_dir($directory)){
return []; return [];
} }

View File

@ -150,7 +150,7 @@ class TimingsHandler{
* @param string $name * @param string $name
* @param TimingsHandler $parent * @param TimingsHandler $parent
*/ */
public function __construct(string $name, TimingsHandler $parent = null){ public function __construct(string $name, ?TimingsHandler $parent = null){
$this->name = $name; $this->name = $name;
$this->parent = $parent; $this->parent = $parent;

View File

@ -193,7 +193,7 @@ class Internet{
* *
* @throws InternetException if a cURL error occurs * @throws InternetException if a cURL error occurs
*/ */
public static function simpleCurl(string $page, $timeout = 10, array $extraHeaders = [], array $extraOpts = [], callable $onSuccess = null){ public static function simpleCurl(string $page, $timeout = 10, array $extraHeaders = [], array $extraOpts = [], ?callable $onSuccess = null){
if(!self::$online){ if(!self::$online){
throw new InternetException("Cannot execute web request while offline"); throw new InternetException("Cannot execute web request while offline");
} }

View File

@ -41,7 +41,7 @@ class UUID{
private $parts = [0, 0, 0, 0]; private $parts = [0, 0, 0, 0];
private $version = null; private $version = null;
public function __construct(int $part1 = 0, int $part2 = 0, int $part3 = 0, int $part4 = 0, int $version = null){ public function __construct(int $part1 = 0, int $part2 = 0, int $part3 = 0, int $part4 = 0, ?int $version = null){
$this->parts = [$part1, $part2, $part3, $part4]; $this->parts = [$part1, $part2, $part3, $part4];
$this->version = $version ?? ($this->parts[1] & 0xf000) >> 12; $this->version = $version ?? ($this->parts[1] & 0xf000) >> 12;
@ -63,7 +63,7 @@ class UUID{
* *
* @return UUID * @return UUID
*/ */
public static function fromString(string $uuid, int $version = null) : UUID{ public static function fromString(string $uuid, ?int $version = null) : UUID{
return self::fromBinary(hex2bin(str_replace("-", "", trim($uuid))), $version); return self::fromBinary(hex2bin(str_replace("-", "", trim($uuid))), $version);
} }
@ -77,7 +77,7 @@ class UUID{
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public static function fromBinary(string $uuid, int $version = null) : UUID{ public static function fromBinary(string $uuid, ?int $version = null) : UUID{
if(strlen($uuid) !== 16){ if(strlen($uuid) !== 16){
throw new \InvalidArgumentException("Must have exactly 16 bytes"); throw new \InvalidArgumentException("Must have exactly 16 bytes");
} }