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

build(deps-dev): update phpstan/phpstan requirement from 1.10.18 to 1.10.33 #1679

Merged
merged 3 commits into from
Sep 9, 2023
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"require-dev": {
"fig-r/psr2r-sniffer": "1.4.0",
"overtrue/phplint": "9.0.4",
"phpstan/phpstan": "1.10.18",
"phpstan/phpstan": "1.10.33",
"phpunit/phpunit": "10.3.3",
"phpunit/php-code-coverage": "10.1.1",
"rector/rector": "0.15.13",
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parameters:
ForceAttackerCombatResult: 'array{Player: \Smr\AbstractPlayer, TotalDamage: int, DeadBeforeShot: bool, Weapons: array<int, array{Weapon: \Smr\Combat\Weapon\AbstractWeapon, Target: \Smr\Force, Hit: bool, WeaponDamage?: WeaponDamageData, ActualDamage?: ForceTakenDamageData, KillResults?: array{}}>, Drones?: array{Weapon: \Smr\Combat\Weapon\AbstractWeapon, Target: \Smr\Force, Hit: bool, WeaponDamage: WeaponDamageData, ActualDamage: ForceTakenDamageData, KillResults?: array{}}}'
ForceAttackerCombatResults: 'array{TotalDamage: int, Traders: array<int, ForceAttackerCombatResult>}'
ForceCombatResults: 'array{TotalDamage: int, DeadBeforeShot: bool, ForcesDestroyed?: bool, Results: array{Mines?: array{Weapon: \Smr\Combat\Weapon\AbstractWeapon, Target: \Smr\AbstractPlayer, Hit: bool, WeaponDamage: WeaponDamageData, ActualDamage: TakenDamageData, KillResults?: array{DeadExp: int, LostCredits: int}}, Drones?: array{Weapon: \Smr\Combat\Weapon\AbstractWeapon, Target: \Smr\AbstractPlayer, Hit: bool, WeaponDamage: WeaponDamageData, ActualDamage: TakenDamageData, KillResults?: array{DeadExp: int, LostCredits: int}}, Scouts?: array{Weapon: \Smr\Combat\Weapon\AbstractWeapon, Target: \Smr\AbstractPlayer, Hit: bool, WeaponDamage: WeaponDamageData, ActualDamage: TakenDamageData, KillResults?: array{DeadExp: int, LostCredits: int}}}}'
TraderCombatResult: 'array{Player: \Smr\AbstractPlayer, TotalDamage: int, TotalDamagePerTargetPlayer?: array<int, int>, DeadBeforeShot: bool, Weapons: array<int, array{Weapon: \Smr\Combat\Weapon\AbstractWeapon, Target: \Smr\AbstractPlayer, Hit: bool, WeaponDamage?: WeaponDamageData, ActualDamage?: TakenDamageData, KillResults?: array{DeadExp: int, KillerExp: int, KillerCredits: int}}>, Drones?: array{Weapon: \Smr\Combat\Weapon\AbstractWeapon, Target: \Smr\AbstractPlayer, Hit: bool, WeaponDamage: WeaponDamageData, ActualDamage: TakenDamageData, KillResults?: array{DeadExp: int, KillerExp: int, KillerCredits: int}}}'
TraderCombatResult: 'array{Player: \Smr\AbstractPlayer, TotalDamage: int, TotalDamagePerTargetPlayer: array<int, int>, DeadBeforeShot: bool, Weapons: array<int, array{Weapon: \Smr\Combat\Weapon\AbstractWeapon, Target: \Smr\AbstractPlayer, Hit: bool, WeaponDamage?: WeaponDamageData, ActualDamage?: TakenDamageData, KillResults?: array{DeadExp: int, KillerExp: int, KillerCredits: int}}>, Drones?: array{Weapon: \Smr\Combat\Weapon\AbstractWeapon, Target: \Smr\AbstractPlayer, Hit: bool, WeaponDamage: WeaponDamageData, ActualDamage: TakenDamageData, KillResults?: array{DeadExp: int, KillerExp: int, KillerCredits: int}}}'
TraderTeamCombatResults: 'array{TotalDamage: int, Traders: array<int, TraderCombatResult>}'

#----------------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion src/lib/Smr/AbstractShip.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,12 @@
*/
public function shootPlayers(array $targetPlayers): array {
$thisPlayer = $this->getPlayer();
$results = ['Player' => $thisPlayer, 'TotalDamage' => 0, 'Weapons' => []];
$results = [
'Player' => $thisPlayer,
'TotalDamage' => 0,
'TotalDamagePerTargetPlayer' => [],
'Weapons' => [],
];

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

View check run for this annotation

Codecov / codecov/patch

src/lib/Smr/AbstractShip.php#L765-L770

Added lines #L765 - L770 were not covered by tests
foreach ($targetPlayers as $targetPlayer) {
$results['TotalDamagePerTargetPlayer'][$targetPlayer->getAccountID()] = 0;
}
Expand Down
61 changes: 26 additions & 35 deletions src/lib/Smr/Alliance.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,37 +94,35 @@ protected function __construct(
protected readonly int $gameID,
DatabaseRecord $dbRecord = null,
) {
if ($allianceID !== 0) {
$db = Database::getInstance();
$this->SQLID = [
'alliance_id' => $db->escapeNumber($allianceID),
'game_id' => $db->escapeNumber($gameID),
];
$db = Database::getInstance();
$this->SQLID = [
'alliance_id' => $db->escapeNumber($allianceID),
'game_id' => $db->escapeNumber($gameID),
];

if ($dbRecord === null) {
$dbResult = $db->read('SELECT * FROM alliance WHERE ' . self::SQL, $this->SQLID);
if ($dbResult->hasRecord()) {
$dbRecord = $dbResult->record();
}
}
if ($dbRecord === null) {
throw new AllianceNotFound('Invalid allianceID: ' . $allianceID . ' OR gameID: ' . $gameID);
if ($dbRecord === null) {
$dbResult = $db->read('SELECT * FROM alliance WHERE ' . self::SQL, $this->SQLID);
if ($dbResult->hasRecord()) {
$dbRecord = $dbResult->record();
}

$this->allianceName = $dbRecord->getString('alliance_name');
$this->password = $dbRecord->getString('alliance_password');
$this->recruiting = $dbRecord->getBoolean('recruiting');
$this->description = $dbRecord->getNullableString('alliance_description');
$this->leaderID = $dbRecord->getInt('leader_id');
$this->bank = $dbRecord->getInt('alliance_account');
$this->kills = $dbRecord->getInt('alliance_kills');
$this->deaths = $dbRecord->getInt('alliance_deaths');
$this->motd = $dbRecord->getString('mod');
$this->imgSrc = $dbRecord->getString('img_src');
$this->discordServer = $dbRecord->getNullableString('discord_server');
$this->discordChannel = $dbRecord->getNullableString('discord_channel');
$this->flagshipID = $dbRecord->getInt('flagship_id');
}
if ($dbRecord === null) {
throw new AllianceNotFound('Invalid allianceID: ' . $allianceID . ' OR gameID: ' . $gameID);
}

$this->allianceName = $dbRecord->getString('alliance_name');
$this->password = $dbRecord->getString('alliance_password');
$this->recruiting = $dbRecord->getBoolean('recruiting');
$this->description = $dbRecord->getNullableString('alliance_description');
$this->leaderID = $dbRecord->getInt('leader_id');
$this->bank = $dbRecord->getInt('alliance_account');
$this->kills = $dbRecord->getInt('alliance_kills');
$this->deaths = $dbRecord->getInt('alliance_deaths');
$this->motd = $dbRecord->getString('mod');
$this->imgSrc = $dbRecord->getString('img_src');
$this->discordServer = $dbRecord->getNullableString('discord_server');
$this->discordChannel = $dbRecord->getNullableString('discord_channel');
$this->flagshipID = $dbRecord->getInt('flagship_id');
}

/**
Expand Down Expand Up @@ -169,13 +167,6 @@ public static function createAlliance(int $gameID, string $name, bool $allowNHA
return self::getAlliance($allianceID, $gameID);
}

/**
* Returns true if the alliance ID is associated with allianceless players.
*/
public function isNone(): bool {
return $this->allianceID === 0;
}

/**
* Returns true if the alliance is the Newbie Help Alliance.
*/
Expand Down
33 changes: 21 additions & 12 deletions src/pages/Player/Rankings/AllianceVsAlliance.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,39 @@ public function build(AbstractPlayer $player, Template $template): void {

$alliance_vs = [];
foreach ($alliance_vs_ids as $curr_id) {
$curr_alliance = Alliance::getAlliance($curr_id, $player->getGameID());
$container = new self($curr_id, $this->versusAllianceIDs);
$style = '';
if (!$curr_alliance->isNone() && $curr_alliance->hasDisbanded()) {
$style = 'class="red"';
}
if ($player->getAllianceID() === $curr_id) {
$style = 'class="bold"';
}
if ($curr_id === 0) {
$alliance_name = 'No Alliance';
} else {
$curr_alliance = Alliance::getAlliance($curr_id, $player->getGameID());
if ($curr_alliance->hasDisbanded()) {
$style = 'class="red"';
}
$alliance_name = $curr_alliance->getAllianceDisplayName();
}
$alliance_vs[] = [
'ID' => $curr_id,
'DetailsHREF' => $container->href(),
'Name' => $curr_alliance->isNone() ? 'No Alliance' : $curr_alliance->getAllianceDisplayName(),
'Name' => $alliance_name,
'Style' => $style,
];
}
$template->assign('AllianceVs', $alliance_vs);

$alliance_vs_table = [];
foreach ($alliance_vs_ids as $curr_id) {
$curr_alliance = Alliance::getAlliance($curr_id, $player->getGameID());
foreach ($alliance_vs_ids as $id) {
$row_alliance = Alliance::getAlliance($id, $player->getGameID());
$showRed = (!$curr_alliance->isNone() && $curr_alliance->hasDisbanded()) ||
(!$row_alliance->isNone() && $row_alliance->hasDisbanded());
$showRed = (
($curr_id !== 0 && Alliance::getAlliance($curr_id, $player->getGameID())->hasDisbanded()) ||
($id !== 0 && Alliance::getAlliance($id, $player->getGameID())->hasDisbanded())
);
$showBold = $curr_id === $player->getAllianceID() || $id === $player->getAllianceID();
$style = '';
if ($curr_id === $id && !$row_alliance->isNone()) {
if ($curr_id === $id && $id !== 0) {
$value = '--';
if ($showRed) {
$style = 'class="red"';
Expand Down Expand Up @@ -120,8 +125,12 @@ public function build(AbstractPlayer $player, Template $template): void {
$template->assign('AllianceVsTable', $alliance_vs_table);

// Show details for a specific alliance
$main_alliance = Alliance::getAlliance($this->detailsAllianceID, $player->getGameID());
$mainName = $main_alliance->isNone() ? 'No Alliance' : $main_alliance->getAllianceDisplayName();
if ($this->detailsAllianceID === 0) {
$mainName = 'No alliance';
} else {
$main_alliance = Alliance::getAlliance($this->detailsAllianceID, $player->getGameID());
$mainName = $main_alliance->getAllianceDisplayName();
}
$template->assign('DetailsName', $mainName);

$kills = [];
Expand Down
10 changes: 0 additions & 10 deletions test/SmrTest/lib/AllianceIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,4 @@ public function test_isNHA(): void {
self::assertTrue($alliance->isNHA());
}

public function test_isNone(): void {
// Create an alliance that is not "none"
$alliance = Alliance::createAlliance(1, 'Some alliance');
self::assertFalse($alliance->isNone());

// Create an alliance that is "none"
$alliance = Alliance::getAlliance(0, 1);
self::assertTrue($alliance->isNone());
}

}