1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-04 02:14:06 +02:00

stricter cs

This commit is contained in:
Robin Appelman 2017-07-30 15:03:52 +02:00
commit d9a843ecd6
54 changed files with 346 additions and 168 deletions

View file

@ -1,12 +1,16 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace Demostf\API\Demo;
class HeaderParser {
/**
* @param string $head string containing the demo header binary data
* @return Header
*
* @throws \InvalidArgumentException
*
* @return Header
*/
public function parseString(string $head): Header {
$info = @unpack(
@ -16,33 +20,40 @@ class HeaderParser {
if (!isset($info['type']) || $info['type'] !== 'HL2DEMO') {
throw new \InvalidArgumentException('Not an HL2 demo');
}
return Header::fromArray($info);
}
/**
* Parse demo info from a stream
* Parse demo info from a stream.
*
* @param resource $stream
* @return Header
*
* @throws \InvalidArgumentException
*
* @return Header
*/
public function parseStream($stream): Header {
$head = fread($stream, 2048);
return $this->parseString($head);
}
/**
* Parse demo info from a local file
* Parse demo info from a local file.
*
* @param string $path
* @return Header
*
* @throws \InvalidArgumentException
*
* @return Header
*/
public function parseHeader(string $path): Header {
if (!is_readable($path)) {
throw new \InvalidArgumentException('Unable to open demo: ' . $path);
}
$fh = fopen($path, 'rb');
return $this->parseStream($fh);
}
}