1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-03 18:04:08 +02:00
This commit is contained in:
Robin Appelman 2017-07-30 15:50:24 +02:00
commit b3fbc1be3c
7 changed files with 91 additions and 10 deletions

View file

@ -35,11 +35,11 @@ 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');
}
return $this->handleData($data);
}
private function handleData(array $data): ParsedDemo {
@ -60,7 +60,8 @@ class Parser {
foreach ($data['chat'] as $message) {
if (isset($message['from'])) {
$chat[] = new ChatMessage($message['from'], (int) floor(($message['tick'] - $data['startTick']) * $intervalPerTick), $message['text']);
$chat[] = new ChatMessage($message['from'],
(int)floor(($message['tick'] - $data['startTick']) * $intervalPerTick), $message['text']);
}
}
@ -79,13 +80,14 @@ class Parser {
$player['userId'],
$this->convertSteamIdToCommunityId($player['steamId']),
$player['team'],
$this->getClassName((int) $class)
$this->getClassName((int)$class)
);
}
}
$kills = array_map(function (array $death) {
return new ParsedKill($death['killer'] ?? 0, $death['assister'] ?? 0, $death['victim'] ?? 0, $death['weapon']);
return new ParsedKill($death['killer'] ?? 0, $death['assister'] ?? 0, $death['victim'] ?? 0,
$death['weapon']);
}, $data['deaths']);
return new ParsedDemo(

View file

@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Demostf\API\Demo;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
/**
* Wrapper around demo.js parser.
@ -32,7 +32,7 @@ class RawParser {
} else {
return $result;
}
} catch (GuzzleException $e) {
} catch (RequestException $e) {
if (strpos($e->getMessage(), 'cURL error 52') !== false) {
throw new \Exception('Failed to parse demo, can\'t reach demo parser');
}

View file

@ -21,6 +21,15 @@ class BaseProvider {
*/
protected $db;
/**
* BaseProvider constructor.
* @param Connection $connection
*
* The DBAL connection used will always be a PDO
* but phan isn't aware of this.
*
* @suppress PhanTypeMismatchArgument
*/
public function __construct(Connection $connection) {
$this->connection = $connection;
$this->db = new Database($connection->getWrappedConnection());