Skip to content

Commit

Permalink
Fix implicitly nullable function arguments (#1973)
Browse files Browse the repository at this point in the history
In PHP 8.4, making function arguments implicitly nullable via a null
default value is deprecated. The specified type must be explicitly
nullable.

No functionality changes.
  • Loading branch information
hemberger authored Dec 5, 2024
1 parent 07bbb2f commit bd7d8d0
Show file tree
Hide file tree
Showing 22 changed files with 90 additions and 90 deletions.
8 changes: 4 additions & 4 deletions src/lib/Default/smr.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function inify(string $text): string {
return str_replace(',', '', html_entity_decode($text));
}

function bbify(string $message, int $gameID = null, bool $noLinks = false): string {
function bbify(string $message, ?int $gameID = null, bool $noLinks = false): string {
static $bbParser;
if (!isset($bbParser)) {
$bbParser = new BBCode();
Expand Down Expand Up @@ -281,15 +281,15 @@ function handleUserError(string $message): never {
$container->go();
}

function create_link(Page|string $container, string $text, string $class = null): string {
function create_link(Page|string $container, string $text, ?string $class = null): string {
return '<a' . ($class === null ? '' : ' class="' . $class . '"') . ' href="' . (is_string($container) ? $container : $container->href()) . '">' . $text . '</a>';
}

function create_submit_link(Page $container, string $text): string {
return '<a href="' . $container->href() . '" class="submitStyle">' . $text . '</a>';
}

function get_colored_text_range(float $value, int $maxValue, string $text = null, int $minValue = 0): string {
function get_colored_text_range(float $value, int $maxValue, ?string $text = null, int $minValue = 0): string {
if ($text === null) {
$text = number_format($value);
}
Expand Down Expand Up @@ -317,7 +317,7 @@ function get_colored_text_range(float $value, int $maxValue, string $text = null
return '<span style="color:#' . $colour . '">' . $text . '</span>';
}

function get_colored_text(float $value, string $text = null): string {
function get_colored_text(float $value, ?string $text = null): string {
return get_colored_text_range($value, 300, $text, -300);
}

Expand Down
22 changes: 11 additions & 11 deletions src/lib/Smr/AbstractPlayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public static function getAlliancePlayers(int $gameID, int $allianceID, bool $fo
return self::$CACHE_ALLIANCE_PLAYERS[$gameID][$allianceID];
}

public static function getPlayer(int $accountID, int $gameID, bool $forceUpdate = false, DatabaseRecord $dbRecord = null): Player {
public static function getPlayer(int $accountID, int $gameID, bool $forceUpdate = false, ?DatabaseRecord $dbRecord = null): Player {
if ($forceUpdate || !isset(self::$CACHE_PLAYERS[$gameID][$accountID])) {
self::$CACHE_PLAYERS[$gameID][$accountID] = new Player($gameID, $accountID, $dbRecord);
}
Expand Down Expand Up @@ -281,7 +281,7 @@ public static function getPlayerByPlayerName(string $playerName, int $gameID, bo
protected function __construct(
protected readonly int $gameID,
protected readonly int $accountID,
DatabaseRecord $dbRecord = null,
?DatabaseRecord $dbRecord = null,
) {
$db = Database::getInstance();
$this->SQLID = [
Expand Down Expand Up @@ -834,7 +834,7 @@ public function sendGlobalMessage(string $message, bool $canBeIgnored = true): v
/**
* @return ($canBeIgnored is true ? int|false : int) Message ID
*/
public function sendMessage(int $receiverID, int $messageTypeID, string $message, bool $canBeIgnored = true, bool $unread = true, int $expires = null, bool $senderDelete = false): int|false {
public function sendMessage(int $receiverID, int $messageTypeID, string $message, bool $canBeIgnored = true, bool $unread = true, ?int $expires = null, bool $senderDelete = false): int|false {
//get expire time
if ($canBeIgnored) {
if ($this->getAccount()->isMailBanned()) {
Expand Down Expand Up @@ -878,7 +878,7 @@ public function sendMessage(int $receiverID, int $messageTypeID, string $message
return self::doMessageSending($this->getAccountID(), $receiverID, $this->getGameID(), $messageTypeID, $message, $expires, $senderDelete, $unread);
}

public function sendMessageFromOpAnnounce(int $receiverID, string $message, int $expires = null): void {
public function sendMessageFromOpAnnounce(int $receiverID, string $message, ?int $expires = null): void {
// get expire time if not set
if ($expires === null) {
$expires = Epoch::time() + 86400 * 14;
Expand Down Expand Up @@ -910,7 +910,7 @@ public static function sendMessageFromFedClerk(int $gameID, int $receiverID, str
self::doMessageSending(ACCOUNT_ID_FED_CLERK, $receiverID, $gameID, MSG_PLAYER, $message, $expires);
}

public static function sendMessageFromAdmin(int $gameID, int $receiverID, string $message, int $expires = null): void {
public static function sendMessageFromAdmin(int $gameID, int $receiverID, string $message, ?int $expires = null): void {
//get expire time
if ($expires === null) {
$expires = Epoch::time() + 86400 * 365;
Expand All @@ -919,7 +919,7 @@ public static function sendMessageFromAdmin(int $gameID, int $receiverID, string
self::doMessageSending(ACCOUNT_ID_ADMIN, $receiverID, $gameID, MSG_ADMIN, $message, $expires);
}

public static function sendMessageFromAllianceAmbassador(int $gameID, int $receiverID, string $message, int $expires = null): void {
public static function sendMessageFromAllianceAmbassador(int $gameID, int $receiverID, string $message, ?int $expires = null): void {
//get expire time
if ($expires === null) {
$expires = Epoch::time() + 86400 * 31;
Expand All @@ -928,7 +928,7 @@ public static function sendMessageFromAllianceAmbassador(int $gameID, int $recei
self::doMessageSending(ACCOUNT_ID_ALLIANCE_AMBASSADOR, $receiverID, $gameID, MSG_ALLIANCE, $message, $expires);
}

public function sendMessageFromCasino(string $message, int $expires = null): void {
public function sendMessageFromCasino(string $message, ?int $expires = null): void {
//get expire time
if ($expires === null) {
$expires = Epoch::time() + 86400 * 7;
Expand All @@ -937,7 +937,7 @@ public function sendMessageFromCasino(string $message, int $expires = null): voi
self::doMessageSending(ACCOUNT_ID_CASINO, $this->getAccountID(), $this->getGameID(), MSG_CASINO, $message, $expires);
}

public static function sendMessageFromRace(int $raceID, int $gameID, int $receiverID, string $message, int $expires = null): void {
public static function sendMessageFromRace(int $raceID, int $gameID, int $receiverID, string $message, ?int $expires = null): void {
//get expire time
if ($expires === null) {
$expires = Epoch::time() + 86400 * 5;
Expand Down Expand Up @@ -1433,7 +1433,7 @@ public function canChangeRace(): bool {
return !$this->isRaceChanged() && (Epoch::time() - $this->getGame()->getStartTime() < TIME_FOR_RACE_CHANGE);
}

public static function getColouredRaceNameOrDefault(int $otherRaceID, self $player = null, bool $linked = false): string {
public static function getColouredRaceNameOrDefault(int $otherRaceID, ?self $player = null, bool $linked = false): string {
$relations = 0;
if ($player !== null) {
$relations = $player->getRelation($otherRaceID);
Expand Down Expand Up @@ -1491,7 +1491,7 @@ public function getAllianceDisplayName(bool $linked = false, bool $includeAllian
return $this->getAlliance()->getAllianceDisplayName($linked, $includeAllianceID);
}

public function getAllianceRole(int $allianceID = null): int {
public function getAllianceRole(?int $allianceID = null): int {
if ($allianceID === null) {
$allianceID = $this->getAllianceID();
}
Expand All @@ -1512,7 +1512,7 @@ public function getAllianceRole(int $allianceID = null): int {
return $this->allianceRoles[$allianceID];
}

public function leaveAlliance(self $kickedBy = null): void {
public function leaveAlliance(?self $kickedBy = null): void {
$alliance = $this->getAlliance();
if ($kickedBy !== null) {
$kickedBy->sendMessage($this->getAccountID(), MSG_PLAYER, 'You were kicked out of the alliance!', false);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Smr/AbstractShip.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public function getRealSpeed(): float {
/**
* @return ($hardwareTypeID is null ? array<int, int> : int)
*/
public function getHardware(int $hardwareTypeID = null): array|int {
public function getHardware(?int $hardwareTypeID = null): array|int {
if ($hardwareTypeID === null) {
return $this->hardware;
}
Expand Down Expand Up @@ -646,14 +646,14 @@ public function setCargoHolds(int $amount): void {
/**
* @return ($goodID is null ? array<int, int> : int)
*/
public function getCargo(int $goodID = null): int|array {
public function getCargo(?int $goodID = null): int|array {
if ($goodID === null) {
return $this->cargo;
}
return $this->cargo[$goodID] ?? 0;
}

public function hasCargo(int $goodID = null): bool {
public function hasCargo(?int $goodID = null): bool {
if ($goodID === null) {
return $this->getUsedHolds() > 0;
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib/Smr/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public function getScore(): int {
/**
* @return array<array{Stat: array<string>, Score: float}>
*/
public function getIndividualScores(Player $player = null): array {
public function getIndividualScores(?Player $player = null): array {
$gameID = 0;
if ($player !== null) {
$gameID = $player->getGameID();
Expand Down Expand Up @@ -767,7 +767,7 @@ protected function setEmail(string $email): void {
/**
* Perform basic sanity checks on the usability of an email address.
*/
public static function checkEmail(string $email, self $owner = null): void {
public static function checkEmail(string $email, ?self $owner = null): void {
if ($email === '') {
throw new UserError('Email address is missing!');
}
Expand Down Expand Up @@ -1143,7 +1143,7 @@ public function setDefaultCSSEnabled(bool $bool): void {
/**
* @return ($hotkeyType is null ? array<string, array<string>> : array<string>)
*/
public function getHotkeys(string $hotkeyType = null): array {
public function getHotkeys(?string $hotkeyType = null): array {
if ($hotkeyType !== null) {
return $this->hotkeys[$hotkeyType] ?? [];
}
Expand Down Expand Up @@ -1245,7 +1245,7 @@ public function getPermissions(): array {
return $this->permissions;
}

public function hasPermission(int $permissionID = null): bool {
public function hasPermission(?int $permissionID = null): bool {
$permissions = $this->getPermissions();
if ($permissionID === null) {
return count($permissions) > 0;
Expand Down Expand Up @@ -1414,7 +1414,7 @@ public function banAccount(int $expireTime, self $admin, int $reasonID, string $
}
}

public function unbanAccount(self $admin = null, string $currException = null): void {
public function unbanAccount(?self $admin = null, ?string $currException = null): void {
$adminID = 0;
if ($admin !== null) {
$adminID = $admin->getAccountID();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Smr/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static function getByHofName(string $hofNamePattern, bool $approved = tru

public function __construct(
public int $accountID,
DatabaseRecord $dbRecord = null,
?DatabaseRecord $dbRecord = null,
) {
$db = Database::getInstance();
if ($dbRecord === null) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Smr/Alliance.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function clearCache(): void {
self::$CACHE_ALLIANCES = [];
}

public static function getAlliance(int $allianceID, int $gameID, bool $forceUpdate = false, DatabaseRecord $dbRecord = null): self {
public static function getAlliance(int $allianceID, int $gameID, bool $forceUpdate = false, ?DatabaseRecord $dbRecord = null): self {
if ($forceUpdate || !isset(self::$CACHE_ALLIANCES[$gameID][$allianceID])) {
self::$CACHE_ALLIANCES[$gameID][$allianceID] = new self($allianceID, $gameID, $dbRecord);
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public static function getAllianceByName(string $name, int $gameID, bool $forceU
protected function __construct(
protected readonly int $allianceID,
protected readonly int $gameID,
DatabaseRecord $dbRecord = null,
?DatabaseRecord $dbRecord = null,
) {
$db = Database::getInstance();
$this->SQLID = [
Expand Down Expand Up @@ -412,7 +412,7 @@ public function getDescription(): string {
return htmlentities($this->description);
}

public function setAllianceDescription(string $description, AbstractPlayer $player = null): void {
public function setAllianceDescription(string $description, ?AbstractPlayer $player = null): void {
$description = word_filter($description);
if ($description === $this->description) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Smr/Combat/Weapon/Weapon.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class Weapon extends AbstractWeapon {
protected bool $bonusDamage = false; // default
protected bool $damageRollover = false; // fixed for all Weapons

public static function getWeapon(int $weaponTypeID, DatabaseRecord $dbRecord = null): self {
public static function getWeapon(int $weaponTypeID, ?DatabaseRecord $dbRecord = null): self {
return new self($weaponTypeID, $dbRecord);
}

protected function __construct(
protected readonly int $weaponTypeID,
DatabaseRecord $dbRecord = null,
?DatabaseRecord $dbRecord = null,
) {
$this->weaponType = WeaponType::getWeaponType($weaponTypeID, $dbRecord);
$this->raceID = $this->weaponType->getRaceID();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Smr/Force.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static function getSectorForces(int $gameID, int $sectorID, bool $forceUp
return self::$CACHE_SECTOR_FORCES[$gameID][$sectorID];
}

public static function getForce(int $gameID, int $sectorID, int $ownerID, bool $forceUpdate = false, DatabaseRecord $dbRecord = null): self {
public static function getForce(int $gameID, int $sectorID, int $ownerID, bool $forceUpdate = false, ?DatabaseRecord $dbRecord = null): self {
if ($forceUpdate || !isset(self::$CACHE_FORCES[$gameID][$sectorID][$ownerID])) {
self::tidyUpForces(Galaxy::getGalaxyContaining($gameID, $sectorID));
$p = new self($gameID, $sectorID, $ownerID, $dbRecord);
Expand Down Expand Up @@ -145,7 +145,7 @@ protected function __construct(
protected readonly int $gameID,
protected readonly int $sectorID,
protected readonly int $ownerID,
DatabaseRecord $dbRecord = null,
?DatabaseRecord $dbRecord = null,
) {
$db = Database::getInstance();
$this->SQLID = [
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Smr/Galaxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function getGameGalaxies(int $gameID, bool $forceUpdate = false):
return self::$CACHE_GAME_GALAXIES[$gameID];
}

public static function getGalaxy(int $gameID, int $galaxyID, bool $forceUpdate = false, DatabaseRecord $dbRecord = null): self {
public static function getGalaxy(int $gameID, int $galaxyID, bool $forceUpdate = false, ?DatabaseRecord $dbRecord = null): self {
if ($forceUpdate || !isset(self::$CACHE_GALAXIES[$gameID][$galaxyID])) {
$g = new self($gameID, $galaxyID, false, $dbRecord);
self::$CACHE_GALAXIES[$gameID][$galaxyID] = $g;
Expand Down Expand Up @@ -83,7 +83,7 @@ protected function __construct(
protected readonly int $gameID,
protected readonly int $galaxyID,
bool $create = false,
DatabaseRecord $dbRecord = null,
?DatabaseRecord $dbRecord = null,
) {
$db = Database::getInstance();
$this->SQLID = [
Expand Down Expand Up @@ -270,7 +270,7 @@ public function getPlayers(): array {
*
* @return array<int, array<int, Sector>>
*/
public function getMapSectors(int $centerSectorID = null, int $dist = null): array {
public function getMapSectors(?int $centerSectorID = null, ?int $dist = null): array {
if ($centerSectorID === null) {
$topLeft = Sector::getSector($this->getGameID(), $this->getStartSector());
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Smr/Globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ public static function getSectorScanHREF(AbstractPlayer $player, int $toSector):
return self::$AVAILABLE_LINKS['Scan' . $player->getSector()->getSectorDirection($toSector)] = $container->href();
}

public static function getPlotCourseHREF(int $fromSector = null, int $toSector = null): string {
public static function getPlotCourseHREF(?int $fromSector = null, ?int $toSector = null): string {
if ($fromSector === null && $toSector === null) {
return self::$AVAILABLE_LINKS['PlotCourse'] = (new PlotCourse())->href();
}
return (new PlotCourseConventionalProcessor(from: $fromSector, to: $toSector))->href();
}

public static function getAllianceHREF(int $allianceID = null): string {
public static function getAllianceHREF(?int $allianceID = null): string {
if ($allianceID > 0) {
return self::getAllianceMotdHREF($allianceID);
}
Expand All @@ -225,7 +225,7 @@ public static function getAllianceBankHREF(int $allianceID): string {
return $container->href();
}

public static function getAllianceRosterHREF(int $allianceID = null): string {
public static function getAllianceRosterHREF(?int $allianceID = null): string {
return (new AllianceRoster($allianceID))->href();
}

Expand Down
12 changes: 6 additions & 6 deletions src/lib/Smr/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static function removeSectorLocations(int $gameID, int $sectorID): void {
self::$CACHE_SECTOR_LOCATIONS[$gameID][$sectorID] = [];
}

public static function getLocation(int $gameID, int $locationTypeID, bool $forceUpdate = false, DatabaseRecord $dbRecord = null): self {
public static function getLocation(int $gameID, int $locationTypeID, bool $forceUpdate = false, ?DatabaseRecord $dbRecord = null): self {
if ($forceUpdate || !isset(self::$CACHE_LOCATIONS[$locationTypeID])) {
self::$CACHE_LOCATIONS[$locationTypeID] = new self($gameID, $locationTypeID, $dbRecord);
}
Expand All @@ -162,7 +162,7 @@ public static function getLocation(int $gameID, int $locationTypeID, bool $force
protected function __construct(
protected readonly int $gameID, // use 0 to be independent of game
protected readonly int $typeID,
DatabaseRecord $dbRecord = null,
?DatabaseRecord $dbRecord = null,
) {
$db = Database::getInstance();
$this->SQLID = ['location_type_id' => $db->escapeNumber($typeID)];
Expand Down Expand Up @@ -358,7 +358,7 @@ public function getHardwareSold(): array {
return $this->hardwareSold;
}

public function isHardwareSold(int $hardwareTypeID = null): bool {
public function isHardwareSold(?int $hardwareTypeID = null): bool {
$hardware = $this->getHardwareSold();
if ($hardwareTypeID === null) {
return count($hardware) !== 0;
Expand Down Expand Up @@ -422,7 +422,7 @@ public function getShipsSold(): array {
return $this->shipsSold;
}

public function isShipSold(int $shipTypeID = null): bool {
public function isShipSold(?int $shipTypeID = null): bool {
$ships = $this->getShipsSold();
if ($shipTypeID === null) {
return count($ships) !== 0;
Expand Down Expand Up @@ -471,7 +471,7 @@ public function getWeaponsSold(): array {
return $this->weaponsSold;
}

public function isWeaponSold(int $weaponTypeID = null): bool {
public function isWeaponSold(?int $weaponTypeID = null): bool {
$weapons = $this->getWeaponsSold();
if ($weaponTypeID === null) {
return count($weapons) !== 0;
Expand Down Expand Up @@ -547,7 +547,7 @@ public function equals(Location $otherLocation): bool {
return $this->getTypeID() === $otherLocation->getTypeID();
}

public function hasX(mixed $x, AbstractPlayer $player = null): bool {
public function hasX(mixed $x, ?AbstractPlayer $player = null): bool {
if ($x instanceof WeaponType) {
return $this->isWeaponSold($x->getWeaponTypeID());
}
Expand Down
Loading

0 comments on commit bd7d8d0

Please sign in to comment.