1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-03 09:54:17 +02:00

more type hints

This commit is contained in:
Robin Appelman 2022-01-23 16:04:09 +01:00
commit 4f617d12d4
11 changed files with 700 additions and 546 deletions

View file

@ -27,5 +27,10 @@
"phpunit/phpunit": "^9", "phpunit/phpunit": "^9",
"friendsofphp/php-cs-fixer": "^2.16", "friendsofphp/php-cs-fixer": "^2.16",
"phpstan/phpstan": "^0.12.57" "phpstan/phpstan": "^0.12.57"
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true
}
} }
} }

1118
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -84,7 +84,11 @@ class DemoPlayer implements JsonSerializable {
); );
} }
public function jsonSerialize() { /**
* @return array{'id': int, 'user_id': int, 'name': string, 'team': string, 'class': string, 'steamid': string, 'kills': int, 'assists': int, 'deaths': int}
*/
#[\ReturnTypeWillChange]
public function jsonSerialize():array {
return [ return [
'id' => $this->getId(), 'id' => $this->getId(),
'user_id' => $this->getUserId(), 'user_id' => $this->getUserId(),

View file

@ -7,12 +7,9 @@ namespace Demostf\API\Data;
use JsonSerializable; use JsonSerializable;
class SteamUser implements JsonSerializable { class SteamUser implements JsonSerializable {
/** @var int */ private int $id;
private $id; private string $steamId;
/** @var string */ private string $name;
private $steamId;
/** @var string */
private $name;
public function __construct(int $id, string $steamId, string $name) { public function __construct(int $id, string $steamId, string $name) {
$this->id = $id; $this->id = $id;
@ -31,7 +28,10 @@ class SteamUser implements JsonSerializable {
public function getName(): string { public function getName(): string {
return $this->name; return $this->name;
} }
/**
* @return array{'id': int, 'name': string, 'steamid': string}
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() { public function jsonSerialize() {
return [ return [
'id' => $this->getId(), 'id' => $this->getId(),

View file

@ -34,7 +34,10 @@ class User implements JsonSerializable {
public function getToken(): string { public function getToken(): string {
return $this->token; return $this->token;
} }
/**
* @return array{'id': int, 'name': string, 'steamid': string}
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() { public function jsonSerialize() {
return [ return [
'id' => $this->getId(), 'id' => $this->getId(),

View file

@ -7,14 +7,9 @@ namespace Demostf\API\Demo;
use JsonSerializable; use JsonSerializable;
class ChatMessage implements JsonSerializable { class ChatMessage implements JsonSerializable {
/** @var string */ private string $user;
private $user; private int $time;
private string $message;
/** @var int */
private $time;
/** @var string */
private $message;
/** /**
* ChatMessage constructor. * ChatMessage constructor.
@ -37,6 +32,10 @@ class ChatMessage implements JsonSerializable {
return $this->message; return $this->message;
} }
/**
* @return array{'user': string, 'time': int, 'message': string}
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() { public function jsonSerialize() {
return [ return [
'user' => $this->user, 'user' => $this->user,

View file

@ -188,6 +188,16 @@ class Demo implements JsonSerializable {
return $this->path; return $this->path;
} }
/**
* @return array{
* 'id': int, 'url': string, 'name': string,
* 'server': string, 'duration': float, 'nick': string,
* 'map': string, 'time': int, 'red': string, 'blue': string,
* 'redScore': int, 'blueScore': int, 'playerCount': int,
* 'uploader': array, 'hash': string, 'backend': string, 'path': string
* }
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() { public function jsonSerialize() {
$data = [ $data = [
'id' => $this->getId(), 'id' => $this->getId(),

View file

@ -7,10 +7,8 @@ namespace Demostf\API\Demo;
use Demostf\API\Data\StoredDemo; use Demostf\API\Data\StoredDemo;
class DemoStore { class DemoStore {
/** @var string */ private string $root;
private $root; private string $webRoot;
/** @var string */
private $webRoot;
public function __construct(string $root, string $webRoot) { public function __construct(string $root, string $webRoot) {
$this->root = $root; $this->root = $root;

View file

@ -8,60 +8,17 @@ namespace Demostf\API\Demo;
* HL2 demo metadata. * HL2 demo metadata.
*/ */
class Header { class Header {
/** protected string $type;
* @var string protected int $version;
*/ protected int $protocol;
protected $type; protected string $server;
protected string $nick;
/** protected string $map;
* @var int protected string $game;
*/ protected float $duration;
protected $version; protected int $ticks;
protected int $frames;
/** protected int $sigon;
* @var int
*/
protected $protocol;
/**
* @var string
*/
protected $server;
/**
* @var string
*/
protected $nick;
/**
* @var string
*/
protected $map;
/**
* @var string
*/
protected $game;
/**
* @var float
*/
protected $duration;
/**
* @var int
*/
protected $ticks;
/**
* @var int
*/
protected $frames;
/**
* @var int
*/
protected $sigon;
public function __construct( public function __construct(
string $type, string $type,

View file

@ -28,8 +28,7 @@ class Parser {
9 => 'engineer', 9 => 'engineer',
]; ];
/** @var RawParser */ private RawParser $rawParser;
private $rawParser;
public function __construct(RawParser $rawParser) { public function __construct(RawParser $rawParser) {
$this->rawParser = $rawParser; $this->rawParser = $rawParser;

View file

@ -13,8 +13,7 @@ use GuzzleHttp\Exception\RequestException;
* Doesn't do any post-processing on the result * Doesn't do any post-processing on the result
*/ */
class RawParser { class RawParser {
/** @var string */ private string $parserPath;
private $parserPath;
public function __construct(string $parserPath) { public function __construct(string $parserPath) {
$this->parserPath = $parserPath; $this->parserPath = $parserPath;