Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix implicitly nullable function arguments #1973

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
/**
* @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 {

Check warning on line 837 in src/lib/Smr/AbstractPlayer.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/AbstractPlayer.php#L837

Added line #L837 was not covered by tests
//get expire time
if ($canBeIgnored) {
if ($this->getAccount()->isMailBanned()) {
Expand Down Expand Up @@ -878,7 +878,7 @@
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 {

Check warning on line 881 in src/lib/Smr/AbstractPlayer.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/AbstractPlayer.php#L881

Added line #L881 was not covered by tests
// get expire time if not set
if ($expires === null) {
$expires = Epoch::time() + 86400 * 14;
Expand Down Expand Up @@ -910,7 +910,7 @@
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 {

Check warning on line 913 in src/lib/Smr/AbstractPlayer.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/AbstractPlayer.php#L913

Added line #L913 was not covered by tests
//get expire time
if ($expires === null) {
$expires = Epoch::time() + 86400 * 365;
Expand All @@ -919,7 +919,7 @@
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 {

Check warning on line 922 in src/lib/Smr/AbstractPlayer.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/AbstractPlayer.php#L922

Added line #L922 was not covered by tests
//get expire time
if ($expires === null) {
$expires = Epoch::time() + 86400 * 31;
Expand All @@ -928,7 +928,7 @@
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 {

Check warning on line 931 in src/lib/Smr/AbstractPlayer.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/AbstractPlayer.php#L931

Added line #L931 was not covered by tests
//get expire time
if ($expires === null) {
$expires = Epoch::time() + 86400 * 7;
Expand All @@ -937,7 +937,7 @@
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 {

Check warning on line 940 in src/lib/Smr/AbstractPlayer.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/AbstractPlayer.php#L940

Added line #L940 was not covered by tests
//get expire time
if ($expires === null) {
$expires = Epoch::time() + 86400 * 5;
Expand Down Expand Up @@ -1433,7 +1433,7 @@
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 {

Check warning on line 1436 in src/lib/Smr/AbstractPlayer.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/AbstractPlayer.php#L1436

Added line #L1436 was not covered by tests
$relations = 0;
if ($player !== null) {
$relations = $player->getRelation($otherRaceID);
Expand Down Expand Up @@ -1491,7 +1491,7 @@
return $this->getAlliance()->getAllianceDisplayName($linked, $includeAllianceID);
}

public function getAllianceRole(int $allianceID = null): int {
public function getAllianceRole(?int $allianceID = null): int {

Check warning on line 1494 in src/lib/Smr/AbstractPlayer.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/AbstractPlayer.php#L1494

Added line #L1494 was not covered by tests
if ($allianceID === null) {
$allianceID = $this->getAllianceID();
}
Expand All @@ -1512,7 +1512,7 @@
return $this->allianceRoles[$allianceID];
}

public function leaveAlliance(self $kickedBy = null): void {
public function leaveAlliance(?self $kickedBy = null): void {

Check warning on line 1515 in src/lib/Smr/AbstractPlayer.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/AbstractPlayer.php#L1515

Added line #L1515 was not covered by tests
$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 @@
/**
* @return array<array{Stat: array<string>, Score: float}>
*/
public function getIndividualScores(Player $player = null): array {
public function getIndividualScores(?Player $player = null): array {

Check warning on line 512 in src/lib/Smr/Account.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Account.php#L512

Added line #L512 was not covered by tests
$gameID = 0;
if ($player !== null) {
$gameID = $player->getGameID();
Expand Down Expand Up @@ -767,7 +767,7 @@
/**
* 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 {

Check warning on line 770 in src/lib/Smr/Account.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Account.php#L770

Added line #L770 was not covered by tests
if ($email === '') {
throw new UserError('Email address is missing!');
}
Expand Down Expand Up @@ -1143,7 +1143,7 @@
/**
* @return ($hotkeyType is null ? array<string, array<string>> : array<string>)
*/
public function getHotkeys(string $hotkeyType = null): array {
public function getHotkeys(?string $hotkeyType = null): array {

Check warning on line 1146 in src/lib/Smr/Account.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Account.php#L1146

Added line #L1146 was not covered by tests
if ($hotkeyType !== null) {
return $this->hotkeys[$hotkeyType] ?? [];
}
Expand Down Expand Up @@ -1245,7 +1245,7 @@
return $this->permissions;
}

public function hasPermission(int $permissionID = null): bool {
public function hasPermission(?int $permissionID = null): bool {

Check warning on line 1248 in src/lib/Smr/Account.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Account.php#L1248

Added line #L1248 was not covered by tests
$permissions = $this->getPermissions();
if ($permissionID === null) {
return count($permissions) > 0;
Expand Down Expand Up @@ -1414,7 +1414,7 @@
}
}

public function unbanAccount(self $admin = null, string $currException = null): void {
public function unbanAccount(?self $admin = null, ?string $currException = null): void {

Check warning on line 1417 in src/lib/Smr/Account.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Account.php#L1417

Added line #L1417 was not covered by tests
$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 @@
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 @@
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 @@
return htmlentities($this->description);
}

public function setAllianceDescription(string $description, AbstractPlayer $player = null): void {
public function setAllianceDescription(string $description, ?AbstractPlayer $player = null): void {

Check warning on line 415 in src/lib/Smr/Alliance.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Alliance.php#L415

Added line #L415 was not covered by tests
$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 @@
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 {

Check warning on line 35 in src/lib/Smr/Combat/Weapon/Weapon.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Combat/Weapon/Weapon.php#L35

Added line #L35 was not covered by tests
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 @@
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 {

Check warning on line 107 in src/lib/Smr/Force.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Force.php#L107

Added line #L107 was not covered by tests
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 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 @@
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 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 @@
*
* @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 {

Check warning on line 273 in src/lib/Smr/Galaxy.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Galaxy.php#L273

Added line #L273 was not covered by tests
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 @@
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 {

Check warning on line 209 in src/lib/Smr/Globals.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Globals.php#L209

Added line #L209 was not covered by tests
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 {

Check warning on line 216 in src/lib/Smr/Globals.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Globals.php#L216

Added line #L216 was not covered by tests
if ($allianceID > 0) {
return self::getAllianceMotdHREF($allianceID);
}
Expand All @@ -225,7 +225,7 @@
return $container->href();
}

public static function getAllianceRosterHREF(int $allianceID = null): string {
public static function getAllianceRosterHREF(?int $allianceID = null): string {

Check warning on line 228 in src/lib/Smr/Globals.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Globals.php#L228

Added line #L228 was not covered by tests
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 @@
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 @@
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 @@
return $this->hardwareSold;
}

public function isHardwareSold(int $hardwareTypeID = null): bool {
public function isHardwareSold(?int $hardwareTypeID = null): bool {

Check warning on line 361 in src/lib/Smr/Location.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Location.php#L361

Added line #L361 was not covered by tests
$hardware = $this->getHardwareSold();
if ($hardwareTypeID === null) {
return count($hardware) !== 0;
Expand Down Expand Up @@ -422,7 +422,7 @@
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 @@
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 @@
return $this->getTypeID() === $otherLocation->getTypeID();
}

public function hasX(mixed $x, AbstractPlayer $player = null): bool {
public function hasX(mixed $x, ?AbstractPlayer $player = null): bool {

Check warning on line 550 in src/lib/Smr/Location.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/Location.php#L550

Added line #L550 was not covered by tests
if ($x instanceof WeaponType) {
return $this->isWeaponSold($x->getWeaponTypeID());
}
Expand Down
Loading
Loading