Skip to content

Commit

Permalink
Improve TraderCombatResult type
Browse files Browse the repository at this point in the history
Always initialize the `TotalDamagePerTargetPlayer` field of the
`TraderCombatResult` array type. This fixes a PHPStan warning.
  • Loading branch information
hemberger committed Sep 9, 2023
1 parent 6e1fe8c commit 0d7e33e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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 isUnderground(): bool {
*/
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

0 comments on commit 0d7e33e

Please sign in to comment.