From b83603d2c5abeaa147bc9896a75e8a445486900a Mon Sep 17 00:00:00 2001 From: B3none Date: Wed, 27 Mar 2019 19:53:15 +0000 Subject: [PATCH 01/32] Started initial refactor --- Tests/ClientTest.php | 8 +-- composer.json | 8 ++- examples/cache/Laravel.php | 2 +- examples/cache/phpFastCache.php | 2 +- src/{API => }/APIClient.php | 69 ++++++++++------------ src/Exceptions/APIErrorException.php | 6 -- src/Exceptions/PlayerNotFoundException.php | 6 -- src/Helpers/Iteratable.php | 9 +++ src/{API => Helpers}/Request.php | 9 +-- src/{Types => Models}/Ban.php | 2 +- src/{Types => Models}/Bans.php | 2 +- src/{Types => Models}/GameTime.php | 10 +--- src/{Types => Models}/Player.php | 2 +- src/{Types => Models}/Server.php | 2 +- src/{Types => Models}/Servers.php | 3 +- src/Models/Version.php | 43 ++++++++++++++ src/Types/Version.php | 49 --------------- 17 files changed, 105 insertions(+), 127 deletions(-) rename src/{API => }/APIClient.php (54%) create mode 100644 src/Helpers/Iteratable.php rename src/{API => Helpers}/Request.php (86%) rename src/{Types => Models}/Ban.php (97%) rename src/{Types => Models}/Bans.php (98%) rename src/{Types => Models}/GameTime.php (89%) rename src/{Types => Models}/Player.php (98%) rename src/{Types => Models}/Server.php (98%) rename src/{Types => Models}/Servers.php (96%) create mode 100644 src/Models/Version.php delete mode 100644 src/Types/Version.php diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index 686ea9f..5f231a0 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -3,10 +3,10 @@ namespace TruckersMP\Tests\API; use Carbon\Carbon; -use TruckersMP\API\APIClient; -use TruckersMP\Types\Ban; -use TruckersMP\Types\Bans; -use TruckersMP\Types\Player; +use TruckersMP\Helpers\APIClient; +use TruckersMP\Models\Ban; +use TruckersMP\Models\Bans; +use TruckersMP\Models\Player; class ClientTest extends \PHPUnit_Framework_TestCase { diff --git a/composer.json b/composer.json index 2f6d7a8..0baba94 100644 --- a/composer.json +++ b/composer.json @@ -21,10 +21,16 @@ "email": "me@cjmaxik.ru", "homepage": "https://cjmaxik.ru", "role": "IGA/Dev" + }, + { + "name": "Alex Blackham (B3none)", + "email": "ablackham2000@gmail.com", + "homepage": "https://github.com/b3none", + "role": "Dev" } ], "require": { - "php": ">=5.6.0", + "php": ">=7.1.0", "nesbot/carbon": "^1.21", "php-http/message": "^1.2", "guzzlehttp/psr7": "^1.3" diff --git a/examples/cache/Laravel.php b/examples/cache/Laravel.php index a88bb1a..57a77cb 100644 --- a/examples/cache/Laravel.php +++ b/examples/cache/Laravel.php @@ -11,7 +11,7 @@ use App\Http\Requests; use Cache; use Illuminate\Http\Request; -use TruckersMP\API\APIClient; +use TruckersMP\Helpers\APIClient; class SearchController extends Controller { diff --git a/examples/cache/phpFastCache.php b/examples/cache/phpFastCache.php index 08e59c3..be4784a 100644 --- a/examples/cache/phpFastCache.php +++ b/examples/cache/phpFastCache.php @@ -7,7 +7,7 @@ */ use phpFastCache\CacheManager; -use TruckersMP\API\APIClient; +use TruckersMP\Helpers\APIClient; // Setup File Path on your config files CacheManager::setup([ diff --git a/src/API/APIClient.php b/src/APIClient.php similarity index 54% rename from src/API/APIClient.php rename to src/APIClient.php index b351292..a2ef922 100644 --- a/src/API/APIClient.php +++ b/src/APIClient.php @@ -1,17 +1,17 @@ request->execute('player/' . $id); @@ -56,14 +52,13 @@ public function player($id) } /** - * @param $id + * Get bans information by player ID. * + * @param int $id * @throws \Exception - * @throws \Http\Client\Exception - * - * @return \TruckersMP\Types\Bans + * @return \TruckersMP\Models\Bans */ - public function bans($id) + public function bans(int $id): Bans { $result = $this->request->execute('bans/' . $id); @@ -71,12 +66,12 @@ public function bans($id) } /** - * @throws \Exception - * @throws \Http\Client\Exception + * Get server information. * - * @return \TruckersMP\Types\Servers + * @throws \Exception + * @return \TruckersMP\Models\Servers */ - public function servers() + public function servers(): Servers { $result = $this->request->execute('servers'); @@ -84,12 +79,12 @@ public function servers() } /** - * @throws \Exception - * @throws \Http\Client\Exception + * Get the current game time * - * @return \TruckersMP\Types\GameTime + * @throws \Exception + * @return \TruckersMP\Models\GameTime */ - public function gameTime() + public function gameTime(): GameTime { $result = $this->request->execute('game_time'); @@ -98,11 +93,9 @@ public function gameTime() /** * @throws \Exception - * @throws \Http\Client\Exception - * - * @return \TruckersMP\Types\Version + * @return \TruckersMP\Models\Version */ - public function version() + public function version(): Version { $result = $this->request->execute('version'); diff --git a/src/Exceptions/APIErrorException.php b/src/Exceptions/APIErrorException.php index 28749af..3dd7956 100644 --- a/src/Exceptions/APIErrorException.php +++ b/src/Exceptions/APIErrorException.php @@ -1,10 +1,4 @@ message = new GuzzleMessageFactory(); $this->apiEndpoint = $apiEndpoint; - $this->adapter = new GuzzleAdapter(new GuzzleClient($config)); + $this->adapter = new GuzzleAdapter(new GuzzleClient($config)); } /** diff --git a/src/Types/Ban.php b/src/Models/Ban.php similarity index 97% rename from src/Types/Ban.php rename to src/Models/Ban.php index 369cad3..8e4e57b 100644 --- a/src/Types/Ban.php +++ b/src/Models/Ban.php @@ -1,6 +1,6 @@ version = new \stdClass(); + $this->version->human = $response['name']; + $this->version->stage = $response['stage']; + $this->version->nummeric = $response['numeric']; + + $this->checksum = new \stdClass(); + $this->checksum->atsmp = new \stdClass(); + $this->checksum->atsmp->dll = $response['atsmp_checksum']['dll']; + $this->checksum->atsmp->adb = $response['atsmp_checksum']['adb']; + $this->checksum->ets2mp = new \stdClass(); + $this->checksum->ets2mp->dll = $response['atsmp_checksum']['dll']; + $this->checksum->ets2mp->adb = $response['atsmp_checksum']['adb']; + + $this->released = new Carbon($response['time'], 'UTC'); + + $this->support = new \stdClass(); + $this->support->ets2 = $response['supported_game_version']; + $this->support->ats = $response['supported_ats_game_version']; + } +} diff --git a/src/Types/Version.php b/src/Types/Version.php deleted file mode 100644 index 9765a2b..0000000 --- a/src/Types/Version.php +++ /dev/null @@ -1,49 +0,0 @@ -version = new \stdClass(); - $this->version->human = $response['name']; - $this->version->stage = $response['stage']; - $this->version->nummeric = $response['numeric']; - - $this->checksum = new \stdClass(); - $this->checksum->atsmp = new \stdClass(); - $this->checksum->atsmp->dll = $response['atsmp_checksum']['dll']; - $this->checksum->atsmp->adb = $response['atsmp_checksum']['adb']; - $this->checksum->ets2mp = new \stdClass(); - $this->checksum->ets2mp->dll = $response['atsmp_checksum']['dll']; - $this->checksum->ets2mp->adb = $response['atsmp_checksum']['adb']; - - $this->released = new Carbon($response['time'], 'UTC'); - - $this->support = new \stdClass(); - $this->support->ets2 = $response['supported_game_version']; - $this->support->ats = $response['supported_ats_game_version']; - } -} From 2ff6d7dc98766ab74bfff157de267d25c11c8276 Mon Sep 17 00:00:00 2001 From: B3none Date: Wed, 27 Mar 2019 19:56:40 +0000 Subject: [PATCH 02/32] Renamed models, removed iterable helper. --- Tests/ClientTest.php | 39 ++++++++-------- src/APIClient.php | 44 +++++++++---------- src/Helpers/Iteratable.php | 9 ---- .../{Request.php => RequestHelper.php} | 4 +- src/Models/{Ban.php => BanModel.php} | 4 +- src/Models/{Bans.php => BansModel.php} | 6 +-- .../{GameTime.php => GameTimeModel.php} | 4 +- src/Models/{Player.php => PlayerModel.php} | 4 +- src/Models/{Server.php => ServerModel.php} | 4 +- src/Models/{Servers.php => ServersModel.php} | 6 +-- src/Models/{Version.php => VersionModel.php} | 4 +- 11 files changed, 60 insertions(+), 68 deletions(-) delete mode 100644 src/Helpers/Iteratable.php rename src/Helpers/{Request.php => RequestHelper.php} (95%) rename src/Models/{Ban.php => BanModel.php} (96%) rename src/Models/{Bans.php => BansModel.php} (94%) rename src/Models/{GameTime.php => GameTimeModel.php} (94%) rename src/Models/{Player.php => PlayerModel.php} (97%) rename src/Models/{Server.php => ServerModel.php} (98%) rename src/Models/{Servers.php => ServersModel.php} (92%) rename src/Models/{Version.php => VersionModel.php} (95%) diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index 5f231a0..795718b 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -4,19 +4,24 @@ use Carbon\Carbon; use TruckersMP\Helpers\APIClient; -use TruckersMP\Models\Ban; -use TruckersMP\Models\Bans; -use TruckersMP\Models\Player; +use TruckersMP\Models\BanModel; +use TruckersMP\Models\BansModel; +use TruckersMP\Models\PlayerModel; class ClientTest extends \PHPUnit_Framework_TestCase { - private $testAccount = 585204; + /** + * @var int + */ + protected $testAccount = 585204; - private $client; + /** + * @var APIClient + */ + protected $client; /** * ClientTest constructor. - * */ public function __construct() { @@ -27,24 +32,22 @@ public function __construct() /** * @throws \Exception - * @throws \Http\Client\Exception */ - public function testPlayer() + public function testPlayer(): void { $player = $this->client->player($this->testAccount); $this->assertEquals($player->name, 'tuxytestaccount'); $this->assertEquals($player->groupID, 1); - $this->assertEquals($player->groupName, 'Player'); + $this->assertEquals($player->groupName, 'PlayerModel'); - $this->assertInstanceOf(Player::class, $player); + $this->assertInstanceOf(PlayerModel::class, $player); } /** * @throws \Exception - * @throws \Http\Client\Exception */ - public function testPlayerBans() + public function testPlayerBans(): void { $bans = $this->client->bans($this->testAccount); @@ -52,15 +55,14 @@ public function testPlayerBans() $this->assertEquals($bans[0]->created, '2016-06-19 10:08:26'); $this->assertEquals($bans[0]->reason, 'Test ban'); - $this->assertInstanceOf(Bans::class, $bans); - $this->assertInstanceOf(Ban::class, $bans[0]); + $this->assertInstanceOf(BansModel::class, $bans); + $this->assertInstanceOf(BanModel::class, $bans[0]); } /** * @throws \Exception - * @throws \Http\Client\Exception */ - public function testServers() + public function testServers(): void { $servers = $this->client->servers(); @@ -69,9 +71,8 @@ public function testServers() /** * @throws \Exception - * @throws \Http\Client\Exception */ - public function testVersion() + public function testVersion(): void { $version = $this->client->version(); @@ -90,7 +91,7 @@ public function testVersion() $this->assertNotEmpty($version->support->ats); } - public function testGameTime() + public function testGameTime(): void { $time = $this->client->gameTime(); diff --git a/src/APIClient.php b/src/APIClient.php index a2ef922..53c82b9 100644 --- a/src/APIClient.php +++ b/src/APIClient.php @@ -7,11 +7,11 @@ namespace TruckersMP\Helpers; -use TruckersMP\Models\Bans; -use TruckersMP\Models\GameTime; -use TruckersMP\Models\Player; -use TruckersMP\Models\Servers; -use TruckersMP\Models\Version; +use TruckersMP\Models\BansModel; +use TruckersMP\Models\GameTimeModel; +use TruckersMP\Models\PlayerModel; +use TruckersMP\Models\ServersModel; +use TruckersMP\Models\VersionModel; class APIClient { @@ -19,7 +19,7 @@ class APIClient const API_VERSION = 'v2'; /** - * @var \TruckersMP\Helpers\Request + * @var \TruckersMP\Helpers\RequestHelper */ protected $request; @@ -34,7 +34,7 @@ public function __construct(array $config = [], bool $secure = true) $scheme = $secure ? 'https' : 'http'; $url = $scheme . '://' . self::API_ENDPOINT . '/' . self::API_VERSION . '/'; - $this->request = new Request($url, $config); + $this->request = new RequestHelper($url, $config); } /** @@ -42,13 +42,13 @@ public function __construct(array $config = [], bool $secure = true) * * @param int $id * @throws \Exception - * @return \TruckersMP\Models\Player + * @return \TruckersMP\Models\PlayerModel */ - public function player(int $id): Player + public function player(int $id): PlayerModel { $result = $this->request->execute('player/' . $id); - return new Player($result); + return new PlayerModel($result); } /** @@ -56,49 +56,49 @@ public function player(int $id): Player * * @param int $id * @throws \Exception - * @return \TruckersMP\Models\Bans + * @return \TruckersMP\Models\BansModel */ - public function bans(int $id): Bans + public function bans(int $id): BansModel { $result = $this->request->execute('bans/' . $id); - return new Bans($result); + return new BansModel($result); } /** * Get server information. * * @throws \Exception - * @return \TruckersMP\Models\Servers + * @return \TruckersMP\Models\ServersModel */ - public function servers(): Servers + public function servers(): ServersModel { $result = $this->request->execute('servers'); - return new Servers($result); + return new ServersModel($result); } /** * Get the current game time * * @throws \Exception - * @return \TruckersMP\Models\GameTime + * @return \TruckersMP\Models\GameTimeModel */ - public function gameTime(): GameTime + public function gameTime(): GameTimeModel { $result = $this->request->execute('game_time'); - return new GameTime($result); + return new GameTimeModel($result); } /** * @throws \Exception - * @return \TruckersMP\Models\Version + * @return \TruckersMP\Models\VersionModel */ - public function version(): Version + public function version(): VersionModel { $result = $this->request->execute('version'); - return new Version($result); + return new VersionModel($result); } } diff --git a/src/Helpers/Iteratable.php b/src/Helpers/Iteratable.php deleted file mode 100644 index 7cc53da..0000000 --- a/src/Helpers/Iteratable.php +++ /dev/null @@ -1,9 +0,0 @@ - $ban) { - $this->bans[$k] = new Ban($ban); + $this->bans[$k] = new BanModel($ban); } } diff --git a/src/Models/GameTime.php b/src/Models/GameTimeModel.php similarity index 94% rename from src/Models/GameTime.php rename to src/Models/GameTimeModel.php index 8926c18..fb5938e 100644 --- a/src/Models/GameTime.php +++ b/src/Models/GameTimeModel.php @@ -4,12 +4,12 @@ use Carbon\Carbon; -class GameTime +class GameTimeModel { public $time; /** - * GameTime constructor. + * GameTimeModel constructor. * * @param array $response * diff --git a/src/Models/Player.php b/src/Models/PlayerModel.php similarity index 97% rename from src/Models/Player.php rename to src/Models/PlayerModel.php index 3cca906..7224441 100644 --- a/src/Models/Player.php +++ b/src/Models/PlayerModel.php @@ -4,7 +4,7 @@ use TruckersMP\Exceptions\PlayerNotFoundException; -class Player +class PlayerModel { /** * User ID. @@ -63,7 +63,7 @@ class Player public $inGameAdmin; /** - * Player constructor. + * PlayerModel constructor. * * @param array $response * diff --git a/src/Models/Server.php b/src/Models/ServerModel.php similarity index 98% rename from src/Models/Server.php rename to src/Models/ServerModel.php index 262d508..da3f062 100644 --- a/src/Models/Server.php +++ b/src/Models/ServerModel.php @@ -2,7 +2,7 @@ namespace TruckersMP\Models; -class Server +class ServerModel { /** * Game server ID. @@ -117,7 +117,7 @@ class Server public $syncDelay; /** - * Server constructor. + * ServerModel constructor. * * @param array $server */ diff --git a/src/Models/Servers.php b/src/Models/ServersModel.php similarity index 92% rename from src/Models/Servers.php rename to src/Models/ServersModel.php index 7d16fba..7c8322d 100644 --- a/src/Models/Servers.php +++ b/src/Models/ServersModel.php @@ -4,7 +4,7 @@ use TruckersMP\Exceptions\APIErrorException; -class Servers implements \Iterator, \ArrayAccess +class ServersModel implements \Iterator, \ArrayAccess { /** * Array of servers. @@ -21,7 +21,7 @@ class Servers implements \Iterator, \ArrayAccess private $position = 0; /** - * Servers constructor. + * ServersModel constructor. * * @param array $response * @@ -36,7 +36,7 @@ public function __construct(array $response) } foreach ($response['response'] as $k => $server) { - $this->servers[$k] = new Server($server); + $this->servers[$k] = new ServerModel($server); } } diff --git a/src/Models/Version.php b/src/Models/VersionModel.php similarity index 95% rename from src/Models/Version.php rename to src/Models/VersionModel.php index 1d12abe..c2a7a38 100644 --- a/src/Models/Version.php +++ b/src/Models/VersionModel.php @@ -4,7 +4,7 @@ use Carbon\Carbon; -class Version +class VersionModel { public $version; @@ -15,7 +15,7 @@ class Version public $support; /** - * Version constructor. + * VersionModel constructor. * * @param array $response */ From e084a4946b93df1d1dae13bbcb6cc2f1c60e5d69 Mon Sep 17 00:00:00 2001 From: B3none Date: Wed, 27 Mar 2019 20:23:32 +0000 Subject: [PATCH 03/32] Refactored models and implemented GroupedModel class to extend from. --- composer.json | 3 +- composer.lock | 58 +++++++++++++++++++-- src/Models/BansModel.php | 91 +++------------------------------ src/Models/GameTimeModel.php | 3 ++ src/Models/GroupedModel.php | 98 ++++++++++++++++++++++++++++++++++++ src/Models/PlayerModel.php | 15 +++--- src/Models/ServerModel.php | 30 +++++------ src/Models/ServersModel.php | 58 ++------------------- src/Models/VersionModel.php | 12 +++++ 9 files changed, 202 insertions(+), 166 deletions(-) create mode 100644 src/Models/GroupedModel.php diff --git a/composer.json b/composer.json index 0baba94..912eaed 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ "php": ">=7.1.0", "nesbot/carbon": "^1.21", "php-http/message": "^1.2", - "guzzlehttp/psr7": "^1.3" + "guzzlehttp/psr7": "^1.3", + "leedavis81/vent": "dev-master" }, "require-dev": { "phpunit/phpunit": "^5.3", diff --git a/composer.lock b/composer.lock index 6875e2b..dc03677 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b1dd8f3b08c2fbe389ccc6ed1f4f8f96", + "content-hash": "8a5cead4663ab9dc6e9927dad2e85941", "packages": [ { "name": "clue/stream-filter", @@ -120,6 +120,54 @@ ], "time": "2017-03-20T17:10:46+00:00" }, + { + "name": "leedavis81/vent", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/leedavis81/vent.git", + "reference": "b2e7892960df93260e0e3d0e58ba95228b2c30d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/leedavis81/vent/zipball/b2e7892960df93260e0e3d0e58ba95228b2c30d3", + "reference": "b2e7892960df93260e0e3d0e58ba95228b2c30d3", + "shasum": "" + }, + "require": { + "php": ">=5.4" + }, + "require-dev": { + "phpunit/phpunit": "3.7.*", + "satooshi/php-coveralls": "~0.6" + }, + "type": "library", + "autoload": { + "psr-0": { + "Vent\\": "src/", + "VentTest\\": "tests/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Lee Davis", + "email": "leedavis81@hotmail.com", + "homepage": "http://leedavis81.github.io", + "role": "Developer" + } + ], + "description": "PHP variable events.", + "keywords": [ + "event", + "php", + "variable" + ], + "time": "2014-03-04T17:17:50+00:00" + }, { "name": "nesbot/carbon", "version": "1.22.1", @@ -2140,11 +2188,13 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "leedavis81/vent": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.6.0" + "php": ">=7.1.0" }, "platform-dev": [] } diff --git a/src/Models/BansModel.php b/src/Models/BansModel.php index 04b6725..b8875c9 100644 --- a/src/Models/BansModel.php +++ b/src/Models/BansModel.php @@ -2,23 +2,19 @@ namespace TruckersMP\Models; -use Psr\Http\Message\ResponseInterface; use TruckersMP\Exceptions\PlayerNotFoundException; +use Vent\VentTrait; -class BansModel implements \Iterator, \ArrayAccess +class BansModel extends GroupedModel { + use VentTrait; + /** * Array of bans. * * @var array */ - public $bans; - /** - * Iterator position. - * - * @var int - */ - private $position = 0; + public $bans = []; /** * BansModel constructor. @@ -41,82 +37,7 @@ public function __construct(array $response) foreach ($response['response'] as $k => $ban) { $this->bans[$k] = new BanModel($ban); } - } - public function rewind() - { - $this->position = 0; - } - - /** - * @return mixed - */ - public function current() - { - return $this->bans[$this->position]; - } - - /** - * @return int - */ - public function key() - { - return $this->position; - } - - public function next() - { - ++$this->position; - } - - /** - * @return bool - */ - public function valid() - { - return isset($this->bans[$this->position]); - } - - /** - * @param mixed $offset - * @param mixed $value - * - * @return \Exception - */ - public function offsetSet($offset, $value) - { - // TODO: custom class that gives a better description of the error - return new \Exception('Can not change bans'); - } - - /** - * @param mixed $offset - * - * @return bool - */ - public function offsetExists($offset) - { - return isset($this->bans[$offset]); - } - - /** - * @param mixed $offset - * - * @return \Exception - */ - public function offsetUnset($offset) - { - // TODO: custom class that gives a better description of the error - return new \Exception('Can not change bans'); - } - - /** - * @param mixed $offset - * - * @return mixed|null - */ - public function offsetGet($offset) - { - return isset($this->bans[$offset]) ? $this->bans[$offset] : null; + $this->groupedValue = $this->bans; } } diff --git a/src/Models/GameTimeModel.php b/src/Models/GameTimeModel.php index fb5938e..3b886d0 100644 --- a/src/Models/GameTimeModel.php +++ b/src/Models/GameTimeModel.php @@ -6,6 +6,9 @@ class GameTimeModel { + /** + * @var Carbon + */ public $time; /** diff --git a/src/Models/GroupedModel.php b/src/Models/GroupedModel.php new file mode 100644 index 0000000..3132343 --- /dev/null +++ b/src/Models/GroupedModel.php @@ -0,0 +1,98 @@ +position = 0; + } + + /** + * @return mixed + */ + public function current() + { + return $this->groupedValue[$this->position]; + } + + /** + * @return int + */ + public function key(): int + { + return $this->position; + } + + /** + * @return void + */ + public function next(): void + { + $this->position++; + } + + /** + * @return bool + */ + public function valid(): bool + { + return isset($this->groupedValue[$this->position]); + } + + /** + * @param mixed $offset + * @param mixed $value + * @return \Exception + */ + public function offsetSet($offset, $value): \Exception + { + return new \Exception($this->exceptionMessage); + } + + /** + * @param mixed $offset + * @return bool + */ + public function offsetExists($offset): bool + { + return isset($this->groupedValue[$offset]); + } + + /** + * @param mixed $offset + * @return \Exception + */ + public function offsetUnset($offset): \Exception + { + return new \Exception($this->exceptionMessage); + } + + /** + * @param mixed $offset + * @return bool|null + */ + public function offsetGet($offset): ?bool + { + return isset($this->groupedValue[$offset]) ? $this->groupedValue[$offset] : null; + } +} \ No newline at end of file diff --git a/src/Models/PlayerModel.php b/src/Models/PlayerModel.php index 7224441..f21a2ac 100644 --- a/src/Models/PlayerModel.php +++ b/src/Models/PlayerModel.php @@ -66,7 +66,6 @@ class PlayerModel * PlayerModel constructor. * * @param array $response - * * @throws \TruckersMP\Exceptions\PlayerNotFoundException */ public function __construct(array $response) @@ -75,13 +74,13 @@ public function __construct(array $response) throw new PlayerNotFoundException($response['response']); } - $this->id = $response['response']['id']; - $this->name = $response['response']['name']; - $this->avatar = $response['response']['avatar']; - $this->joinDate = $response['response']['joinDate']; - $this->steamID64 = $response['response']['steamID64']; - $this->groupID = $response['response']['groupID']; - $this->groupName = $response['response']['groupName']; + $this->id = $response['response']['id']; + $this->name = $response['response']['name']; + $this->avatar = $response['response']['avatar']; + $this->joinDate = $response['response']['joinDate']; + $this->steamID64 = $response['response']['steamID64']; + $this->groupID = $response['response']['groupID']; + $this->groupName = $response['response']['groupName']; $this->inGameAdmin = $response['response']['permissions']['isGameAdmin']; } } diff --git a/src/Models/ServerModel.php b/src/Models/ServerModel.php index da3f062..a344eab 100644 --- a/src/Models/ServerModel.php +++ b/src/Models/ServerModel.php @@ -123,21 +123,21 @@ class ServerModel */ public function __construct(array $server) { - $this->id = intval($server['id']); - $this->game = $server['game']; - $this->ip = $server['ip']; - $this->port = intval($server['port']); - $this->name = $server['name']; - $this->shortName = $server['shortname']; - $this->online = boolval($server['online']); - $this->players = intval($server['players']); - $this->queue = intval($server['queue']); - $this->maxPlayers = intval($server['maxplayers']); - $this->speedLimiter = boolval($server['speedlimiter']); - $this->collisions = boolval($server['collisions']); - $this->carsForPlayers = boolval($server['carsforplayers']); + $this->id = intval($server['id']); + $this->game = $server['game']; + $this->ip = $server['ip']; + $this->port = intval($server['port']); + $this->name = $server['name']; + $this->shortName = $server['shortname']; + $this->online = boolval($server['online']); + $this->players = intval($server['players']); + $this->queue = intval($server['queue']); + $this->maxPlayers = intval($server['maxplayers']); + $this->speedLimiter = boolval($server['speedlimiter']); + $this->collisions = boolval($server['collisions']); + $this->carsForPlayers = boolval($server['carsforplayers']); $this->policeCarsForPlayers = boolval($server['policecarsforplayers']); - $this->afkEnabled = boolval($server['afkenabled']); - $this->syncDelay = intval($server['syncdelay']); + $this->afkEnabled = boolval($server['afkenabled']); + $this->syncDelay = intval($server['syncdelay']); } } diff --git a/src/Models/ServersModel.php b/src/Models/ServersModel.php index 7c8322d..03daa58 100644 --- a/src/Models/ServersModel.php +++ b/src/Models/ServersModel.php @@ -4,27 +4,24 @@ use TruckersMP\Exceptions\APIErrorException; -class ServersModel implements \Iterator, \ArrayAccess +class ServersModel extends GroupedModel { /** * Array of servers. * * @var array */ - public $servers; + public $servers = []; /** - * Iterator position. - * - * @var int + * @var string */ - private $position = 0; + protected $exceptionMessage = 'You do not have access to modify the servers.'; /** * ServersModel constructor. * * @param array $response - * * @throws APIErrorException */ public function __construct(array $response) @@ -38,52 +35,7 @@ public function __construct(array $response) foreach ($response['response'] as $k => $server) { $this->servers[$k] = new ServerModel($server); } - } - - public function rewind() - { - $this->position = 0; - } - public function current() - { - return $this->servers[$this->position]; - } - - public function key() - { - return $this->position; - } - - public function next() - { - ++$this->position; - } - - public function valid() - { - return isset($this->servers[$this->position]); - } - - public function offsetSet($offset, $value) - { - // TODO: custom class that gives a better description of the error - return new \Exception('Can not change servers'); - } - - public function offsetExists($offset) - { - return isset($this->servers[$offset]); - } - - public function offsetUnset($offset) - { - // TODO: custom class that gives a better description of the error - return new \Exception('Can not change servers'); - } - - public function offsetGet($offset) - { - return isset($this->servers[$offset]) ? $this->servers[$offset] : null; + $this->groupedValue = $this->servers; } } diff --git a/src/Models/VersionModel.php b/src/Models/VersionModel.php index c2a7a38..7e11339 100644 --- a/src/Models/VersionModel.php +++ b/src/Models/VersionModel.php @@ -6,12 +6,24 @@ class VersionModel { + /** + * @var \stdClass + */ public $version; + /** + * @var \stdClass + */ public $checksum; + /** + * @var Carbon + */ public $released; + /** + * @var \stdClass + */ public $support; /** From 5e77325e25ac39b049b3e7da6027806c411db4f5 Mon Sep 17 00:00:00 2001 From: B3none Date: Wed, 27 Mar 2019 20:26:53 +0000 Subject: [PATCH 04/32] Removed silly spacing --- src/APIClient.php | 2 +- src/Models/BanModel.php | 4 ++-- src/Models/GameTimeModel.php | 13 ++++++------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/APIClient.php b/src/APIClient.php index 53c82b9..2137c93 100644 --- a/src/APIClient.php +++ b/src/APIClient.php @@ -32,7 +32,7 @@ class APIClient public function __construct(array $config = [], bool $secure = true) { $scheme = $secure ? 'https' : 'http'; - $url = $scheme . '://' . self::API_ENDPOINT . '/' . self::API_VERSION . '/'; + $url = $scheme . '://' . self::API_ENDPOINT . '/' . self::API_VERSION . '/'; $this->request = new RequestHelper($url, $config); } diff --git a/src/Models/BanModel.php b/src/Models/BanModel.php index 1efdf11..48eed86 100644 --- a/src/Models/BanModel.php +++ b/src/Models/BanModel.php @@ -73,8 +73,8 @@ public function __construct($ban) } } - $this->reason = $ban['reason']; + $this->reason = $ban['reason']; $this->adminName = $ban['adminName']; - $this->adminID = $ban['adminID']; + $this->adminID = $ban['adminID']; } } diff --git a/src/Models/GameTimeModel.php b/src/Models/GameTimeModel.php index 3b886d0..2591430 100644 --- a/src/Models/GameTimeModel.php +++ b/src/Models/GameTimeModel.php @@ -15,27 +15,26 @@ class GameTimeModel * GameTimeModel constructor. * * @param array $response - * * @throws \Exception */ public function __construct(array $response) { if ($response['error']) { - // TODO: actually throw a usable error - throw new \Exception('API Error'); + throw new \Exception($response['error']); } + $load['minutes'] = $response['game_time']; - $load['hours'] = $load['minutes'] / 60; + $load['hours'] = $load['minutes'] / 60; $load['minutes'] = $load['minutes'] % 60; - $load['days'] = $load['hours'] / 24; + $load['days'] = $load['hours'] / 24; $load['hours'] = $load['hours'] % 24; $load['months'] = $load['days'] / 30; - $load['days'] = $load['days'] % 30; + $load['days'] = $load['days'] % 30; - $load['years'] = intval($load['months'] / 12); + $load['years'] = intval($load['months'] / 12); $load['months'] = $load['months'] % 12; $this->time = Carbon::create($load['years'], $load['months'], $load['days'], $load['hours'], $load['minutes']); From 5e5753dda72715ba3348556d985b1431f7e8b99a Mon Sep 17 00:00:00 2001 From: B3none Date: Wed, 27 Mar 2019 20:33:39 +0000 Subject: [PATCH 05/32] Added write listeners for grouped variables --- src/Models/BansModel.php | 8 +++++--- src/Models/ServersModel.php | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Models/BansModel.php b/src/Models/BansModel.php index b8875c9..be12c8a 100644 --- a/src/Models/BansModel.php +++ b/src/Models/BansModel.php @@ -20,11 +20,15 @@ class BansModel extends GroupedModel * BansModel constructor. * * @param array $response - * * @throws \TruckersMP\Exceptions\PlayerNotFoundException */ public function __construct(array $response) { + // Make sure our grouped variable is kept updated + $this->registerEvent('write', 'bans', function(){ + $this->groupedValue = $this->bans; + }); + $this->position = 0; if ($response['error'] && @@ -37,7 +41,5 @@ public function __construct(array $response) foreach ($response['response'] as $k => $ban) { $this->bans[$k] = new BanModel($ban); } - - $this->groupedValue = $this->bans; } } diff --git a/src/Models/ServersModel.php b/src/Models/ServersModel.php index 03daa58..ec14ed1 100644 --- a/src/Models/ServersModel.php +++ b/src/Models/ServersModel.php @@ -3,9 +3,12 @@ namespace TruckersMP\Models; use TruckersMP\Exceptions\APIErrorException; +use Vent\VentTrait; class ServersModel extends GroupedModel { + use VentTrait; + /** * Array of servers. * @@ -26,6 +29,11 @@ class ServersModel extends GroupedModel */ public function __construct(array $response) { + // Make sure our grouped variable is kept updated + $this->registerEvent('write', 'servers', function(){ + $this->groupedValue = $this->servers; + }); + $this->position = 0; if ($response['error'] == 'true' && $response['descriptor'] == 'Unable to fetch servers') { From 866c135c37f278c2e29e32e38cc934af8b56c0a3 Mon Sep 17 00:00:00 2001 From: B3none Date: Wed, 27 Mar 2019 20:35:42 +0000 Subject: [PATCH 06/32] Throw APIErrorException if there's a gametime endpoint error --- src/Models/GameTimeModel.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Models/GameTimeModel.php b/src/Models/GameTimeModel.php index 2591430..5b87728 100644 --- a/src/Models/GameTimeModel.php +++ b/src/Models/GameTimeModel.php @@ -3,6 +3,7 @@ namespace TruckersMP\Models; use Carbon\Carbon; +use TruckersMP\Exceptions\APIErrorException; class GameTimeModel { @@ -20,7 +21,7 @@ class GameTimeModel public function __construct(array $response) { if ($response['error']) { - throw new \Exception($response['error']); + throw new APIErrorException($response['error']); } $load['minutes'] = $response['game_time']; From f051502f1732cffdef89a5f9bb219841275f033f Mon Sep 17 00:00:00 2001 From: B3none Date: Wed, 27 Mar 2019 20:41:42 +0000 Subject: [PATCH 07/32] Fixed wording in readme --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 6b39f54..a8f0489 100644 --- a/readme.md +++ b/readme.md @@ -10,16 +10,16 @@ This is a PHP library created to simplify development using the [TruckersMP](http://truckersmp.com/) API. This client library provides functions to connect and gather data from each API endpoint, and returns the data as an object. -> If you want to use API without library (or if you have advanced knowledge of PHP), check out [API documentation](https://stats.truckersmp.com/api). +> If you want to use the API without a library (or if you have advanced knowledge of PHP), check out our [API documentation](https://stats.truckersmp.com/api). ## Warning! -Please use our service responsibly. API Consumers who require high rates of requests against our APIs should contact TruckersMP Staff with a rationale and contact email for high-rate usage. +Please use our service responsibly. People who make lots of requests to our API should contact TruckersMP Staff with a rationale and contact email. ## Requirements -- PHP 5.6.0 or newer +- PHP 7.1.0 or newer - Composer ## Installation @@ -39,7 +39,7 @@ After doing either of the above, execute the command `composer install`. ```php Date: Wed, 27 Mar 2019 20:43:16 +0000 Subject: [PATCH 08/32] Removed redundant PHP versions from Travis setup --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a3caff7..7d7276b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,6 @@ cache: - $HOME/.composer/cache php: - - 5.6 - - 7.0 - 7.1 - hhvm From 5fc36688a0db4c4a87aa6c450d1f134ace6e8a9e Mon Sep 17 00:00:00 2001 From: B3none Date: Wed, 27 Mar 2019 20:45:49 +0000 Subject: [PATCH 09/32] Altered .gitignore --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 34a600c..d257e62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,11 @@ -### Composer ### +# Composer composer.phar /vendor/ + +# PHPStorm /.idea/ + +# Unit Tests /Tests/cache/ From 7f537990f26e078bb5cf67e914834fa576969d2e Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 00:03:58 +0000 Subject: [PATCH 10/32] Fixed PHPCBF errors. --- src/Models/BansModel.php | 2 +- src/Models/GroupedModel.php | 2 +- src/Models/ServersModel.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Models/BansModel.php b/src/Models/BansModel.php index be12c8a..85669c6 100644 --- a/src/Models/BansModel.php +++ b/src/Models/BansModel.php @@ -25,7 +25,7 @@ class BansModel extends GroupedModel public function __construct(array $response) { // Make sure our grouped variable is kept updated - $this->registerEvent('write', 'bans', function(){ + $this->registerEvent('write', 'bans', function () { $this->groupedValue = $this->bans; }); diff --git a/src/Models/GroupedModel.php b/src/Models/GroupedModel.php index 3132343..e78afe8 100644 --- a/src/Models/GroupedModel.php +++ b/src/Models/GroupedModel.php @@ -95,4 +95,4 @@ public function offsetGet($offset): ?bool { return isset($this->groupedValue[$offset]) ? $this->groupedValue[$offset] : null; } -} \ No newline at end of file +} diff --git a/src/Models/ServersModel.php b/src/Models/ServersModel.php index ec14ed1..0ea9cc0 100644 --- a/src/Models/ServersModel.php +++ b/src/Models/ServersModel.php @@ -30,7 +30,7 @@ class ServersModel extends GroupedModel public function __construct(array $response) { // Make sure our grouped variable is kept updated - $this->registerEvent('write', 'servers', function(){ + $this->registerEvent('write', 'servers', function () { $this->groupedValue = $this->servers; }); From eeec4cd320dc952ad3c643a482c497e23829c37c Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 00:13:48 +0000 Subject: [PATCH 11/32] More slight refinements, fixed unit test error --- Tests/ClientTest.php | 6 +++++- composer.json | 3 ++- src/APIClient.php | 5 +++++ src/Helpers/RequestHelper.php | 15 +++++++-------- src/Models/BanModel.php | 2 +- src/Models/GroupedModel.php | 4 ++-- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index 795718b..510afa0 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -32,6 +32,7 @@ public function __construct() /** * @throws \Exception + * @throws \Http\Client\Exception */ public function testPlayer(): void { @@ -39,13 +40,14 @@ public function testPlayer(): void $this->assertEquals($player->name, 'tuxytestaccount'); $this->assertEquals($player->groupID, 1); - $this->assertEquals($player->groupName, 'PlayerModel'); + $this->assertEquals($player->groupName, 'Player'); $this->assertInstanceOf(PlayerModel::class, $player); } /** * @throws \Exception + * @throws \Http\Client\Exception */ public function testPlayerBans(): void { @@ -61,6 +63,7 @@ public function testPlayerBans(): void /** * @throws \Exception + * @throws \Http\Client\Exception */ public function testServers(): void { @@ -71,6 +74,7 @@ public function testServers(): void /** * @throws \Exception + * @throws \Http\Client\Exception */ public function testVersion(): void { diff --git a/composer.json b/composer.json index 912eaed..2b742be 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,8 @@ "nesbot/carbon": "^1.21", "php-http/message": "^1.2", "guzzlehttp/psr7": "^1.3", - "leedavis81/vent": "dev-master" + "leedavis81/vent": "dev-master", + "ext-json": "*" }, "require-dev": { "phpunit/phpunit": "^5.3", diff --git a/src/APIClient.php b/src/APIClient.php index 2137c93..e4d0999 100644 --- a/src/APIClient.php +++ b/src/APIClient.php @@ -42,6 +42,7 @@ public function __construct(array $config = [], bool $secure = true) * * @param int $id * @throws \Exception + * @throws \Http\Client\Exception * @return \TruckersMP\Models\PlayerModel */ public function player(int $id): PlayerModel @@ -56,6 +57,7 @@ public function player(int $id): PlayerModel * * @param int $id * @throws \Exception + * @throws \Http\Client\Exception * @return \TruckersMP\Models\BansModel */ public function bans(int $id): BansModel @@ -69,6 +71,7 @@ public function bans(int $id): BansModel * Get server information. * * @throws \Exception + * @throws \Http\Client\Exception * @return \TruckersMP\Models\ServersModel */ public function servers(): ServersModel @@ -82,6 +85,7 @@ public function servers(): ServersModel * Get the current game time * * @throws \Exception + * @throws \Http\Client\Exception * @return \TruckersMP\Models\GameTimeModel */ public function gameTime(): GameTimeModel @@ -93,6 +97,7 @@ public function gameTime(): GameTimeModel /** * @throws \Exception + * @throws \Http\Client\Exception * @return \TruckersMP\Models\VersionModel */ public function version(): VersionModel diff --git a/src/Helpers/RequestHelper.php b/src/Helpers/RequestHelper.php index 8f6ba43..eebb70e 100644 --- a/src/Helpers/RequestHelper.php +++ b/src/Helpers/RequestHelper.php @@ -11,17 +11,17 @@ class RequestHelper /** * @var \Http\Message\MessageFactory\GuzzleMessageFactory */ - private $message; + protected $message; /** * @var string */ - private $apiEndpoint; + protected $apiEndpoint; /** * @var \Http\Adapter\Guzzle6\Client */ - private $adapter; + protected $adapter; /** * RequestHelper constructor. @@ -30,23 +30,22 @@ class RequestHelper * @param array $config * */ - public function __construct($apiEndpoint, $config) + public function __construct($apiEndpoint, array $config) { $this->message = new GuzzleMessageFactory(); - $this->apiEndpoint = $apiEndpoint; $this->adapter = new GuzzleAdapter(new GuzzleClient($config)); } /** * @param string $uri URI of API method - * * @return array + * @throws \Http\Client\Exception */ - public function execute($uri) + public function execute(string $uri): array { $request = $this->message->createRequest('GET', $this->apiEndpoint . $uri); - $result = $this->adapter->sendRequest($request); + $result = $this->adapter->sendRequest($request); return json_decode((string)$result->getBody(), true, 512, JSON_BIGINT_AS_STRING); } diff --git a/src/Models/BanModel.php b/src/Models/BanModel.php index 48eed86..10f154d 100644 --- a/src/Models/BanModel.php +++ b/src/Models/BanModel.php @@ -53,7 +53,7 @@ class BanModel * * @param array $ban */ - public function __construct($ban) + public function __construct(array $ban) { // Expiration if ($ban['expiration'] === null) { diff --git a/src/Models/GroupedModel.php b/src/Models/GroupedModel.php index e78afe8..9eea013 100644 --- a/src/Models/GroupedModel.php +++ b/src/Models/GroupedModel.php @@ -89,9 +89,9 @@ public function offsetUnset($offset): \Exception /** * @param mixed $offset - * @return bool|null + * @return mixed */ - public function offsetGet($offset): ?bool + public function offsetGet($offset) { return isset($this->groupedValue[$offset]) ? $this->groupedValue[$offset] : null; } From f9d41997b0a17d1983d2d680e9a67773d01a5b20 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 00:14:49 +0000 Subject: [PATCH 12/32] Updated unit tests --- Tests/ClientTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index 510afa0..9e268dc 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -3,12 +3,13 @@ namespace TruckersMP\Tests\API; use Carbon\Carbon; +use PHPUnit\Framework\TestCase; use TruckersMP\Helpers\APIClient; use TruckersMP\Models\BanModel; use TruckersMP\Models\BansModel; use TruckersMP\Models\PlayerModel; -class ClientTest extends \PHPUnit_Framework_TestCase +class ClientTest extends TestCase { /** * @var int @@ -95,6 +96,9 @@ public function testVersion(): void $this->assertNotEmpty($version->support->ats); } + /** + * @throws \Http\Client\Exception + */ public function testGameTime(): void { $time = $this->client->gameTime(); From ec26cc5edcc1a994f9d95c2130505691198365af Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 09:37:09 +0000 Subject: [PATCH 13/32] Switched to Client --- Tests/ClientTest.php | 8 ++++---- examples/cache/Laravel.php | 4 ++-- examples/cache/phpFastCache.php | 4 ++-- readme.md | 4 ++-- src/{APIClient.php => Client.php} | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) rename src/{APIClient.php => Client.php} (98%) diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index 9e268dc..d191484 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -4,7 +4,7 @@ use Carbon\Carbon; use PHPUnit\Framework\TestCase; -use TruckersMP\Helpers\APIClient; +use TruckersMP\Helpers\Client; use TruckersMP\Models\BanModel; use TruckersMP\Models\BansModel; use TruckersMP\Models\PlayerModel; @@ -17,7 +17,7 @@ class ClientTest extends TestCase protected $testAccount = 585204; /** - * @var APIClient + * @var Client */ protected $client; @@ -28,7 +28,7 @@ public function __construct() { parent::__construct(); - $this->client = new APIClient(); + $this->client = new Client(); } /** @@ -70,7 +70,7 @@ public function testServers(): void { $servers = $this->client->servers(); - $this->assertEquals($servers[0]->name, 'Europe 1'); + $this->assertEquals($servers[0]->name, 'Europe 1 [Simulation]'); } /** diff --git a/examples/cache/Laravel.php b/examples/cache/Laravel.php index 57a77cb..798b419 100644 --- a/examples/cache/Laravel.php +++ b/examples/cache/Laravel.php @@ -11,14 +11,14 @@ use App\Http\Requests; use Cache; use Illuminate\Http\Request; -use TruckersMP\Helpers\APIClient; +use TruckersMP\Helpers\Client; class SearchController extends Controller { public function find_user(Request $request) { - $client = new APIClient(); + $client = new Client(); $needle = $request->input('needle'); /** diff --git a/examples/cache/phpFastCache.php b/examples/cache/phpFastCache.php index be4784a..d07fd66 100644 --- a/examples/cache/phpFastCache.php +++ b/examples/cache/phpFastCache.php @@ -7,7 +7,7 @@ */ use phpFastCache\CacheManager; -use TruckersMP\Helpers\APIClient; +use TruckersMP\Helpers\Client; // Setup File Path on your config files CacheManager::setup([ @@ -17,7 +17,7 @@ // In your class, function, you can call the Cache $InstanceCache = CacheManager::getInstance('files'); -$client = new APIClient(); +$client = new Client(); /** * Try to get $products from Caching First diff --git a/readme.md b/readme.md index a8f0489..25870a2 100644 --- a/readme.md +++ b/readme.md @@ -39,9 +39,9 @@ After doing either of the above, execute the command `composer install`. ```php player(50); diff --git a/src/APIClient.php b/src/Client.php similarity index 98% rename from src/APIClient.php rename to src/Client.php index e4d0999..22fe2af 100644 --- a/src/APIClient.php +++ b/src/Client.php @@ -13,7 +13,7 @@ use TruckersMP\Models\ServersModel; use TruckersMP\Models\VersionModel; -class APIClient +class Client { const API_ENDPOINT = 'api.truckersmp.com'; const API_VERSION = 'v2'; @@ -24,7 +24,7 @@ class APIClient protected $request; /** - * APIClient constructor. + * Client constructor. * * @param array $config * @param bool $secure From 10fdccde61da09c02b962e4d97ebbb75cc9d7995 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 09:39:06 +0000 Subject: [PATCH 14/32] Switched GroupedModel to abstract class --- examples/cache/Laravel.php | 2 +- src/Client.php | 3 ++- src/Models/GroupedModel.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/cache/Laravel.php b/examples/cache/Laravel.php index 798b419..3c0f289 100644 --- a/examples/cache/Laravel.php +++ b/examples/cache/Laravel.php @@ -11,7 +11,7 @@ use App\Http\Requests; use Cache; use Illuminate\Http\Request; -use TruckersMP\Helpers\Client; +use TruckersMP\Client; class SearchController extends Controller { diff --git a/src/Client.php b/src/Client.php index 22fe2af..b6b039c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -5,8 +5,9 @@ * Website: truckersmp.com */ -namespace TruckersMP\Helpers; +namespace TruckersMP; +use TruckersMP\Helpers\RequestHelper; use TruckersMP\Models\BansModel; use TruckersMP\Models\GameTimeModel; use TruckersMP\Models\PlayerModel; diff --git a/src/Models/GroupedModel.php b/src/Models/GroupedModel.php index 9eea013..189511d 100644 --- a/src/Models/GroupedModel.php +++ b/src/Models/GroupedModel.php @@ -2,7 +2,7 @@ namespace TruckersMP\Models; -class GroupedModel implements \Iterator, \ArrayAccess +abstract class GroupedModel implements \Iterator, \ArrayAccess { /** * @var int From 0e10d77db62b0edba57dd48bd78836f8ad42c5a7 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 09:44:34 +0000 Subject: [PATCH 15/32] Call correct class in unit tests --- Tests/ClientTest.php | 2 +- examples/cache/phpFastCache.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index d191484..a2e0eb9 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -4,7 +4,7 @@ use Carbon\Carbon; use PHPUnit\Framework\TestCase; -use TruckersMP\Helpers\Client; +use TruckersMP\Client; use TruckersMP\Models\BanModel; use TruckersMP\Models\BansModel; use TruckersMP\Models\PlayerModel; diff --git a/examples/cache/phpFastCache.php b/examples/cache/phpFastCache.php index d07fd66..91d7df9 100644 --- a/examples/cache/phpFastCache.php +++ b/examples/cache/phpFastCache.php @@ -7,12 +7,12 @@ */ use phpFastCache\CacheManager; -use TruckersMP\Helpers\Client; +use TruckersMP\Client; // Setup File Path on your config files CacheManager::setup([ - "path" => '/path/to/your/cache/folder', - ]); + "path" => '/path/to/your/cache/folder', +]); // In your class, function, you can call the Cache $InstanceCache = CacheManager::getInstance('files'); From e891fb92fc8de0ec5450373730ac2daac67b3960 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 09:45:12 +0000 Subject: [PATCH 16/32] Removed more spacing --- examples/cache/phpFastCache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/cache/phpFastCache.php b/examples/cache/phpFastCache.php index 91d7df9..a84ae75 100644 --- a/examples/cache/phpFastCache.php +++ b/examples/cache/phpFastCache.php @@ -23,7 +23,7 @@ * Try to get $products from Caching First * product_page is "identity keyword"; */ -$key = "player_" . $player_id; +$key = "player_" . $player_id; $CachedRequest = $InstanceCache->getItem($key); if (is_null($CachedRequest->get())) { From 9e14c065e0830ca54b1b33c103de33ec6feeaff0 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 10:07:27 +0000 Subject: [PATCH 17/32] Switched example user to caf!!! to fix the erroring unit tests. --- Tests/ClientTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index a2e0eb9..e8b11ce 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -14,7 +14,7 @@ class ClientTest extends TestCase /** * @var int */ - protected $testAccount = 585204; + protected $testAccount = 162950; /** * @var Client @@ -39,7 +39,7 @@ public function testPlayer(): void { $player = $this->client->player($this->testAccount); - $this->assertEquals($player->name, 'tuxytestaccount'); + $this->assertEquals($player->name, 'caff!!!'); $this->assertEquals($player->groupID, 1); $this->assertEquals($player->groupName, 'Player'); @@ -54,9 +54,9 @@ public function testPlayerBans(): void { $bans = $this->client->bans($this->testAccount); - $this->assertEquals($bans[0]->expires, '2016-06-19 13:00:00'); - $this->assertEquals($bans[0]->created, '2016-06-19 10:08:26'); - $this->assertEquals($bans[0]->reason, 'Test ban'); + $this->assertEquals($bans[0]->expires, '2016-05-04 20:40:00'); + $this->assertEquals($bans[0]->created, '2016-05-03 20:41:40'); + $this->assertEquals($bans[0]->reason, 'Car carrying trailer - http://i.imgur.com/9MZ7DzC.jpg'); $this->assertInstanceOf(BansModel::class, $bans); $this->assertInstanceOf(BanModel::class, $bans[0]); From f9c618383c2edb332f6206eaac27165e75498144 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 11:11:12 +0000 Subject: [PATCH 18/32] Switched to PHPUnit 7 and updated Unit Tests to test the bans whether they're empty or not. --- Tests/ClientTest.php | 17 +- composer.json | 2 +- composer.lock | 967 ++++++++++++++++++++++++++++--------------- 3 files changed, 642 insertions(+), 344 deletions(-) diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index e8b11ce..31e370f 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -14,7 +14,7 @@ class ClientTest extends TestCase /** * @var int */ - protected $testAccount = 162950; + protected $testAccount = 585204; /** * @var Client @@ -39,7 +39,7 @@ public function testPlayer(): void { $player = $this->client->player($this->testAccount); - $this->assertEquals($player->name, 'caff!!!'); + $this->assertEquals($player->name, 'tuxytestaccount'); $this->assertEquals($player->groupID, 1); $this->assertEquals($player->groupName, 'Player'); @@ -54,12 +54,17 @@ public function testPlayerBans(): void { $bans = $this->client->bans($this->testAccount); - $this->assertEquals($bans[0]->expires, '2016-05-04 20:40:00'); - $this->assertEquals($bans[0]->created, '2016-05-03 20:41:40'); - $this->assertEquals($bans[0]->reason, 'Car carrying trailer - http://i.imgur.com/9MZ7DzC.jpg'); + if (count($bans->bans) > 0) { + $this->assertEquals(gettype($bans[0]->expires), 'string'); + $this->assertEquals(gettype($bans[0]->expires), 'string'); + $this->assertEquals(gettype($bans[0]->expires), 'string'); + + $this->assertInstanceOf(BanModel::class, $bans[0]); + } else { + $this->assertEquals($bans->bans, []); + } $this->assertInstanceOf(BansModel::class, $bans); - $this->assertInstanceOf(BanModel::class, $bans[0]); } /** diff --git a/composer.json b/composer.json index 2b742be..d87eb5c 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": "^5.3", + "phpunit/phpunit": "^7.0", "squizlabs/php_codesniffer": "^2.6", "php-http/guzzle6-adapter": "^1.0" }, diff --git a/composer.lock b/composer.lock index dc03677..bdc2adb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,25 +4,28 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8a5cead4663ab9dc6e9927dad2e85941", + "content-hash": "63c614b6973ce1d74728010a9497b41b", "packages": [ { "name": "clue/stream-filter", - "version": "v1.3.0", + "version": "v1.4.0", "source": { "type": "git", "url": "https://github.com/clue/php-stream-filter.git", - "reference": "e3bf9415da163d9ad6701dccb407ed501ae69785" + "reference": "d80fdee9b3a7e0d16fc330a22f41f3ad0eeb09d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/clue/php-stream-filter/zipball/e3bf9415da163d9ad6701dccb407ed501ae69785", - "reference": "e3bf9415da163d9ad6701dccb407ed501ae69785", + "url": "https://api.github.com/repos/clue/php-stream-filter/zipball/d80fdee9b3a7e0d16fc330a22f41f3ad0eeb09d0", + "reference": "d80fdee9b3a7e0d16fc330a22f41f3ad0eeb09d0", "shasum": "" }, "require": { "php": ">=5.3" }, + "require-dev": { + "phpunit/phpunit": "^5.0 || ^4.8" + }, "type": "library", "autoload": { "psr-4": { @@ -53,36 +56,37 @@ "stream_filter_append", "stream_filter_register" ], - "time": "2015-11-08T23:41:30+00:00" + "time": "2017-08-18T09:54:01+00:00" }, { "name": "guzzlehttp/psr7", - "version": "1.4.2", + "version": "1.5.2", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" + "reference": "9f83dded91781a01c63574e387eaa769be769115" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/9f83dded91781a01c63574e387eaa769be769115", + "reference": "9f83dded91781a01c63574e387eaa769be769115", "shasum": "" }, "require": { "php": ">=5.4.0", - "psr/http-message": "~1.0" + "psr/http-message": "~1.0", + "ralouphie/getallheaders": "^2.0.5" }, "provide": { "psr/http-message-implementation": "1.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "1.5-dev" } }, "autoload": { @@ -112,13 +116,14 @@ "keywords": [ "http", "message", + "psr-7", "request", "response", "stream", "uri", "url" ], - "time": "2017-03-20T17:10:46+00:00" + "time": "2018-12-04T20:46:45+00:00" }, { "name": "leedavis81/vent", @@ -170,35 +175,40 @@ }, { "name": "nesbot/carbon", - "version": "1.22.1", + "version": "1.36.2", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc" + "reference": "cd324b98bc30290f233dd0e75e6ce49f7ab2a6c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc", - "reference": "7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/cd324b98bc30290f233dd0e75e6ce49f7ab2a6c9", + "reference": "cd324b98bc30290f233dd0e75e6ce49f7ab2a6c9", "shasum": "" }, "require": { - "php": ">=5.3.0", - "symfony/translation": "~2.6 || ~3.0" + "php": ">=5.3.9", + "symfony/translation": "~2.6 || ~3.0 || ~4.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "~2", - "phpunit/phpunit": "~4.0 || ~5.0" + "phpunit/phpunit": "^4.8.35 || ^5.7" + }, + "suggest": { + "friendsofphp/php-cs-fixer": "Needed for the `composer phpcs` command. Allow to automatically fix code style.", + "phpstan/phpstan": "Needed for the `composer phpstan` command. Allow to detect potential errors." }, "type": "library", "extra": { - "branch-alias": { - "dev-master": "1.23-dev" + "laravel": { + "providers": [ + "Carbon\\Laravel\\ServiceProvider" + ] } }, "autoload": { "psr-4": { - "Carbon\\": "src/Carbon/" + "": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -219,28 +229,31 @@ "datetime", "time" ], - "time": "2017-01-16T07:55:07+00:00" + "time": "2018-12-28T10:07:33+00:00" }, { "name": "php-http/message", - "version": "1.5.0", + "version": "1.7.2", "source": { "type": "git", "url": "https://github.com/php-http/message.git", - "reference": "13df8c48f40ca7925303aa336f19be4b80984f01" + "reference": "b159ffe570dffd335e22ef0b91a946eacb182fa1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-http/message/zipball/13df8c48f40ca7925303aa336f19be4b80984f01", - "reference": "13df8c48f40ca7925303aa336f19be4b80984f01", + "url": "https://api.github.com/repos/php-http/message/zipball/b159ffe570dffd335e22ef0b91a946eacb182fa1", + "reference": "b159ffe570dffd335e22ef0b91a946eacb182fa1", "shasum": "" }, "require": { - "clue/stream-filter": "^1.3", - "php": ">=5.4", + "clue/stream-filter": "^1.4", + "php": "^5.4 || ^7.0", "php-http/message-factory": "^1.0.2", "psr/http-message": "^1.0" }, + "provide": { + "php-http/message-factory-implementation": "1.0" + }, "require-dev": { "akeneo/phpspec-skip-example-extension": "^1.0", "coduo/phpspec-data-provider-extension": "^1.0", @@ -288,7 +301,7 @@ "message", "psr-7" ], - "time": "2017-02-14T08:58:37+00:00" + "time": "2018-11-01T09:32:41+00:00" }, { "name": "php-http/message-factory", @@ -390,18 +403,126 @@ ], "time": "2016-08-06T14:39:51+00:00" }, + { + "name": "ralouphie/getallheaders", + "version": "2.0.5", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/5601c8a83fbba7ef674a7369456d12f1e0d0eafa", + "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "phpunit/phpunit": "~3.7.0", + "satooshi/php-coveralls": ">=1.0" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "time": "2016-02-11T07:05:27+00:00" + }, + { + "name": "symfony/contracts", + "version": "v1.0.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/contracts.git", + "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/contracts/zipball/1aa7ab2429c3d594dd70689604b5cf7421254cdf", + "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "require-dev": { + "psr/cache": "^1.0", + "psr/container": "^1.0" + }, + "suggest": { + "psr/cache": "When using the Cache contracts", + "psr/container": "When using the Service contracts", + "symfony/cache-contracts-implementation": "", + "symfony/service-contracts-implementation": "", + "symfony/translation-contracts-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\": "" + }, + "exclude-from-classmap": [ + "**/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A set of abstractions extracted out of the Symfony components", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "time": "2018-12-05T08:06:11+00:00" + }, { "name": "symfony/polyfill-mbstring", - "version": "v1.3.0", + "version": "v1.11.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4" + "reference": "fe5e94c604826c35a32fa832f35bd036b6799609" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/e79d363049d1c2128f133a2667e4f4190904f7f4", - "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fe5e94c604826c35a32fa832f35bd036b6799609", + "reference": "fe5e94c604826c35a32fa832f35bd036b6799609", "shasum": "" }, "require": { @@ -413,7 +534,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "1.11-dev" } }, "autoload": { @@ -447,44 +568,53 @@ "portable", "shim" ], - "time": "2016-11-14T01:06:16+00:00" + "time": "2019-02-06T07:57:58+00:00" }, { "name": "symfony/translation", - "version": "v3.2.7", + "version": "v4.2.4", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "c740eee70783d2af4d3d6b70d5146f209e6b4d13" + "reference": "748464177a77011f8f4cdd076773862ce4915f8f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/c740eee70783d2af4d3d6b70d5146f209e6b4d13", - "reference": "c740eee70783d2af4d3d6b70d5146f209e6b4d13", + "url": "https://api.github.com/repos/symfony/translation/zipball/748464177a77011f8f4cdd076773862ce4915f8f", + "reference": "748464177a77011f8f4cdd076773862ce4915f8f", "shasum": "" }, "require": { - "php": ">=5.5.9", + "php": "^7.1.3", + "symfony/contracts": "^1.0.2", "symfony/polyfill-mbstring": "~1.0" }, "conflict": { - "symfony/config": "<2.8" + "symfony/config": "<3.4", + "symfony/dependency-injection": "<3.4", + "symfony/yaml": "<3.4" + }, + "provide": { + "symfony/translation-contracts-implementation": "1.0" }, "require-dev": { "psr/log": "~1.0", - "symfony/config": "~2.8|~3.0", - "symfony/intl": "^2.8.18|^3.2.5", - "symfony/yaml": "~2.8|~3.0" + "symfony/config": "~3.4|~4.0", + "symfony/console": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/finder": "~2.8|~3.0|~4.0", + "symfony/intl": "~3.4|~4.0", + "symfony/yaml": "~3.4|~4.0" }, "suggest": { - "psr/log": "To use logging capability in translator", + "psr/log-implementation": "To use logging capability in translator", "symfony/config": "", "symfony/yaml": "" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.2-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -511,38 +641,40 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2017-03-21T21:44:32+00:00" + "time": "2019-02-27T03:31:50+00:00" } ], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.0.5", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + "reference": "a2c590166b2133a4633738648b6b064edae0814a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", + "reference": "a2c590166b2133a4633738648b6b064edae0814a", "shasum": "" }, "require": { - "php": ">=5.3,<8.0-DEV" + "php": "^7.1" }, "require-dev": { - "athletic/athletic": "~0.1.8", + "doctrine/coding-standard": "^6.0", "ext-pdo": "*", "ext-phar": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~2.0" + "phpbench/phpbench": "^0.13", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-shim": "^0.11", + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.2.x-dev" } }, "autoload": { @@ -562,25 +694,25 @@ } ], "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://github.com/doctrine/instantiator", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", "keywords": [ "constructor", "instantiate" ], - "time": "2015-06-14T21:17:01+00:00" + "time": "2019-03-17T17:37:11+00:00" }, { "name": "guzzlehttp/guzzle", - "version": "6.2.3", + "version": "6.3.3", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006" + "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/8d6c6cc55186db87b7dc5009827429ba4e9dc006", - "reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", + "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", "shasum": "" }, "require": { @@ -590,13 +722,16 @@ }, "require-dev": { "ext-curl": "*", - "phpunit/phpunit": "^4.0", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", "psr/log": "^1.0" }, + "suggest": { + "psr/log": "Required for using the Log middleware" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "6.2-dev" + "dev-master": "6.3-dev" } }, "autoload": { @@ -629,7 +764,7 @@ "rest", "web service" ], - "time": "2017-02-28T22:50:30+00:00" + "time": "2018-04-22T15:46:56+00:00" }, { "name": "guzzlehttp/promises", @@ -684,37 +819,43 @@ }, { "name": "myclabs/deep-copy", - "version": "1.6.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "5a5a9fc8025a08d8919be87d6884d5a92520cefe" + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/5a5a9fc8025a08d8919be87d6884d5a92520cefe", - "reference": "5a5a9fc8025a08d8919be87d6884d5a92520cefe", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", "shasum": "" }, "require": { - "php": ">=5.4.0" + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" }, "require-dev": { - "doctrine/collections": "1.*", - "phpunit/phpunit": "~4.1" + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^7.1" }, "type": "library", "autoload": { "psr-4": { "DeepCopy\\": "src/DeepCopy/" - } + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "description": "Create deep copies (clones) of your objects", - "homepage": "https://github.com/myclabs/DeepCopy", "keywords": [ "clone", "copy", @@ -722,7 +863,109 @@ "object", "object graph" ], - "time": "2017-01-26T22:05:40+00:00" + "time": "2018-06-11T23:09:50+00:00" + }, + { + "name": "phar-io/manifest", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "phar-io/version": "^2.0", + "php": "^5.6 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "time": "2018-07-08T19:23:20+00:00" + }, + { + "name": "phar-io/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "time": "2018-07-08T19:19:57+00:00" }, { "name": "php-http/guzzle6-adapter", @@ -892,16 +1135,16 @@ }, { "name": "phpdocumentor/reflection-common", - "version": "1.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", - "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", "shasum": "" }, "require": { @@ -942,33 +1185,39 @@ "reflection", "static analysis" ], - "time": "2015-12-27T11:43:31+00:00" + "time": "2017-09-11T18:02:19+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "3.1.1", + "version": "4.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e" + "reference": "94fd0001232e47129dd3504189fa1c7225010d08" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e", - "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08", "shasum": "" }, "require": { - "php": ">=5.5", - "phpdocumentor/reflection-common": "^1.0@dev", - "phpdocumentor/type-resolver": "^0.2.0", + "php": "^7.0", + "phpdocumentor/reflection-common": "^1.0.0", + "phpdocumentor/type-resolver": "^0.4.0", "webmozart/assert": "^1.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.4" + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, "autoload": { "psr-4": { "phpDocumentor\\Reflection\\": [ @@ -987,24 +1236,24 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2016-09-30T07:12:33+00:00" + "time": "2017-11-30T07:14:17+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "0.2.1", + "version": "0.4.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb" + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", - "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", "shasum": "" }, "require": { - "php": ">=5.5", + "php": "^5.5 || ^7.0", "phpdocumentor/reflection-common": "^1.0" }, "require-dev": { @@ -1034,37 +1283,37 @@ "email": "me@mikevanriel.com" } ], - "time": "2016-11-25T06:54:22+00:00" + "time": "2017-07-14T14:27:02+00:00" }, { "name": "phpspec/prophecy", - "version": "v1.7.0", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "93d39f1f7f9326d746203c7c056f300f7f126073" + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/93d39f1f7f9326d746203c7c056f300f7f126073", - "reference": "93d39f1f7f9326d746203c7c056f300f7f126073", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", - "sebastian/comparator": "^1.1|^2.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8 || ^5.6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6.x-dev" + "dev-master": "1.8.x-dev" } }, "autoload": { @@ -1097,44 +1346,44 @@ "spy", "stub" ], - "time": "2017-03-02T20:05:34+00:00" + "time": "2018-08-05T17:53:17+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "4.0.8", + "version": "6.1.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d" + "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef7b2f56815df854e66ceaee8ebe9393ae36a40d", - "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", + "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", - "php": "^5.6 || ^7.0", - "phpunit/php-file-iterator": "^1.3", - "phpunit/php-text-template": "^1.2", - "phpunit/php-token-stream": "^1.4.2 || ^2.0", - "sebastian/code-unit-reverse-lookup": "^1.0", - "sebastian/environment": "^1.3.2 || ^2.0", - "sebastian/version": "^1.0 || ^2.0" + "php": "^7.1", + "phpunit/php-file-iterator": "^2.0", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-token-stream": "^3.0", + "sebastian/code-unit-reverse-lookup": "^1.0.1", + "sebastian/environment": "^3.1 || ^4.0", + "sebastian/version": "^2.0.1", + "theseer/tokenizer": "^1.1" }, "require-dev": { - "ext-xdebug": "^2.1.4", - "phpunit/phpunit": "^5.7" + "phpunit/phpunit": "^7.0" }, "suggest": { - "ext-xdebug": "^2.5.1" + "ext-xdebug": "^2.6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0.x-dev" + "dev-master": "6.1-dev" } }, "autoload": { @@ -1149,7 +1398,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1160,29 +1409,32 @@ "testing", "xunit" ], - "time": "2017-04-02T07:44:40+00:00" + "time": "2018-10-31T16:06:48+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.2", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + "reference": "050bedf145a257b1ff02746c31894800e5122946" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/050bedf145a257b1ff02746c31894800e5122946", + "reference": "050bedf145a257b1ff02746c31894800e5122946", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1197,7 +1449,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1207,7 +1459,7 @@ "filesystem", "iterator" ], - "time": "2016-10-03T07:40:28+00:00" + "time": "2018-09-13T20:33:42+00:00" }, { "name": "phpunit/php-text-template", @@ -1252,28 +1504,28 @@ }, { "name": "phpunit/php-timer", - "version": "1.0.9", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b389aebe1b8b0578430bda0c7c95a829608e059", + "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.1-dev" } }, "autoload": { @@ -1288,7 +1540,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1297,33 +1549,33 @@ "keywords": [ "timer" ], - "time": "2017-02-26T11:10:40+00:00" + "time": "2019-02-20T10:12:59+00:00" }, { "name": "phpunit/php-token-stream", - "version": "1.4.11", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7" + "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7", - "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c99e3be9d3e85f60646f152f9002d46ed7770d18", + "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": ">=5.3.3" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1346,55 +1598,57 @@ "keywords": [ "tokenizer" ], - "time": "2017-02-27T10:12:30+00:00" + "time": "2018-10-30T05:52:18+00:00" }, { "name": "phpunit/phpunit", - "version": "5.7.19", + "version": "7.5.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "69c4f49ff376af2692bad9cebd883d17ebaa98a1" + "reference": "c29c0525cf4572c11efe1db49a8b8aee9dfac58a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/69c4f49ff376af2692bad9cebd883d17ebaa98a1", - "reference": "69c4f49ff376af2692bad9cebd883d17ebaa98a1", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c29c0525cf4572c11efe1db49a8b8aee9dfac58a", + "reference": "c29c0525cf4572c11efe1db49a8b8aee9dfac58a", "shasum": "" }, "require": { + "doctrine/instantiator": "^1.1", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", - "myclabs/deep-copy": "~1.3", - "php": "^5.6 || ^7.0", - "phpspec/prophecy": "^1.6.2", - "phpunit/php-code-coverage": "^4.0.4", - "phpunit/php-file-iterator": "~1.4", - "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "^1.0.6", - "phpunit/phpunit-mock-objects": "^3.2", - "sebastian/comparator": "^1.2.4", - "sebastian/diff": "~1.2", - "sebastian/environment": "^1.3.4 || ^2.0", - "sebastian/exporter": "~2.0", - "sebastian/global-state": "^1.1", - "sebastian/object-enumerator": "~2.0", - "sebastian/resource-operations": "~1.0", - "sebastian/version": "~1.0.3|~2.0", - "symfony/yaml": "~2.1|~3.0" + "myclabs/deep-copy": "^1.7", + "phar-io/manifest": "^1.0.2", + "phar-io/version": "^2.0", + "php": "^7.1", + "phpspec/prophecy": "^1.7", + "phpunit/php-code-coverage": "^6.0.7", + "phpunit/php-file-iterator": "^2.0.1", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-timer": "^2.1", + "sebastian/comparator": "^3.0", + "sebastian/diff": "^3.0", + "sebastian/environment": "^4.0", + "sebastian/exporter": "^3.1", + "sebastian/global-state": "^2.0", + "sebastian/object-enumerator": "^3.0.3", + "sebastian/resource-operations": "^2.0", + "sebastian/version": "^2.0.1" }, "conflict": { - "phpdocumentor/reflection-docblock": "3.0.2" + "phpunit/phpunit-mock-objects": "*" }, "require-dev": { "ext-pdo": "*" }, "suggest": { + "ext-soap": "*", "ext-xdebug": "*", - "phpunit/php-invoker": "~1.1" + "phpunit/php-invoker": "^2.0" }, "bin": [ "phpunit" @@ -1402,7 +1656,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.7.x-dev" + "dev-master": "7.5-dev" } }, "autoload": { @@ -1428,66 +1682,7 @@ "testing", "xunit" ], - "time": "2017-04-03T02:22:27+00:00" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "3.4.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "3ab72b65b39b491e0c011e2e09bb2206c2aa8e24" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/3ab72b65b39b491e0c011e2e09bb2206c2aa8e24", - "reference": "3ab72b65b39b491e0c011e2e09bb2206c2aa8e24", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.2", - "php": "^5.6 || ^7.0", - "phpunit/php-text-template": "^1.2", - "sebastian/exporter": "^1.2 || ^2.0" - }, - "conflict": { - "phpunit/phpunit": "<5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "^5.4" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "time": "2016-12-08T20:27:08+00:00" + "time": "2019-03-26T13:23:54+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -1536,30 +1731,30 @@ }, { "name": "sebastian/comparator", - "version": "1.2.4", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", - "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", "shasum": "" }, "require": { - "php": ">=5.3.3", - "sebastian/diff": "~1.2", - "sebastian/exporter": "~1.2 || ~2.0" + "php": "^7.1", + "sebastian/diff": "^3.0", + "sebastian/exporter": "^3.1" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1590,38 +1785,39 @@ } ], "description": "Provides the functionality to compare PHP values for equality", - "homepage": "http://www.github.com/sebastianbergmann/comparator", + "homepage": "https://github.com/sebastianbergmann/comparator", "keywords": [ "comparator", "compare", "equality" ], - "time": "2017-01-29T09:50:25+00:00" + "time": "2018-07-12T15:12:46+00:00" }, { "name": "sebastian/diff", - "version": "1.4.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", - "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "~4.8" + "phpunit/phpunit": "^7.5 || ^8.0", + "symfony/process": "^2 || ^3.3 || ^4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1646,34 +1842,40 @@ "description": "Diff implementation", "homepage": "https://github.com/sebastianbergmann/diff", "keywords": [ - "diff" + "diff", + "udiff", + "unidiff", + "unified diff" ], - "time": "2015-12-08T07:14:41+00:00" + "time": "2019-02-04T06:01:07+00:00" }, { "name": "sebastian/environment", - "version": "2.0.0", + "version": "4.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" + "reference": "6fda8ce1974b62b14935adc02a9ed38252eca656" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", - "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6fda8ce1974b62b14935adc02a9ed38252eca656", + "reference": "6fda8ce1974b62b14935adc02a9ed38252eca656", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^5.0" + "phpunit/phpunit": "^7.5" + }, + "suggest": { + "ext-posix": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -1698,34 +1900,34 @@ "environment", "hhvm" ], - "time": "2016-11-26T07:53:53+00:00" + "time": "2019-02-01T05:27:49+00:00" }, { "name": "sebastian/exporter", - "version": "2.0.0", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", - "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937", + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937", "shasum": "" }, "require": { - "php": ">=5.3.3", - "sebastian/recursion-context": "~2.0" + "php": "^7.0", + "sebastian/recursion-context": "^3.0" }, "require-dev": { "ext-mbstring": "*", - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.1.x-dev" } }, "autoload": { @@ -1765,27 +1967,27 @@ "export", "exporter" ], - "time": "2016-11-19T08:54:04+00:00" + "time": "2017-04-03T13:19:02+00:00" }, { "name": "sebastian/global-state", - "version": "1.1.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "^6.0" }, "suggest": { "ext-uopz": "*" @@ -1793,7 +1995,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1816,33 +2018,34 @@ "keywords": [ "global state" ], - "time": "2015-10-12T03:26:01+00:00" + "time": "2017-04-27T15:39:26+00:00" }, { "name": "sebastian/object-enumerator", - "version": "2.0.1", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7" + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/1311872ac850040a79c3c058bea3e22d0f09cbb7", - "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", "shasum": "" }, "require": { - "php": ">=5.6", - "sebastian/recursion-context": "~2.0" + "php": "^7.0", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" }, "require-dev": { - "phpunit/phpunit": "~5" + "phpunit/phpunit": "^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0.x-dev" } }, "autoload": { @@ -1862,32 +2065,77 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-02-18T15:18:39+00:00" + "time": "2017-08-03T12:35:26+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "773f97c67f28de00d397be301821b06708fca0be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", + "reference": "773f97c67f28de00d397be301821b06708fca0be", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "time": "2017-03-29T09:07:27+00:00" }, { "name": "sebastian/recursion-context", - "version": "2.0.0", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", - "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0.x-dev" } }, "autoload": { @@ -1915,29 +2163,29 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2016-11-19T07:33:16+00:00" + "time": "2017-03-03T06:23:57+00:00" }, { "name": "sebastian/resource-operations", - "version": "1.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9", "shasum": "" }, "require": { - "php": ">=5.6.0" + "php": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1957,7 +2205,7 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2015-07-28T20:34:47+00:00" + "time": "2018-10-04T04:07:39+00:00" }, { "name": "sebastian/version", @@ -2004,16 +2252,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "2.8.1", + "version": "2.9.2", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "d7cf0d894e8aa4c73712ee4a331cc1eaa37cdc7d" + "reference": "2acf168de78487db620ab4bc524135a13cfe6745" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/d7cf0d894e8aa4c73712ee4a331cc1eaa37cdc7d", - "reference": "d7cf0d894e8aa4c73712ee4a331cc1eaa37cdc7d", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/2acf168de78487db620ab4bc524135a13cfe6745", + "reference": "2acf168de78487db620ab4bc524135a13cfe6745", "shasum": "" }, "require": { @@ -2078,43 +2326,40 @@ "phpcs", "standards" ], - "time": "2017-03-01T22:17:45+00:00" + "time": "2018-11-07T22:31:41+00:00" }, { - "name": "symfony/yaml", - "version": "v3.2.7", + "name": "symfony/polyfill-ctype", + "version": "v1.11.0", "source": { "type": "git", - "url": "https://github.com/symfony/yaml.git", - "reference": "62b4cdb99d52cb1ff253c465eb1532a80cebb621" + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "82ebae02209c21113908c229e9883c419720738a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/62b4cdb99d52cb1ff253c465eb1532a80cebb621", - "reference": "62b4cdb99d52cb1ff253c465eb1532a80cebb621", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", + "reference": "82ebae02209c21113908c229e9883c419720738a", "shasum": "" }, "require": { - "php": ">=5.5.9" - }, - "require-dev": { - "symfony/console": "~2.8|~3.0" + "php": ">=5.3.3" }, "suggest": { - "symfony/console": "For validating YAML files using the lint command" + "ext-ctype": "For best performance" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.2-dev" + "dev-master": "1.11-dev" } }, "autoload": { "psr-4": { - "Symfony\\Component\\Yaml\\": "" + "Symfony\\Polyfill\\Ctype\\": "" }, - "exclude-from-classmap": [ - "/Tests/" + "files": [ + "bootstrap.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -2122,35 +2367,82 @@ "MIT" ], "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "backendtea@gmail.com" } ], - "description": "Symfony Yaml Component", + "description": "Symfony polyfill for ctype functions", "homepage": "https://symfony.com", - "time": "2017-03-20T09:45:15+00:00" + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2019-02-06T07:57:58+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "time": "2017-04-07T12:08:54+00:00" }, { "name": "webmozart/assert", - "version": "1.2.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", - "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", + "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" }, "require-dev": { "phpunit/phpunit": "^4.6", @@ -2183,7 +2475,7 @@ "check", "validate" ], - "time": "2016-11-23T20:04:58+00:00" + "time": "2018-12-25T11:19:39+00:00" } ], "aliases": [], @@ -2194,7 +2486,8 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.1.0" + "php": ">=7.1.0", + "ext-json": "*" }, "platform-dev": [] } From d60debaf2bddf0fc68ed130323284b54a0bd990b Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 11:12:16 +0000 Subject: [PATCH 19/32] Added deprecated tag to the version function --- src/Client.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Client.php b/src/Client.php index b6b039c..1fc56ca 100644 --- a/src/Client.php +++ b/src/Client.php @@ -97,6 +97,8 @@ public function gameTime(): GameTimeModel } /** + * @deprecated + * * @throws \Exception * @throws \Http\Client\Exception * @return \TruckersMP\Models\VersionModel From d13fc7a443d8b9489b250384eb8230d9403f3273 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 11:18:11 +0000 Subject: [PATCH 20/32] Added Rules endpoint. --- src/Client.php | 28 ++++++++++++++++++++++++++++ src/Models/RulesModel.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/Models/RulesModel.php diff --git a/src/Client.php b/src/Client.php index 1fc56ca..c3af44f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -11,6 +11,7 @@ use TruckersMP\Models\BansModel; use TruckersMP\Models\GameTimeModel; use TruckersMP\Models\PlayerModel; +use TruckersMP\Models\RulesModel; use TruckersMP\Models\ServersModel; use TruckersMP\Models\VersionModel; @@ -41,6 +42,8 @@ public function __construct(array $config = [], bool $secure = true) /** * Get player information by ID. * + * https://stats.truckersmp.com/api#players_lookup + * * @param int $id * @throws \Exception * @throws \Http\Client\Exception @@ -56,6 +59,8 @@ public function player(int $id): PlayerModel /** * Get bans information by player ID. * + * https://stats.truckersmp.com/api#ban_lookup + * * @param int $id * @throws \Exception * @throws \Http\Client\Exception @@ -71,6 +76,8 @@ public function bans(int $id): BansModel /** * Get server information. * + * https://stats.truckersmp.com/api#servers_list + * * @throws \Exception * @throws \Http\Client\Exception * @return \TruckersMP\Models\ServersModel @@ -85,6 +92,8 @@ public function servers(): ServersModel /** * Get the current game time * + * https://stats.truckersmp.com/api#game_time + * * @throws \Exception * @throws \Http\Client\Exception * @return \TruckersMP\Models\GameTimeModel @@ -99,6 +108,10 @@ public function gameTime(): GameTimeModel /** * @deprecated * + * Information about the current TruckersMP version for ETS2 and ATS + * + * https://stats.truckersmp.com/api#truckersmp_version + * * @throws \Exception * @throws \Http\Client\Exception * @return \TruckersMP\Models\VersionModel @@ -109,4 +122,19 @@ public function version(): VersionModel return new VersionModel($result); } + + /** + * Get the current in-game rules. + * + * https://stats.truckersmp.com/api#truckersmp_rules + * + * @return RulesModel + * @throws \Http\Client\Exception + */ + public function rules(): RulesModel + { + $result = $this->request->execute('rules'); + + return new RulesModel($result); + } } diff --git a/src/Models/RulesModel.php b/src/Models/RulesModel.php new file mode 100644 index 0000000..fe12f96 --- /dev/null +++ b/src/Models/RulesModel.php @@ -0,0 +1,31 @@ +rules = $response['response']['rules']; + $this->revision = $response['response']['revision']; + } +} From 48e88e1ee28dade8a12ec87be734377bc695f4be Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 11:20:29 +0000 Subject: [PATCH 21/32] Fixed rules. --- src/Models/RulesModel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Models/RulesModel.php b/src/Models/RulesModel.php index fe12f96..0b662c9 100644 --- a/src/Models/RulesModel.php +++ b/src/Models/RulesModel.php @@ -25,7 +25,7 @@ class RulesModel */ public function __construct(array $response) { - $this->rules = $response['response']['rules']; - $this->revision = $response['response']['revision']; + $this->rules = $response['rules']; + $this->revision = $response['revision']; } } From 195f0d50c91146756dc13b007914e1d98ac5ada4 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 11:22:12 +0000 Subject: [PATCH 22/32] Altered client, fixed rules. --- src/Client.php | 15 ++++++++------- src/Models/RulesModel.php | 7 +++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Client.php b/src/Client.php index c3af44f..e362593 100644 --- a/src/Client.php +++ b/src/Client.php @@ -21,7 +21,7 @@ class Client const API_VERSION = 'v2'; /** - * @var \TruckersMP\Helpers\RequestHelper + * @var RequestHelper */ protected $request; @@ -47,7 +47,7 @@ public function __construct(array $config = [], bool $secure = true) * @param int $id * @throws \Exception * @throws \Http\Client\Exception - * @return \TruckersMP\Models\PlayerModel + * @return PlayerModel */ public function player(int $id): PlayerModel { @@ -64,7 +64,7 @@ public function player(int $id): PlayerModel * @param int $id * @throws \Exception * @throws \Http\Client\Exception - * @return \TruckersMP\Models\BansModel + * @return BansModel */ public function bans(int $id): BansModel { @@ -80,7 +80,7 @@ public function bans(int $id): BansModel * * @throws \Exception * @throws \Http\Client\Exception - * @return \TruckersMP\Models\ServersModel + * @return ServersModel */ public function servers(): ServersModel { @@ -96,7 +96,7 @@ public function servers(): ServersModel * * @throws \Exception * @throws \Http\Client\Exception - * @return \TruckersMP\Models\GameTimeModel + * @return GameTimeModel */ public function gameTime(): GameTimeModel { @@ -114,7 +114,7 @@ public function gameTime(): GameTimeModel * * @throws \Exception * @throws \Http\Client\Exception - * @return \TruckersMP\Models\VersionModel + * @return VersionModel */ public function version(): VersionModel { @@ -128,8 +128,9 @@ public function version(): VersionModel * * https://stats.truckersmp.com/api#truckersmp_rules * - * @return RulesModel * @throws \Http\Client\Exception + * @throws Exceptions\APIErrorException + * @return RulesModel */ public function rules(): RulesModel { diff --git a/src/Models/RulesModel.php b/src/Models/RulesModel.php index 0b662c9..eec658a 100644 --- a/src/Models/RulesModel.php +++ b/src/Models/RulesModel.php @@ -2,6 +2,8 @@ namespace TruckersMP\Models; +use TruckersMP\Exceptions\APIErrorException; + class RulesModel { /** @@ -22,9 +24,14 @@ class RulesModel * RulesModel constructor. * * @param array $response + * @throws APIErrorException */ public function __construct(array $response) { + if ($response['error']) { + throw new APIErrorException('There was an error fetching the rules.'); + } + $this->rules = $response['rules']; $this->revision = $response['revision']; } From baeb46d20fa469495ad9383fb3e725f44821d0c1 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 11:26:35 +0000 Subject: [PATCH 23/32] Updated unit tests to include rules model and added some more assertions --- Tests/ClientTest.php | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index 31e370f..8a8de9c 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -7,7 +7,9 @@ use TruckersMP\Client; use TruckersMP\Models\BanModel; use TruckersMP\Models\BansModel; +use TruckersMP\Models\GameTimeModel; use TruckersMP\Models\PlayerModel; +use TruckersMP\Models\RulesModel; class ClientTest extends TestCase { @@ -52,12 +54,15 @@ public function testPlayer(): void */ public function testPlayerBans(): void { + /** + * @var $bans BanModel[] + */ $bans = $this->client->bans($this->testAccount); if (count($bans->bans) > 0) { - $this->assertEquals(gettype($bans[0]->expires), 'string'); - $this->assertEquals(gettype($bans[0]->expires), 'string'); - $this->assertEquals(gettype($bans[0]->expires), 'string'); + $this->assertTrue(is_string($bans[0]->created)); + $this->assertTrue(is_string($bans[0]->expires)); + $this->assertTrue(is_string($bans[0]->reason)); $this->assertInstanceOf(BanModel::class, $bans[0]); } else { @@ -109,5 +114,23 @@ public function testGameTime(): void $time = $this->client->gameTime(); $this->assertNotEmpty($time); + + $this->assertInstanceOf(Carbon::class, $time->time); + + $this->assertInstanceOf(GameTimeModel::class, $time); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\APIErrorException + */ + public function testRules(): void + { + $rules = $this->client->rules(); + + $this->assertTrue(is_string($rules->rules)); + $this->assertTrue(is_int($rules->revision)); + + $this->assertInstanceOf(RulesModel::class, $rules); } } From 059bb93a2687862f06b2cc151f25dd24c42463f7 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 13:07:57 +0000 Subject: [PATCH 24/32] Switched to using getters and setters to remove unstable dependency. --- src/Models/BanModel.php | 70 +++++++++++-- src/Models/BansModel.php | 25 ++--- src/Models/GameTimeModel.php | 10 +- src/Models/PlayerModel.php | 98 +++++++++++++++--- src/Models/RulesModel.php | 20 +++- src/Models/ServerModel.php | 192 +++++++++++++++++++++++++++++------ src/Models/ServersModel.php | 25 ++--- src/Models/VersionModel.php | 57 ++++++++--- 8 files changed, 390 insertions(+), 107 deletions(-) diff --git a/src/Models/BanModel.php b/src/Models/BanModel.php index 10f154d..e3ad6f4 100644 --- a/src/Models/BanModel.php +++ b/src/Models/BanModel.php @@ -7,46 +7,46 @@ class BanModel { /** - * Time and Date when the ban expires. + * The Time and Date when the ban expires. * * @var Carbon|null */ - public $expires; + protected $expires; /** - * Time and Date when the ban was created. + * The Time and Date when the ban was created. * * @var Carbon */ - public $created; + protected $created; /** - * True if ban is currently active. + * Is the ban currently active? * * @var bool */ - public $active; + protected $active; /** - * Reason for the ban. + * The ban reason. * * @var string */ - public $reason; + protected $reason; /** - * Admin's name. + * The Admin's name. * * @var string */ - public $adminName; + protected $adminName; /** * Admin's ID. * * @var int */ - public $adminID; + protected $adminID; /** * BanModel constructor. @@ -77,4 +77,52 @@ public function __construct(array $ban) $this->adminName = $ban['adminName']; $this->adminID = $ban['adminID']; } + + /** + * @return Carbon|null + */ + public function getExpires(): ?Carbon + { + return $this->expires; + } + + /** + * @return Carbon + */ + public function getCreated(): Carbon + { + return $this->created; + } + + /** + * @return bool + */ + public function isActive(): bool + { + return $this->active; + } + + /** + * @return string + */ + public function getReason(): string + { + return $this->reason; + } + + /** + * @return string + */ + public function getAdminName(): string + { + return $this->adminName; + } + + /** + * @return int + */ + public function getAdminID(): int + { + return $this->adminID; + } } diff --git a/src/Models/BansModel.php b/src/Models/BansModel.php index 85669c6..2e0f84c 100644 --- a/src/Models/BansModel.php +++ b/src/Models/BansModel.php @@ -3,19 +3,9 @@ namespace TruckersMP\Models; use TruckersMP\Exceptions\PlayerNotFoundException; -use Vent\VentTrait; class BansModel extends GroupedModel { - use VentTrait; - - /** - * Array of bans. - * - * @var array - */ - public $bans = []; - /** * BansModel constructor. * @@ -24,11 +14,6 @@ class BansModel extends GroupedModel */ public function __construct(array $response) { - // Make sure our grouped variable is kept updated - $this->registerEvent('write', 'bans', function () { - $this->groupedValue = $this->bans; - }); - $this->position = 0; if ($response['error'] && @@ -39,7 +24,15 @@ public function __construct(array $response) } foreach ($response['response'] as $k => $ban) { - $this->bans[$k] = new BanModel($ban); + $this->groupedValue[$k] = new BanModel($ban); } } + + /** + * @return array + */ + public function getBans(): array + { + return $this->groupedValue; + } } diff --git a/src/Models/GameTimeModel.php b/src/Models/GameTimeModel.php index 5b87728..80f3077 100644 --- a/src/Models/GameTimeModel.php +++ b/src/Models/GameTimeModel.php @@ -10,7 +10,7 @@ class GameTimeModel /** * @var Carbon */ - public $time; + protected $time; /** * GameTimeModel constructor. @@ -40,4 +40,12 @@ public function __construct(array $response) $this->time = Carbon::create($load['years'], $load['months'], $load['days'], $load['hours'], $load['minutes']); } + + /** + * @return Carbon + */ + public function getTime(): Carbon + { + return $this->time; + } } diff --git a/src/Models/PlayerModel.php b/src/Models/PlayerModel.php index f21a2ac..7c0d204 100644 --- a/src/Models/PlayerModel.php +++ b/src/Models/PlayerModel.php @@ -11,56 +11,56 @@ class PlayerModel * * @var int */ - public $id; + protected $id; /** * Username. * * @var string */ - public $name; + protected $name; /** * Avatar URL. * * @var string */ - public $avatar; + protected $avatar; /** * Date and time user joined. * * @var \DateTime */ - public $joinDate; + protected $joinDate; /** * User's associated SteamID. * * @var string */ - public $steamID64; + protected $steamID64; /** * Group ID of user. * * @var int */ - public $groupID; + protected $groupID; /** * Human readable group name. * * @var string */ - public $groupName; + protected $groupName; /** * If user is an in-game admin. * * @var bool */ - public $inGameAdmin; + protected $inGameAdmin; /** * PlayerModel constructor. @@ -74,13 +74,79 @@ public function __construct(array $response) throw new PlayerNotFoundException($response['response']); } - $this->id = $response['response']['id']; - $this->name = $response['response']['name']; - $this->avatar = $response['response']['avatar']; - $this->joinDate = $response['response']['joinDate']; - $this->steamID64 = $response['response']['steamID64']; - $this->groupID = $response['response']['groupID']; - $this->groupName = $response['response']['groupName']; - $this->inGameAdmin = $response['response']['permissions']['isGameAdmin']; + $response = $response['response']; + + $this->id = $response['id']; + $this->name = $response['name']; + $this->avatar = $response['avatar']; + $this->joinDate = $response['joinDate']; + $this->steamID64 = $response['steamID64']; + $this->groupID = $response['groupID']; + $this->groupName = $response['groupName']; + $this->inGameAdmin = $response['permissions']['isGameAdmin']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return string + */ + public function getAvatar(): string + { + return $this->avatar; + } + + /** + * @return \DateTime + */ + public function getJoinDate(): \DateTime + { + return $this->joinDate; + } + + /** + * @return string + */ + public function getSteamID64(): string + { + return $this->steamID64; + } + + /** + * @return int + */ + public function getGroupID(): int + { + return $this->groupID; + } + + /** + * @return string + */ + public function getGroupName(): string + { + return $this->groupName; + } + + /** + * @return bool + */ + public function isAdmin(): bool + { + return $this->inGameAdmin; } } diff --git a/src/Models/RulesModel.php b/src/Models/RulesModel.php index eec658a..528c6e8 100644 --- a/src/Models/RulesModel.php +++ b/src/Models/RulesModel.php @@ -11,14 +11,14 @@ class RulesModel * * @var string */ - public $rules; + protected $rules; /** * The current rules revision. * * @var int */ - public $revision; + protected $revision; /** * RulesModel constructor. @@ -35,4 +35,20 @@ public function __construct(array $response) $this->rules = $response['rules']; $this->revision = $response['revision']; } + + /** + * @return string + */ + public function getRules(): string + { + return $this->rules; + } + + /** + * @return int + */ + public function getRevision(): int + { + return $this->revision; + } } diff --git a/src/Models/ServerModel.php b/src/Models/ServerModel.php index a344eab..73b98d5 100644 --- a/src/Models/ServerModel.php +++ b/src/Models/ServerModel.php @@ -5,116 +5,116 @@ class ServerModel { /** - * Game server ID. + * Server ID. * * @var int */ - public $id; + protected $id; /** - * Game. + * Server game. * * @var string */ - public $game; + protected $game; /** - * IP or Hostname of server. + * Server IP or Hostname. * * @var string */ - public $ip; + protected $ip; /** - * Port. + * Server port. * * @var int */ - public $port; + protected $port; /** - * Game server name. + * Server name. * * @var string */ - public $name; + protected $name; /** - * Game server short name. + * Server short name. * * @var string */ - public $shortName; + protected $shortName; /** - * Online status. + * Server Online status. * * @var bool */ - public $online; + protected $online; /** - * Current player count. + * Server current player count. * * @var int */ - public $players; + protected $players; /** - * Current queue count. + * Server current queue count. * * @var int */ - public $queue; + protected $queue; /** - * Max player count. + * Server max players. * * @var int */ - public $maxPlayers; + protected $maxPlayers; /** - * Speed limiter. + * Server speed limit? * * @var bool */ - public $speedLimiter; + protected $speedLimiter; /** - * Collisions. + * Server collisions? * * @var bool */ - public $collisions; + protected $collisions; /** - * Will cars be available for all players. + * Are cars available to all players? * * @var bool */ - public $carsForPlayers; + protected $carsForPlayers; /** - * Will police cars be available for all players. + * Are police cars available to all players? * * @var bool */ - public $policeCarsForPlayers; + protected $policeCarsForPlayers; /** - * "Away from keyboard" status. + * Server "Away from keyboard" status. * * @var bool */ - public $afkEnabled; + protected $afkEnabled; /** - * Sync delay (tick rate). + * Server sync delay (tick rate). * * @var bool */ - public $syncDelay; + protected $syncDelay; /** * ServerModel constructor. @@ -140,4 +140,132 @@ public function __construct(array $server) $this->afkEnabled = boolval($server['afkenabled']); $this->syncDelay = intval($server['syncdelay']); } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return string + */ + public function getGame(): string + { + return $this->game; + } + + /** + * @return string + */ + public function getIp(): string + { + return $this->ip; + } + + /** + * @return int + */ + public function getPort(): int + { + return $this->port; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return string + */ + public function getShortName(): string + { + return $this->shortName; + } + + /** + * @return bool + */ + public function isOnline(): bool + { + return $this->online; + } + + /** + * @return int + */ + public function getPlayers(): int + { + return $this->players; + } + + /** + * @return int + */ + public function getQueue(): int + { + return $this->queue; + } + + /** + * @return int + */ + public function getMaxPlayers(): int + { + return $this->maxPlayers; + } + + /** + * @return bool + */ + public function hasSpeedLimit(): bool + { + return $this->speedLimiter; + } + + /** + * @return bool + */ + public function hasCollisions(): bool + { + return $this->collisions; + } + + /** + * @return bool + */ + public function canPlayersHaveCars(): bool + { + return $this->carsForPlayers; + } + + /** + * @return bool + */ + public function canPlayersHavePoliceCars(): bool + { + return $this->policeCarsForPlayers; + } + + /** + * @return bool + */ + public function isAfkEnabled(): bool + { + return $this->afkEnabled; + } + + /** + * @return bool + */ + public function hasSyncDelay(): bool + { + return $this->syncDelay; + } } diff --git a/src/Models/ServersModel.php b/src/Models/ServersModel.php index 0ea9cc0..e9ae39a 100644 --- a/src/Models/ServersModel.php +++ b/src/Models/ServersModel.php @@ -3,19 +3,9 @@ namespace TruckersMP\Models; use TruckersMP\Exceptions\APIErrorException; -use Vent\VentTrait; class ServersModel extends GroupedModel { - use VentTrait; - - /** - * Array of servers. - * - * @var array - */ - public $servers = []; - /** * @var string */ @@ -29,11 +19,6 @@ class ServersModel extends GroupedModel */ public function __construct(array $response) { - // Make sure our grouped variable is kept updated - $this->registerEvent('write', 'servers', function () { - $this->groupedValue = $this->servers; - }); - $this->position = 0; if ($response['error'] == 'true' && $response['descriptor'] == 'Unable to fetch servers') { @@ -41,9 +26,15 @@ public function __construct(array $response) } foreach ($response['response'] as $k => $server) { - $this->servers[$k] = new ServerModel($server); + $this->groupedValue[$k] = new ServerModel($server); } + } - $this->groupedValue = $this->servers; + /** + * @return array + */ + public function getServers(): array + { + return $this->groupedValue; } } diff --git a/src/Models/VersionModel.php b/src/Models/VersionModel.php index 7e11339..6e11614 100644 --- a/src/Models/VersionModel.php +++ b/src/Models/VersionModel.php @@ -3,28 +3,29 @@ namespace TruckersMP\Models; use Carbon\Carbon; +use stdClass; class VersionModel { /** - * @var \stdClass + * @var stdClass */ - public $version; + protected $version; /** - * @var \stdClass + * @var stdClass */ - public $checksum; + protected $checksum; /** * @var Carbon */ - public $released; + protected $released; /** - * @var \stdClass + * @var stdClass */ - public $support; + protected $support; /** * VersionModel constructor. @@ -33,23 +34,55 @@ class VersionModel */ public function __construct(array $response) { - $this->version = new \stdClass(); + $this->version = new stdClass(); $this->version->human = $response['name']; $this->version->stage = $response['stage']; $this->version->nummeric = $response['numeric']; - $this->checksum = new \stdClass(); - $this->checksum->atsmp = new \stdClass(); + $this->checksum = new stdClass(); + $this->checksum->atsmp = new stdClass(); $this->checksum->atsmp->dll = $response['atsmp_checksum']['dll']; $this->checksum->atsmp->adb = $response['atsmp_checksum']['adb']; - $this->checksum->ets2mp = new \stdClass(); + $this->checksum->ets2mp = new stdClass(); $this->checksum->ets2mp->dll = $response['atsmp_checksum']['dll']; $this->checksum->ets2mp->adb = $response['atsmp_checksum']['adb']; $this->released = new Carbon($response['time'], 'UTC'); - $this->support = new \stdClass(); + $this->support = new stdClass(); $this->support->ets2 = $response['supported_game_version']; $this->support->ats = $response['supported_ats_game_version']; } + + /** + * @return stdClass + */ + public function getVersion(): stdClass + { + return $this->version; + } + + /** + * @return stdClass + */ + public function getChecksum(): stdClass + { + return $this->checksum; + } + + /** + * @return Carbon + */ + public function getReleased(): Carbon + { + return $this->released; + } + + /** + * @return stdClass + */ + public function getSupport(): stdClass + { + return $this->support; + } } From f33eb636aa5b3afca978872d46c5332ef5a771f4 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 13:08:33 +0000 Subject: [PATCH 25/32] We now call the endpoints based on the function name --- src/Client.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Client.php b/src/Client.php index e362593..61c45f8 100644 --- a/src/Client.php +++ b/src/Client.php @@ -51,9 +51,9 @@ public function __construct(array $config = [], bool $secure = true) */ public function player(int $id): PlayerModel { - $result = $this->request->execute('player/' . $id); - - return new PlayerModel($result); + return new PlayerModel( + $this->request->execute(__FUNCTION__ . '/' . $id) + ); } /** @@ -68,9 +68,9 @@ public function player(int $id): PlayerModel */ public function bans(int $id): BansModel { - $result = $this->request->execute('bans/' . $id); - - return new BansModel($result); + return new BansModel( + $this->request->execute(__FUNCTION__ . '/' . $id) + ); } /** @@ -84,9 +84,9 @@ public function bans(int $id): BansModel */ public function servers(): ServersModel { - $result = $this->request->execute('servers'); - - return new ServersModel($result); + return new ServersModel( + $this->request->execute(__FUNCTION__) + ); } /** @@ -100,9 +100,9 @@ public function servers(): ServersModel */ public function gameTime(): GameTimeModel { - $result = $this->request->execute('game_time'); - - return new GameTimeModel($result); + return new GameTimeModel( + $this->request->execute(strtolower(preg_replace('/(?request->execute('version'); - - return new VersionModel($result); + return new VersionModel( + $this->request->execute(__FUNCTION__) + ); } /** @@ -134,8 +134,8 @@ public function version(): VersionModel */ public function rules(): RulesModel { - $result = $this->request->execute('rules'); - - return new RulesModel($result); + return new RulesModel( + $this->request->execute(__FUNCTION__) + ); } } From 48596e0589bddf3eee3912e1ad9783768108c073 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 13:08:57 +0000 Subject: [PATCH 26/32] Removed unstable dependency --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index d87eb5c..c53ff8e 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,6 @@ "nesbot/carbon": "^1.21", "php-http/message": "^1.2", "guzzlehttp/psr7": "^1.3", - "leedavis81/vent": "dev-master", "ext-json": "*" }, "require-dev": { From ba042f5c6d21e502d3c5c6b110c4972bf8fcbbb7 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 13:09:29 +0000 Subject: [PATCH 27/32] Composer update --- composer.lock | 54 ++------------------------------------------------- 1 file changed, 2 insertions(+), 52 deletions(-) diff --git a/composer.lock b/composer.lock index bdc2adb..06ad471 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "63c614b6973ce1d74728010a9497b41b", + "content-hash": "b54a90e0e918c2b5657ba9a681bce8d9", "packages": [ { "name": "clue/stream-filter", @@ -125,54 +125,6 @@ ], "time": "2018-12-04T20:46:45+00:00" }, - { - "name": "leedavis81/vent", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/leedavis81/vent.git", - "reference": "b2e7892960df93260e0e3d0e58ba95228b2c30d3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/leedavis81/vent/zipball/b2e7892960df93260e0e3d0e58ba95228b2c30d3", - "reference": "b2e7892960df93260e0e3d0e58ba95228b2c30d3", - "shasum": "" - }, - "require": { - "php": ">=5.4" - }, - "require-dev": { - "phpunit/phpunit": "3.7.*", - "satooshi/php-coveralls": "~0.6" - }, - "type": "library", - "autoload": { - "psr-0": { - "Vent\\": "src/", - "VentTest\\": "tests/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Lee Davis", - "email": "leedavis81@hotmail.com", - "homepage": "http://leedavis81.github.io", - "role": "Developer" - } - ], - "description": "PHP variable events.", - "keywords": [ - "event", - "php", - "variable" - ], - "time": "2014-03-04T17:17:50+00:00" - }, { "name": "nesbot/carbon", "version": "1.36.2", @@ -2480,9 +2432,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "leedavis81/vent": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { From 0d4e08a88b7e706588048eeaea3a84e905f785f0 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 14:09:22 +0000 Subject: [PATCH 28/32] Update readme to describe new style. --- readme.md | 88 ++++++++++++++++++++++++++++++++------ src/Models/PlayerModel.php | 9 ++-- 2 files changed, 79 insertions(+), 18 deletions(-) diff --git a/readme.md b/readme.md index 25870a2..39e969b 100644 --- a/readme.md +++ b/readme.md @@ -34,7 +34,7 @@ After doing either of the above, execute the command `composer install`. ## Usage -> **Please note: this examples doesn't use caching. You should cache your requests in order to use API responsibly. Some examples can be found in `examples\cache` folder.** +> **Please note: this example doesn't use caching. You should cache your requests in order to use API responsibly. Some examples can be found in `examples\cache` folder.** ```php player(50); $player = $client->player(76561197965863564); // output the user's name -echo $player->name; +echo $player->getName(); // output the user's group -echo $player->groupName; +echo $player->getGroupName(); ``` ## Methods -`player()` - find player by TruckersMP ID or Steam ID - -`bans()` - view bans by TruckersMP ID - -`servers()` - servers list - -`gameTime()` - gameserver time (uses [Carbon](http://carbon.nesbot.com/docs/)) - -`version()`- TruckersMP version info +All timestamps in this project return a [Carbon](http://carbon.nesbot.com/docs/) class. + +- `player(int $id): PlayerModel` - Get player info by either TruckersMP ID or Steam ID +- `bans(int $id): BansModel` - Get bans for a player by player ID +- `servers(): ServersModel` - Get a list of servers +- `gameTime(): GameTimeModel` - Get the server time +- `version(): VersionModel`- *DEPRECATED* Get the TruckersMP version info +- `rules(): RulesModel` - Get the TruckersMP rules + +## Models + +### BanModel Methods +- `getExpires(): ?Carbon` +- `getCreated(): Carbon` +- `isActive(): bool` +- `getReason(): string` +- `getAdminName(): string` +- `getAdminID(): int` + +### BansModel +Contains an array of BanModels. + +### GameTimeModel Methods +- `getTime(): Carbon` + +### PlayerModel Methods +- `getId(): int` +- `getName(): string` +- `getAvatar(): string` +- `getJoinDate(): Carbon` +- `getSteamID64(): string` +- `getGroupID(): int` +- `getGroupName(): string` +- `isAdmin(): bool` + +### RulesModel Methods +- `getRules(): string` +- `getRevision(): int` + +### ServerModel Methods +- `getId(): int` +- `getGame(): string` +- `getIp(): string` +- `getPort(): int` +- `getName(): string` +- `getShortName(): string` +- `isOnline(): bool` +- `getPlayers(): int` +- `getQueue(): int` +- `getMaxPlayers(): int` +- `hasSpeedLimit(): bool` +- `hasCollisions(): bool` +- `canPlayersHaveCars(): bool` +- `canPlayersHavePoliceCars(): bool` +- `isAfkEnabled(): bool` +- `hasSyncDelay(): bool` + +### ServersModel +Contains an array of ServerModels. + +### VersionModel +- `getVersion(): stdClass` +- `getChecksum(): stdClass` +- `getReleased(): Carbon` +- `getSupport(): stdClass` ## Configuration -We use [Guzzle](https://github.com/guzzle/guzzle) for gathering data from API endpoint. If you want to change Guzzle [configuration](http://guzzlephp.org/), you can pass config array on Client initialization. +We use [Guzzle](https://github.com/guzzle/guzzle) to get data from an API endpoint. If you want to change the Guzzle [configuration](http://guzzlephp.org/) then you can pass config array during Client intialization. + +You can also pass a second parameter to specify `HTTP` (false) or `HTTPS` (true) requests. This is true by default. ```php id = $response['id']; $this->name = $response['name']; $this->avatar = $response['avatar']; - $this->joinDate = $response['joinDate']; + $this->joinDate = new Carbon($response['joinDate'], 'UTC'); $this->steamID64 = $response['steamID64']; $this->groupID = $response['groupID']; $this->groupName = $response['groupName']; @@ -111,9 +112,9 @@ public function getAvatar(): string } /** - * @return \DateTime + * @return Carbon */ - public function getJoinDate(): \DateTime + public function getJoinDate(): Carbon { return $this->joinDate; } From 805f7b9a38ca5733c2090f0ac9362309e7d58512 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 14:12:57 +0000 Subject: [PATCH 29/32] Readme wording updates --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 39e969b..85a24a7 100644 --- a/readme.md +++ b/readme.md @@ -8,7 +8,8 @@ [![Total Downloads](https://poser.pugx.org/truckersmp/api-client/downloads)](https://packagist.org/packages/truckersmp/api-client) -This is a PHP library created to simplify development using the [TruckersMP](http://truckersmp.com/) API. This client library provides functions to connect and gather data from each API endpoint, and returns the data as an object. +This is a PHP library created to simplify development using the [TruckersMP](http://truckersmp.com/) API. +This library provides functions to connect and gather data from each API endpoint, and returns the data as a class with getting functions. > If you want to use the API without a library (or if you have advanced knowledge of PHP), check out our [API documentation](https://stats.truckersmp.com/api). From 864f382ec3c6919616fadbba8cfb4148e1c83d9e Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 14:33:14 +0000 Subject: [PATCH 30/32] Updated unit tests to use new format --- Tests/ClientTest.php | 56 +++++++++++++++++-------------------- src/Models/BansModel.php | 2 +- src/Models/ServersModel.php | 2 +- 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index 8a8de9c..eb2c0dc 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -13,10 +13,7 @@ class ClientTest extends TestCase { - /** - * @var int - */ - protected $testAccount = 585204; + const TEST_ACCOUNT = 585204; /** * @var Client @@ -39,11 +36,11 @@ public function __construct() */ public function testPlayer(): void { - $player = $this->client->player($this->testAccount); + $player = $this->client->player(self::TEST_ACCOUNT); - $this->assertEquals($player->name, 'tuxytestaccount'); - $this->assertEquals($player->groupID, 1); - $this->assertEquals($player->groupName, 'Player'); + $this->assertEquals($player->getName(), 'tuxytestaccount'); + $this->assertEquals($player->getGroupID(), 1); + $this->assertEquals($player->getGroupName(), 'Player'); $this->assertInstanceOf(PlayerModel::class, $player); } @@ -54,19 +51,16 @@ public function testPlayer(): void */ public function testPlayerBans(): void { - /** - * @var $bans BanModel[] - */ - $bans = $this->client->bans($this->testAccount); + $bans = $this->client->bans(self::TEST_ACCOUNT); - if (count($bans->bans) > 0) { - $this->assertTrue(is_string($bans[0]->created)); - $this->assertTrue(is_string($bans[0]->expires)); - $this->assertTrue(is_string($bans[0]->reason)); + if (count($bans->getBans()) > 0) { + $this->assertTrue(is_string($bans->getBans()[0]->getCreated())); + $this->assertTrue(is_string($bans->getBans()[0]->getExpires())); + $this->assertTrue(is_string($bans->getBans()[0]->getReason())); $this->assertInstanceOf(BanModel::class, $bans[0]); } else { - $this->assertEquals($bans->bans, []); + $this->assertEquals($bans->getBans(), []); } $this->assertInstanceOf(BansModel::class, $bans); @@ -80,7 +74,7 @@ public function testServers(): void { $servers = $this->client->servers(); - $this->assertEquals($servers[0]->name, 'Europe 1 [Simulation]'); + $this->assertEquals($servers->getServers()[0]->getName(), 'Europe 1 [Simulation]'); } /** @@ -91,19 +85,19 @@ public function testVersion(): void { $version = $this->client->version(); - $this->assertNotEmpty($version->version->human); - $this->assertNotEmpty($version->version->stage); - $this->assertNotEmpty($version->version->nummeric); + $this->assertNotEmpty($version->getVersion()->human); + $this->assertNotEmpty($version->getVersion()->stage); + $this->assertNotEmpty($version->getVersion()->nummeric); - $this->assertNotEmpty($version->checksum->atsmp->dll); - $this->assertNotEmpty($version->checksum->atsmp->adb); - $this->assertNotEmpty($version->checksum->ets2mp->dll); - $this->assertNotEmpty($version->checksum->ets2mp->adb); + $this->assertNotEmpty($version->getChecksum()->atsmp->dll); + $this->assertNotEmpty($version->getChecksum()->atsmp->adb); + $this->assertNotEmpty($version->getChecksum()->ets2mp->dll); + $this->assertNotEmpty($version->getChecksum()->ets2mp->adb); - $this->assertInstanceOf(Carbon::class, $version->released); + $this->assertInstanceOf(Carbon::class, $version->getReleased()); - $this->assertNotEmpty($version->support->ets2); - $this->assertNotEmpty($version->support->ats); + $this->assertNotEmpty($version->getSupport()->ets2); + $this->assertNotEmpty($version->getSupport()->ats); } /** @@ -115,7 +109,7 @@ public function testGameTime(): void $this->assertNotEmpty($time); - $this->assertInstanceOf(Carbon::class, $time->time); + $this->assertInstanceOf(Carbon::class, $time->getTime()); $this->assertInstanceOf(GameTimeModel::class, $time); } @@ -128,8 +122,8 @@ public function testRules(): void { $rules = $this->client->rules(); - $this->assertTrue(is_string($rules->rules)); - $this->assertTrue(is_int($rules->revision)); + $this->assertTrue(is_string($rules->getRules())); + $this->assertTrue(is_int($rules->getRevision())); $this->assertInstanceOf(RulesModel::class, $rules); } diff --git a/src/Models/BansModel.php b/src/Models/BansModel.php index 2e0f84c..4576e5f 100644 --- a/src/Models/BansModel.php +++ b/src/Models/BansModel.php @@ -29,7 +29,7 @@ public function __construct(array $response) } /** - * @return array + * @return BanModel[] */ public function getBans(): array { diff --git a/src/Models/ServersModel.php b/src/Models/ServersModel.php index e9ae39a..6abd277 100644 --- a/src/Models/ServersModel.php +++ b/src/Models/ServersModel.php @@ -31,7 +31,7 @@ public function __construct(array $response) } /** - * @return array + * @return ServerModel[] */ public function getServers(): array { From b97a76e378fb41fd70ddec8f5227ea4e773a7770 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 14:36:10 +0000 Subject: [PATCH 31/32] Added the ability to pass an index to get functions for groupedModels --- src/Models/BansModel.php | 5 +++-- src/Models/ServersModel.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Models/BansModel.php b/src/Models/BansModel.php index 4576e5f..e748309 100644 --- a/src/Models/BansModel.php +++ b/src/Models/BansModel.php @@ -29,10 +29,11 @@ public function __construct(array $response) } /** + * @param int|null $index * @return BanModel[] */ - public function getBans(): array + public function getBans(?int $index = null): array { - return $this->groupedValue; + return $index ? $this->groupedValue[$index] : $this->groupedValue; } } diff --git a/src/Models/ServersModel.php b/src/Models/ServersModel.php index 6abd277..b67bcd7 100644 --- a/src/Models/ServersModel.php +++ b/src/Models/ServersModel.php @@ -31,10 +31,11 @@ public function __construct(array $response) } /** + * @param null|int $index * @return ServerModel[] */ - public function getServers(): array + public function getServers(?int $index = null): array { - return $this->groupedValue; + return $index ? $this->groupedValue[$index] : $this->groupedValue; } } From 238f85298458b0b71824253724967e9695f8ec79 Mon Sep 17 00:00:00 2001 From: B3none Date: Thu, 28 Mar 2019 14:41:00 +0000 Subject: [PATCH 32/32] Put getGroupedValue logic all in the same place --- src/Exceptions/IndexNotFoundException.php | 7 +++++++ src/Models/BansModel.php | 4 +++- src/Models/GroupedModel.php | 20 ++++++++++++++++++++ src/Models/ServersModel.php | 4 +++- 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/Exceptions/IndexNotFoundException.php diff --git a/src/Exceptions/IndexNotFoundException.php b/src/Exceptions/IndexNotFoundException.php new file mode 100644 index 0000000..428e419 --- /dev/null +++ b/src/Exceptions/IndexNotFoundException.php @@ -0,0 +1,7 @@ +groupedValue[$index] : $this->groupedValue; + return $this->getGroupedValue($index); } } diff --git a/src/Models/GroupedModel.php b/src/Models/GroupedModel.php index 189511d..190e76d 100644 --- a/src/Models/GroupedModel.php +++ b/src/Models/GroupedModel.php @@ -2,6 +2,8 @@ namespace TruckersMP\Models; +use TruckersMP\Exceptions\IndexNotFoundException; + abstract class GroupedModel implements \Iterator, \ArrayAccess { /** @@ -19,6 +21,24 @@ abstract class GroupedModel implements \Iterator, \ArrayAccess */ protected $exceptionMessage = 'You do not have access to modify this grouped value.'; + /** + * @param int|null $index + * @return array + * @throws IndexNotFoundException + */ + public function getGroupedValue(int $index = null): array + { + if ($index) { + if (isset($this->groupedValue[$index])) { + return $this->groupedValue[$index]; + } + + throw new IndexNotFoundException(); + } + + return $this->groupedValue; + } + /** * @return void */ diff --git a/src/Models/ServersModel.php b/src/Models/ServersModel.php index b67bcd7..017b6da 100644 --- a/src/Models/ServersModel.php +++ b/src/Models/ServersModel.php @@ -3,6 +3,7 @@ namespace TruckersMP\Models; use TruckersMP\Exceptions\APIErrorException; +use TruckersMP\Exceptions\IndexNotFoundException; class ServersModel extends GroupedModel { @@ -33,9 +34,10 @@ public function __construct(array $response) /** * @param null|int $index * @return ServerModel[] + * @throws IndexNotFoundException */ public function getServers(?int $index = null): array { - return $index ? $this->groupedValue[$index] : $this->groupedValue; + return $this->getGroupedValue($index); } }