1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-03 18:04:08 +02:00

always set players

This commit is contained in:
Robin Appelman 2021-11-14 22:16:10 +01:00
commit 9c61c483fb
2 changed files with 6 additions and 5 deletions

View file

@ -26,7 +26,7 @@ class Demo implements JsonSerializable {
private int $uploader; private int $uploader;
private ?User $uploaderUser; private ?User $uploaderUser;
/** @var DemoPlayer[] */ /** @var DemoPlayer[] */
private array $players; private ?array $players;
private string $hash; private string $hash;
private string $backend; private string $backend;
private string $path; private string $path;
@ -67,7 +67,7 @@ class Demo implements JsonSerializable {
$this->hash = $hash; $this->hash = $hash;
$this->backend = $backend; $this->backend = $backend;
$this->path = $path; $this->path = $path;
$this->players = []; $this->players = null;
$this->uploaderUser = null; $this->uploaderUser = null;
} }
@ -163,9 +163,9 @@ class Demo implements JsonSerializable {
} }
/** /**
* @return DemoPlayer[] * @return DemoPlayer[]|null
*/ */
public function getPlayers(): array { public function getPlayers(): ?array {
return $this->players; return $this->players;
} }
@ -208,7 +208,7 @@ class Demo implements JsonSerializable {
'backend' => $this->getBackend(), 'backend' => $this->getBackend(),
'path' => $this->getPath(), 'path' => $this->getPath(),
]; ];
if ($this->players) { if (is_array($this->players)) {
$data['players'] = $this->getPlayers(); $data['players'] = $this->getPlayers();
} }

View file

@ -68,6 +68,7 @@ class DemoProviderTest extends TestCase {
$storedData = $demo->jsonSerialize(); $storedData = $demo->jsonSerialize();
$storedData['id'] = $id; $storedData['id'] = $id;
$storedData['players'] = [];
$this->assertEquals($storedData, $retrieved->jsonSerialize()); $this->assertEquals($storedData, $retrieved->jsonSerialize());