1
0
Fork 0
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:
Robin Appelman 2017-07-30 14:51:54 +02:00
commit 309ae17036
54 changed files with 4900 additions and 4106 deletions

View file

@ -11,30 +11,30 @@ use GuzzleHttp\Exception\GuzzleException;
* Doesn't do any post-processing on the result
*/
class RawParser {
/** @var string */
private $parserUrl;
/** @var string */
private $parserUrl;
public function __construct(string $parserUrl) {
$this->parserUrl = $parserUrl;
}
public function __construct(string $parserUrl) {
$this->parserUrl = $parserUrl;
}
public function parse(string $path): ?array {
try {
$client = new Client();
$response = $client->post($this->parserUrl, [
'body' => fopen($path, 'r')
]);
$result = json_decode($response->getBody()->getContents(), true);
if (is_null($result)) {
throw new \Exception('Failed to parse demo, unexpected result from parser');
} else {
return $result;
}
} catch (GuzzleException $e) {
if (strpos($e->getMessage(), 'cURL error 52') !== false) {
throw new \Exception('Failed to parse demo, can\'t reach demo parser');
}
throw new \Exception('Failed to parse demo, ' . $e->getMessage());
}
}
public function parse(string $path): ?array {
try {
$client = new Client();
$response = $client->post($this->parserUrl, [
'body' => fopen($path, 'r')
]);
$result = json_decode($response->getBody()->getContents(), true);
if (is_null($result)) {
throw new \Exception('Failed to parse demo, unexpected result from parser');
} else {
return $result;
}
} catch (GuzzleException $e) {
if (strpos($e->getMessage(), 'cURL error 52') !== false) {
throw new \Exception('Failed to parse demo, can\'t reach demo parser');
}
throw new \Exception('Failed to parse demo, ' . $e->getMessage());
}
}
}