Add GetGameHighScores method
This commit is contained in:
parent
ecac3c6ae5
commit
d19c74e35a
3 changed files with 124 additions and 0 deletions
79
src/TgBotLib/Objects/GameHighScore.php
Normal file
79
src/TgBotLib/Objects/GameHighScore.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Objects;
|
||||
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
|
||||
class GameHighScore implements ObjectTypeInterface
|
||||
{
|
||||
private int $position;
|
||||
private User $user;
|
||||
private int $score;
|
||||
|
||||
/**
|
||||
* This object represents one row of the high scores table for a game.
|
||||
*
|
||||
* @param array|null $data
|
||||
*/
|
||||
public function __construct(?array $data=null)
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->position = $data['position'];
|
||||
$this->user = User::fromArray($data['user']);
|
||||
$this->score = $data['score'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Position in high score table for the game
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPosition(): int
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* User
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Score
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getScore(): int
|
||||
{
|
||||
return $this->score;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toArray(): ?array
|
||||
{
|
||||
return [
|
||||
'position' => $this->position,
|
||||
'user' => $this->user->toArray(),
|
||||
'score' => $this->score
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(?array $data): ?GameHighScore
|
||||
{
|
||||
return new self($data);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue