mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
Add php-cs-fixer
This commit is contained in:
parent
e00e6ece5f
commit
309ae17036
54 changed files with 4900 additions and 4106 deletions
|
|
@ -4,215 +4,215 @@ use Demostf\API\Data\DemoPlayer;
|
|||
use Demostf\API\Data\User;
|
||||
|
||||
class Demo implements \JsonSerializable {
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var string */
|
||||
private $url;
|
||||
/** @var string */
|
||||
private $name;
|
||||
/** @var string */
|
||||
private $server;
|
||||
/** @var float */
|
||||
private $duration;
|
||||
/** @var string */
|
||||
private $nick;
|
||||
/** @var string */
|
||||
private $map;
|
||||
/** @var \DateTime */
|
||||
private $time;
|
||||
/** @var string */
|
||||
private $red;
|
||||
/** @var string */
|
||||
private $blue;
|
||||
/** @var int */
|
||||
private $redScore;
|
||||
/** @var int */
|
||||
private $blueScore;
|
||||
/** @var int */
|
||||
private $playerCount;
|
||||
/** @var int */
|
||||
private $uploader;
|
||||
/** @var User|null */
|
||||
private $uploaderUser;
|
||||
/** @var DemoPlayer[] */
|
||||
private $players;
|
||||
/** @var string */
|
||||
private $hash;
|
||||
/** @var string */
|
||||
private $backend;
|
||||
/** @var string */
|
||||
private $path;
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var string */
|
||||
private $url;
|
||||
/** @var string */
|
||||
private $name;
|
||||
/** @var string */
|
||||
private $server;
|
||||
/** @var float */
|
||||
private $duration;
|
||||
/** @var string */
|
||||
private $nick;
|
||||
/** @var string */
|
||||
private $map;
|
||||
/** @var \DateTime */
|
||||
private $time;
|
||||
/** @var string */
|
||||
private $red;
|
||||
/** @var string */
|
||||
private $blue;
|
||||
/** @var int */
|
||||
private $redScore;
|
||||
/** @var int */
|
||||
private $blueScore;
|
||||
/** @var int */
|
||||
private $playerCount;
|
||||
/** @var int */
|
||||
private $uploader;
|
||||
/** @var User|null */
|
||||
private $uploaderUser;
|
||||
/** @var DemoPlayer[] */
|
||||
private $players;
|
||||
/** @var string */
|
||||
private $hash;
|
||||
/** @var string */
|
||||
private $backend;
|
||||
/** @var string */
|
||||
private $path;
|
||||
|
||||
public function __construct(
|
||||
int $id,
|
||||
string $url,
|
||||
string $name,
|
||||
string $server,
|
||||
float $duration,
|
||||
string $nick,
|
||||
string $map,
|
||||
\DateTime $time,
|
||||
string $red,
|
||||
string $blue,
|
||||
int $redScore,
|
||||
int $blueScore,
|
||||
int $playerCount,
|
||||
int $uploader,
|
||||
string $hash,
|
||||
string $backend,
|
||||
string $path
|
||||
) {
|
||||
$this->id = $id;
|
||||
$this->url = $url;
|
||||
$this->name = $name;
|
||||
$this->server = $server;
|
||||
$this->duration = $duration;
|
||||
$this->nick = $nick;
|
||||
$this->map = $map;
|
||||
$this->time = $time;
|
||||
$this->red = $red;
|
||||
$this->blue = $blue;
|
||||
$this->redScore = $redScore;
|
||||
$this->blueScore = $blueScore;
|
||||
$this->playerCount = $playerCount;
|
||||
$this->uploader = $uploader;
|
||||
$this->hash = $hash;
|
||||
$this->backend = $backend;
|
||||
$this->path = $path;
|
||||
}
|
||||
public function __construct(
|
||||
int $id,
|
||||
string $url,
|
||||
string $name,
|
||||
string $server,
|
||||
float $duration,
|
||||
string $nick,
|
||||
string $map,
|
||||
\DateTime $time,
|
||||
string $red,
|
||||
string $blue,
|
||||
int $redScore,
|
||||
int $blueScore,
|
||||
int $playerCount,
|
||||
int $uploader,
|
||||
string $hash,
|
||||
string $backend,
|
||||
string $path
|
||||
) {
|
||||
$this->id = $id;
|
||||
$this->url = $url;
|
||||
$this->name = $name;
|
||||
$this->server = $server;
|
||||
$this->duration = $duration;
|
||||
$this->nick = $nick;
|
||||
$this->map = $map;
|
||||
$this->time = $time;
|
||||
$this->red = $red;
|
||||
$this->blue = $blue;
|
||||
$this->redScore = $redScore;
|
||||
$this->blueScore = $blueScore;
|
||||
$this->playerCount = $playerCount;
|
||||
$this->uploader = $uploader;
|
||||
$this->hash = $hash;
|
||||
$this->backend = $backend;
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
public function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
public function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getUrl(): string {
|
||||
return $this->url;
|
||||
}
|
||||
public function getUrl(): string {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return $this->name;
|
||||
}
|
||||
public function getName(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getServer(): string {
|
||||
return $this->server;
|
||||
}
|
||||
public function getServer(): string {
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
public function getDuration(): float {
|
||||
return $this->duration;
|
||||
}
|
||||
public function getDuration(): float {
|
||||
return $this->duration;
|
||||
}
|
||||
|
||||
public function getNick(): string {
|
||||
return $this->nick;
|
||||
}
|
||||
public function getNick(): string {
|
||||
return $this->nick;
|
||||
}
|
||||
|
||||
public function getMap(): string {
|
||||
return $this->map;
|
||||
}
|
||||
public function getMap(): string {
|
||||
return $this->map;
|
||||
}
|
||||
|
||||
public function getTime(): \DateTime {
|
||||
return $this->time;
|
||||
}
|
||||
public function getTime(): \DateTime {
|
||||
return $this->time;
|
||||
}
|
||||
|
||||
public function getRed(): string {
|
||||
return $this->red;
|
||||
}
|
||||
public function getRed(): string {
|
||||
return $this->red;
|
||||
}
|
||||
|
||||
public function getBlue(): string {
|
||||
return $this->blue;
|
||||
}
|
||||
public function getBlue(): string {
|
||||
return $this->blue;
|
||||
}
|
||||
|
||||
public function getRedScore(): int {
|
||||
return $this->redScore;
|
||||
}
|
||||
public function getRedScore(): int {
|
||||
return $this->redScore;
|
||||
}
|
||||
|
||||
public function getBlueScore(): int {
|
||||
return $this->blueScore;
|
||||
}
|
||||
public function getBlueScore(): int {
|
||||
return $this->blueScore;
|
||||
}
|
||||
|
||||
public function getPlayerCount(): int {
|
||||
return $this->playerCount;
|
||||
}
|
||||
public function getPlayerCount(): int {
|
||||
return $this->playerCount;
|
||||
}
|
||||
|
||||
public function getUploader(): int {
|
||||
return $this->uploader;
|
||||
}
|
||||
public function getUploader(): int {
|
||||
return $this->uploader;
|
||||
}
|
||||
|
||||
public function getUploaderUser(): ?User {
|
||||
return $this->uploaderUser;
|
||||
}
|
||||
public function getUploaderUser(): ?User {
|
||||
return $this->uploaderUser;
|
||||
}
|
||||
|
||||
public function setUploaderUser(User $uploaderUser) {
|
||||
$this->uploaderUser = $uploaderUser;
|
||||
}
|
||||
public function setUploaderUser(User $uploaderUser) {
|
||||
$this->uploaderUser = $uploaderUser;
|
||||
}
|
||||
|
||||
public static function fromRow($row): Demo {
|
||||
return new Demo(
|
||||
(int)$row['id'],
|
||||
$row['url'],
|
||||
$row['name'],
|
||||
$row['server'],
|
||||
(int)$row['duration'],
|
||||
$row['nick'],
|
||||
$row['map'],
|
||||
\DateTime::createFromFormat('U', '' . strtotime($row['created_at'])),
|
||||
$row['red'],
|
||||
$row['blu'],
|
||||
(int)$row['scoreRed'],
|
||||
(int)$row['scoreBlue'],
|
||||
(int)$row['playerCount'],
|
||||
(int)$row['uploader'],
|
||||
$row['hash'],
|
||||
$row['backend'],
|
||||
$row['path']
|
||||
);
|
||||
}
|
||||
public static function fromRow($row): Demo {
|
||||
return new Demo(
|
||||
(int)$row['id'],
|
||||
$row['url'],
|
||||
$row['name'],
|
||||
$row['server'],
|
||||
(int)$row['duration'],
|
||||
$row['nick'],
|
||||
$row['map'],
|
||||
\DateTime::createFromFormat('U', '' . strtotime($row['created_at'])),
|
||||
$row['red'],
|
||||
$row['blu'],
|
||||
(int)$row['scoreRed'],
|
||||
(int)$row['scoreBlue'],
|
||||
(int)$row['playerCount'],
|
||||
(int)$row['uploader'],
|
||||
$row['hash'],
|
||||
$row['backend'],
|
||||
$row['path']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DemoPlayer[]
|
||||
*/
|
||||
public function getPlayers(): array {
|
||||
return $this->players;
|
||||
}
|
||||
/**
|
||||
* @return DemoPlayer[]
|
||||
*/
|
||||
public function getPlayers(): array {
|
||||
return $this->players;
|
||||
}
|
||||
|
||||
public function setPlayers(array $players) {
|
||||
$this->players = $players;
|
||||
}
|
||||
public function setPlayers(array $players) {
|
||||
$this->players = $players;
|
||||
}
|
||||
|
||||
public function getHash(): string {
|
||||
return $this->hash;
|
||||
}
|
||||
public function getHash(): string {
|
||||
return $this->hash;
|
||||
}
|
||||
|
||||
public function getBackend(): string {
|
||||
return $this->backend;
|
||||
}
|
||||
public function getBackend(): string {
|
||||
return $this->backend;
|
||||
}
|
||||
|
||||
public function getPath(): string {
|
||||
return $this->path;
|
||||
}
|
||||
public function getPath(): string {
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
$data = [
|
||||
'id' => $this->getId(),
|
||||
'url' => $this->getUrl(),
|
||||
'name' => $this->getName(),
|
||||
'server' => $this->getServer(),
|
||||
'duration' => $this->getDuration(),
|
||||
'nick' => $this->getNick(),
|
||||
'map' => $this->getMap(),
|
||||
'time' => $this->getTime()->getTimestamp(),
|
||||
'red' => $this->getRed(),
|
||||
'blue' => $this->getBlue(),
|
||||
'redScore' => $this->getRedScore(),
|
||||
'blueScore' => $this->getBlueScore(),
|
||||
'playerCount' => $this->getPlayerCount(),
|
||||
'uploader' => $this->uploaderUser ? $this->getUploaderUser()->jsonSerialize() : $this->getUploader(),
|
||||
'hash' => $this->getHash(),
|
||||
'backend' => $this->getBackend(),
|
||||
'path' => $this->getPath()
|
||||
];
|
||||
if ($this->players) {
|
||||
$data['players'] = $this->getPlayers();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
public function jsonSerialize() {
|
||||
$data = [
|
||||
'id' => $this->getId(),
|
||||
'url' => $this->getUrl(),
|
||||
'name' => $this->getName(),
|
||||
'server' => $this->getServer(),
|
||||
'duration' => $this->getDuration(),
|
||||
'nick' => $this->getNick(),
|
||||
'map' => $this->getMap(),
|
||||
'time' => $this->getTime()->getTimestamp(),
|
||||
'red' => $this->getRed(),
|
||||
'blue' => $this->getBlue(),
|
||||
'redScore' => $this->getRedScore(),
|
||||
'blueScore' => $this->getBlueScore(),
|
||||
'playerCount' => $this->getPlayerCount(),
|
||||
'uploader' => $this->uploaderUser ? $this->getUploaderUser()->jsonSerialize() : $this->getUploader(),
|
||||
'hash' => $this->getHash(),
|
||||
'backend' => $this->getBackend(),
|
||||
'path' => $this->getPath()
|
||||
];
|
||||
if ($this->players) {
|
||||
$data['players'] = $this->getPlayers();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue