mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-04 02:14:06 +02:00
lint
This commit is contained in:
parent
68f20ac903
commit
c29fe61ad1
24 changed files with 1242 additions and 50 deletions
|
|
@ -149,7 +149,7 @@ class Demo implements \JsonSerializable {
|
|||
$this->uploaderUser = $uploaderUser;
|
||||
}
|
||||
|
||||
public static function fromRow($row): Demo {
|
||||
public static function fromRow($row): self {
|
||||
return new self(
|
||||
(int) $row['id'],
|
||||
$row['url'],
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class DemoSaver {
|
|||
$upload->getBlue(),
|
||||
$demo->getRedScore(),
|
||||
$demo->getBlueScore(),
|
||||
count($demo->getPlayers()),
|
||||
\count($demo->getPlayers()),
|
||||
$upload->getUploaderId(),
|
||||
$upload->getHash(),
|
||||
$storedDemo->getBackend(),
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ class DemoStore {
|
|||
|
||||
public function store(string $sourcePath, string $name): StoredDemo {
|
||||
$target = $this->generatePath($name);
|
||||
if (!is_dir(dirname($target))) {
|
||||
mkdir(dirname($target), 0777, true);
|
||||
if (!is_dir(\dirname($target))) {
|
||||
mkdir(\dirname($target), 0777, true);
|
||||
}
|
||||
rename($sourcePath, $target);
|
||||
chmod($target, 0755);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class HeaderParser {
|
|||
'A8type/Iversion/Iprotocol/A260server/A260nick/A260map/A260game/fduration/Vticks/Vframes/Vsigon',
|
||||
$head
|
||||
);
|
||||
if (!isset($info['type']) || $info['type'] !== 'HL2DEMO') {
|
||||
if (!isset($info['type']) || 'HL2DEMO' !== $info['type']) {
|
||||
throw new \InvalidArgumentException('Not an HL2 demo');
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ class HeaderParser {
|
|||
if (!is_readable($path)) {
|
||||
throw new \InvalidArgumentException('Unable to open demo: ' . $path);
|
||||
}
|
||||
$fh = fopen($path, 'rb');
|
||||
$fh = fopen($path, 'r');
|
||||
|
||||
return $this->parseStream($fh);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class Parser {
|
|||
|
||||
public function analyse(string $path): ParsedDemo {
|
||||
$data = $this->rawParser->parse($path);
|
||||
if (is_array($data)) {
|
||||
if (\is_array($data)) {
|
||||
return $this->handleData($data);
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Error parsing demo');
|
||||
|
|
@ -55,7 +55,7 @@ class Parser {
|
|||
throw new \Exception("Error while parsing demo, no rounds field found\n" . json_encode($data));
|
||||
}
|
||||
foreach ($data['rounds'] as $round) {
|
||||
if ($round['winner'] === 'red') {
|
||||
if ('red' === $round['winner']) {
|
||||
++$red;
|
||||
} else {
|
||||
++$blue;
|
||||
|
|
@ -89,15 +89,15 @@ class Parser {
|
|||
if (!isset($activityMap[$kill->getAttackerDemoId()])) {
|
||||
$activityMap[$kill->getAttackerDemoId()] = 0;
|
||||
}
|
||||
$activityMap[$kill->getAttackerDemoId()]++;
|
||||
++$activityMap[$kill->getAttackerDemoId()];
|
||||
if (!isset($activityMap[$kill->getAssisterDemoId()])) {
|
||||
$activityMap[$kill->getAssisterDemoId()] = 0;
|
||||
}
|
||||
$activityMap[$kill->getAssisterDemoId()]++;
|
||||
++$activityMap[$kill->getAssisterDemoId()];
|
||||
if (!isset($activityMap[$kill->getVictimDemoId()])) {
|
||||
$activityMap[$kill->getVictimDemoId()] = 0;
|
||||
}
|
||||
$activityMap[$kill->getVictimDemoId()]++;
|
||||
++$activityMap[$kill->getVictimDemoId()];
|
||||
}
|
||||
|
||||
foreach ($data['users'] as $player) {
|
||||
|
|
@ -113,7 +113,7 @@ class Parser {
|
|||
$class = $classId;
|
||||
}
|
||||
}
|
||||
if ($player['steamId'] && $player['steamId'] !== 'BOT') {//skip spectators
|
||||
if ($player['steamId'] && 'BOT' !== $player['steamId']) {//skip spectators
|
||||
$players[] = new ParsedPlayer(
|
||||
$player['name'],
|
||||
$player['userId'],
|
||||
|
|
@ -152,7 +152,7 @@ class Parser {
|
|||
* @return string The converted 64bit numeric SteamID
|
||||
*/
|
||||
public static function convertSteamIdToCommunityId(string $steamId): string {
|
||||
if ($steamId === 'STEAM_ID_LAN' || $steamId === 'BOT') {
|
||||
if ('STEAM_ID_LAN' === $steamId || 'BOT' === $steamId) {
|
||||
throw new \InvalidArgumentException("Cannot convert SteamID \"$steamId\" to a community ID.");
|
||||
}
|
||||
if (preg_match('/^STEAM_[0-1]:[0-1]:[0-9]+$/', $steamId)) {
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ class RawParser {
|
|||
$response = $client->post($this->parserUrl, [
|
||||
'body' => stream_for($url),
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/octet-stream'
|
||||
]
|
||||
'Content-Type' => 'application/octet-stream',
|
||||
],
|
||||
]);
|
||||
$result = json_decode($response->getBody()->getContents(), true);
|
||||
$this->tempController->unregister($key);
|
||||
|
|
@ -45,7 +45,7 @@ class RawParser {
|
|||
}
|
||||
} catch (RequestException $e) {
|
||||
$this->tempController->unregister($key);
|
||||
if (strpos($e->getMessage(), 'cURL error 52') !== false) {
|
||||
if (false !== strpos($e->getMessage(), 'cURL error 52')) {
|
||||
throw new \Exception('Failed to parse demo, can\'t reach demo parser');
|
||||
}
|
||||
throw new \Exception('Failed to parse demo, ' . $e->getMessage() . ' ' . $url);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue