From b83603d2c5abeaa147bc9896a75e8a445486900a Mon Sep 17 00:00:00 2001 From: B3none Date: Wed, 27 Mar 2019 19:53:15 +0000 Subject: [PATCH 001/123] 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 002/123] 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 003/123] 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 004/123] 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 005/123] 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 006/123] 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 007/123] 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 008/123] 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 009/123] 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 010/123] 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 011/123] 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 012/123] 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 013/123] 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 014/123] 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 015/123] 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 016/123] 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 017/123] 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 018/123] 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 019/123] 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 020/123] 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 021/123] 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 022/123] 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 023/123] 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 024/123] 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 025/123] 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 026/123] 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 027/123] 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 028/123] 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 029/123] 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 030/123] 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 031/123] 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 032/123] 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); } } From 2808df5c59ec15d556c5035ab00363d1d5c35748 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 16 Nov 2019 21:52:36 +0000 Subject: [PATCH 033/123] Separated the tests into individual classes --- .editorconfig | 15 +++++ Tests/BansTest.php | 58 ++++++++++++++++++ Tests/ClientTest.php | 130 ----------------------------------------- Tests/GameTimeTest.php | 40 +++++++++++++ Tests/PlayerTest.php | 88 ++++++++++++++++++++++++++++ Tests/RulesTest.php | 39 +++++++++++++ Tests/ServersTest.php | 70 ++++++++++++++++++++++ Tests/VersionTest.php | 47 +++++++++++++++ 8 files changed, 357 insertions(+), 130 deletions(-) create mode 100644 .editorconfig create mode 100644 Tests/BansTest.php delete mode 100644 Tests/ClientTest.php create mode 100644 Tests/GameTimeTest.php create mode 100644 Tests/PlayerTest.php create mode 100644 Tests/RulesTest.php create mode 100644 Tests/ServersTest.php create mode 100644 Tests/VersionTest.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6537ca4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 diff --git a/Tests/BansTest.php b/Tests/BansTest.php new file mode 100644 index 0000000..4360718 --- /dev/null +++ b/Tests/BansTest.php @@ -0,0 +1,58 @@ +client = new Client(); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testWeCanGetTheUsersBans() + { + $bans = $this->client->bans(self::TEST_ACCOUNT); + + if (count($bans->getBans()) > 0) { + $ban = $bans->getBans()[0]; + + if ($ban->getExpires() != null) { + $this->assertInstanceOf(Carbon::class, $ban->getExpires()); + } + + $this->assertInstanceOf(Carbon::class, $ban->getCreated()); + $this->assertIsBool($ban->isActive()); + $this->assertIsString($ban->getReason()); + $this->assertIsString($ban->getAdminName()); + $this->assertIsInt($ban->getAdminID()); + + $this->assertInstanceOf(BanModel::class, $ban); + } else { + $this->assertEquals($bans->getBans(), []); + } + + $this->assertInstanceOf(BansModel::class, $bans); + } +} diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php deleted file mode 100644 index eb2c0dc..0000000 --- a/Tests/ClientTest.php +++ /dev/null @@ -1,130 +0,0 @@ -client = new Client(); - } - - /** - * @throws \Exception - * @throws \Http\Client\Exception - */ - public function testPlayer(): void - { - $player = $this->client->player(self::TEST_ACCOUNT); - - $this->assertEquals($player->getName(), 'tuxytestaccount'); - $this->assertEquals($player->getGroupID(), 1); - $this->assertEquals($player->getGroupName(), 'Player'); - - $this->assertInstanceOf(PlayerModel::class, $player); - } - - /** - * @throws \Exception - * @throws \Http\Client\Exception - */ - public function testPlayerBans(): void - { - $bans = $this->client->bans(self::TEST_ACCOUNT); - - 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->getBans(), []); - } - - $this->assertInstanceOf(BansModel::class, $bans); - } - - /** - * @throws \Exception - * @throws \Http\Client\Exception - */ - public function testServers(): void - { - $servers = $this->client->servers(); - - $this->assertEquals($servers->getServers()[0]->getName(), 'Europe 1 [Simulation]'); - } - - /** - * @throws \Exception - * @throws \Http\Client\Exception - */ - public function testVersion(): void - { - $version = $this->client->version(); - - $this->assertNotEmpty($version->getVersion()->human); - $this->assertNotEmpty($version->getVersion()->stage); - $this->assertNotEmpty($version->getVersion()->nummeric); - - $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->getReleased()); - - $this->assertNotEmpty($version->getSupport()->ets2); - $this->assertNotEmpty($version->getSupport()->ats); - } - - /** - * @throws \Http\Client\Exception - */ - public function testGameTime(): void - { - $time = $this->client->gameTime(); - - $this->assertNotEmpty($time); - - $this->assertInstanceOf(Carbon::class, $time->getTime()); - - $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->getRules())); - $this->assertTrue(is_int($rules->getRevision())); - - $this->assertInstanceOf(RulesModel::class, $rules); - } -} diff --git a/Tests/GameTimeTest.php b/Tests/GameTimeTest.php new file mode 100644 index 0000000..174ccdf --- /dev/null +++ b/Tests/GameTimeTest.php @@ -0,0 +1,40 @@ +client = new Client(); + } + + /** + * @throws \Http\Client\Exception + */ + public function testWeCanGetTheGameTime() + { + $time = $this->client->gameTime(); + + $this->assertNotEmpty($time); + + $this->assertInstanceOf(Carbon::class, $time->getTime()); + + $this->assertInstanceOf(GameTimeModel::class, $time); + } +} diff --git a/Tests/PlayerTest.php b/Tests/PlayerTest.php new file mode 100644 index 0000000..4acc26b --- /dev/null +++ b/Tests/PlayerTest.php @@ -0,0 +1,88 @@ +client = new Client(); + $this->player = $this->client->player(self::TEST_ACCOUNT); + } + + /** @test */ + public function testWeCanGetThePlayer() + { + $this->assertInstanceOf(PlayerModel::class, $this->player); + } + + /** @test */ + public function testWeCanGetThePlayerId() + { + $this->assertIsInt($this->player->getId()); + } + + /** @test */ + public function testWeCanGetThePlayerName() + { + $this->assertIsString($this->player->getName()); + } + + /** @test */ + public function testWeCanGetThePlayersAvatar() + { + $this->assertIsString($this->player->getAvatar()); + } + + /** @test */ + public function testWeCanGetThePlayerJoinDate() + { + $this->assertInstanceOf(Carbon::class, $this->player->getJoinDate()); + } + + /** @test */ + public function testWeCanGetThePlayersSteamId() + { + $this->assertIsString($this->player->getSteamID64()); + } + + /** @test */ + public function testWeCanGetThePlayersGroupName() + { + $this->assertIsString($this->player->getGroupName()); + } + + /** @test */ + public function testWeCanGetThePlayersGroupID() + { + $this->assertIsInt($this->player->getGroupID()); + } + + /** @test */ + public function testIfTheUserIsAdmin() + { + $this->assertIsBool($this->player->isAdmin()); + } +} diff --git a/Tests/RulesTest.php b/Tests/RulesTest.php new file mode 100644 index 0000000..e79ac48 --- /dev/null +++ b/Tests/RulesTest.php @@ -0,0 +1,39 @@ +client = new Client(); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\APIErrorException + */ + public function testWeCanGetTheRules() + { + $rules = $this->client->rules(); + + $this->assertIsString($rules->getRules()); + $this->assertIsInt($rules->getRevision()); + + $this->assertInstanceOf(RulesModel::class, $rules); + } +} diff --git a/Tests/ServersTest.php b/Tests/ServersTest.php new file mode 100644 index 0000000..ee7d0af --- /dev/null +++ b/Tests/ServersTest.php @@ -0,0 +1,70 @@ +client = new Client(); + } + + /** + * @throws \Http\Client\Exception + */ + public function testWeCanGetAllTheServers() + { + $servers = $this->client->servers(); + + $this->assertInstanceOf(ServersModel::class, $servers); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testWeCanGetTheServerDetails() + { + $servers = $this->client->servers(); + $server = $servers->getServers()[0]; + + $this->assertInstanceOf(ServerModel::class, $server); + + $this->assertIsInt($server->getId()); + $this->assertIsString($server->getGame()); + + $this->assertIsString($server->getIp()); + $this->assertIsInt($server->getPort()); + + $this->assertIsString($server->getName()); + $this->assertIsString($server->getShortName()); + + $this->assertIsBool($server->isOnline()); + $this->assertIsInt($server->getPlayers()); + $this->assertIsInt($server->getQueue()); + $this->assertIsInt($server->getMaxPlayers()); + + $this->assertIsBool($server->hasSpeedLimit()); + $this->assertIsBool($server->hasCollisions()); + $this->assertIsBool($server->canPlayersHaveCars()); + $this->assertIsBool($server->canPlayersHavePoliceCars()); + $this->assertIsBool($server->isAfkEnabled()); + + $this->assertIsBool($server->hasSyncDelay()); + } +} diff --git a/Tests/VersionTest.php b/Tests/VersionTest.php new file mode 100644 index 0000000..868766c --- /dev/null +++ b/Tests/VersionTest.php @@ -0,0 +1,47 @@ +client = new Client(); + } + + /** + * @throws \Http\Client\Exception + */ + public function testWeCanGetTheVersionDetails() + { + $version = $this->client->version(); + + $this->assertIsString($version->getVersion()->human); + $this->assertIsString($version->getVersion()->stage); + $this->assertIsString($version->getVersion()->nummeric); + + $this->assertIsString($version->getChecksum()->atsmp->dll); + $this->assertIsString($version->getChecksum()->atsmp->adb); + $this->assertIsString($version->getChecksum()->ets2mp->dll); + $this->assertIsString($version->getChecksum()->ets2mp->adb); + + $this->assertInstanceOf(Carbon::class, $version->getReleased()); + + $this->assertIsString($version->getSupport()->ets2); + $this->assertIsString($version->getSupport()->ats); + } +} From 582f2eb67639610dad09032a37bfceadb0c2cef7 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 16 Nov 2019 21:55:00 +0000 Subject: [PATCH 034/123] Removed hhvm from travis config --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7d7276b..fe87355 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,8 @@ cache: php: - 7.1 - - hhvm + - 7.2 + - 7.3 before_install: - composer self-update From 2caa0d32ed8a4d9fd7126c543698557914a74849 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 16 Nov 2019 21:58:26 +0000 Subject: [PATCH 035/123] Set the scheme to always be HTTPS --- src/Client.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index 61c45f8..ee93469 100644 --- a/src/Client.php +++ b/src/Client.php @@ -31,10 +31,9 @@ class Client * @param array $config * @param bool $secure */ - public function __construct(array $config = [], bool $secure = true) + public function __construct(array $config = []) { - $scheme = $secure ? 'https' : 'http'; - $url = $scheme . '://' . self::API_ENDPOINT . '/' . self::API_VERSION . '/'; + $url = 'https://' . self::API_ENDPOINT . '/' . self::API_VERSION . '/'; $this->request = new RequestHelper($url, $config); } From 2602dd7378909ec545bc46206ef9d3075dfaa3f5 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 16 Nov 2019 22:21:09 +0000 Subject: [PATCH 036/123] Added author info and the ability to tell if the player is banned --- Tests/PlayerTest.php | 22 ++++++- composer.json | 120 +++++++++++++++++++------------------ readme.md | 3 + src/Models/PlayerModel.php | 48 +++++++++++++++ 4 files changed, 134 insertions(+), 59 deletions(-) diff --git a/Tests/PlayerTest.php b/Tests/PlayerTest.php index 4acc26b..bdb3607 100644 --- a/Tests/PlayerTest.php +++ b/Tests/PlayerTest.php @@ -68,18 +68,36 @@ public function testWeCanGetThePlayersSteamId() $this->assertIsString($this->player->getSteamID64()); } - /** @test */ + /** @test */ public function testWeCanGetThePlayersGroupName() { $this->assertIsString($this->player->getGroupName()); } - /** @test */ + /** @test */ public function testWeCanGetThePlayersGroupID() { $this->assertIsInt($this->player->getGroupID()); } + /** @test */ + public function testWeCanGetIfThePlayerIsBanned() + { + $this->assertIsBool($this->player->isBanned()); + } + + /** @test */ + public function testWeCanGetWhenThePlayerIsBannedTill() + { + $this->assertInstanceOf(Carbon::class, $this->player->isBannedUntil()); + } + + /** @test */ + public function testWeCanGetIfThePlayersBansArePublic() + { + $this->assertIsBool($this->player->hasBansHidden()); + } + /** @test */ public function testIfTheUserIsAdmin() { diff --git a/composer.json b/composer.json index c53ff8e..74af9d6 100644 --- a/composer.json +++ b/composer.json @@ -1,64 +1,70 @@ { - "name": "truckersmp/api-client", - "description": "TruckersMP API Library helps connecting to and using the TruckersMP API.", - "homepage": "https://truckersmp.com/", - "license": "MIT", - "authors": [ - { - "name": "HumaneWolf", - "email": "humanewolf@truckersmp.com", - "homepage": "https://humanewolf.com/", - "role": "CM/Dev" + "name": "truckersmp/api-client", + "description": "TruckersMP API Library helps connecting to and using the TruckersMP API.", + "homepage": "https://truckersmp.com/", + "license": "MIT", + "authors": [ + { + "name": "HumaneWolf", + "email": "humanewolf@truckersmp.com", + "homepage": "https://humanewolf.com/", + "role": "CM/Dev" + }, + { + "name": "Thor Erik (Tuxy Fluffyclaws) Lie", + "email": "tuxy@truckersmp.com", + "homepage": "https://truckersmp.com/", + "role": "Dev" + }, + { + "name": "CJMAXiK", + "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" + }, + { + "name": "Ben Sherred (Ratcho)", + "email": "me@ratcho.dev", + "homepage": "https://github.com/bensherred", + "role": "Contributor" + } + ], + "require": { + "php": ">=7.1.0", + "nesbot/carbon": "^1.21", + "php-http/message": "^1.2", + "guzzlehttp/psr7": "^1.3", + "ext-json": "*" }, - { - "name": "Thor Erik (Tuxy Fluffyclaws) Lie", - "email": "tuxy@truckersmp.com", - "homepage": "https://truckersmp.com/", - "role": "Dev" + "require-dev": { + "phpunit/phpunit": "^7.0", + "squizlabs/php_codesniffer": "^2.6", + "php-http/guzzle6-adapter": "^1.0" }, - { - "name": "CJMAXiK", - "email": "me@cjmaxik.ru", - "homepage": "https://cjmaxik.ru", - "role": "IGA/Dev" + "autoload": { + "psr-4": { + "TruckersMP\\": "src/" + }, + "classmap": [ + "src/" + ] }, - { - "name": "Alex Blackham (B3none)", - "email": "ablackham2000@gmail.com", - "homepage": "https://github.com/b3none", - "role": "Dev" - } - ], - "require": { - "php": ">=7.1.0", - "nesbot/carbon": "^1.21", - "php-http/message": "^1.2", - "guzzlehttp/psr7": "^1.3", - "ext-json": "*" - }, - "require-dev": { - "phpunit/phpunit": "^7.0", - "squizlabs/php_codesniffer": "^2.6", - "php-http/guzzle6-adapter": "^1.0" - }, - "autoload": { - "psr-4": { - "TruckersMP\\": "src/" + "autoload-dev": { + "psr-4": { + "TruckersMP\\Tests\\API\\": "tests/" + } }, - "classmap": [ - "src/" - ] - }, - "autoload-dev": { - "psr-4": { - "TruckersMP\\Tests\\API\\": "tests/" + "scripts": { + "test": [ + "./vendor/bin/phpunit", + "./vendor/bin/phpcs src --standard=PSR2", + "./vendor/bin/phpcs Tests --standard=PSR2" + ] } - }, - "scripts": { - "test": [ - "./vendor/bin/phpunit", - "./vendor/bin/phpcs src --standard=PSR2", - "./vendor/bin/phpcs Tests --standard=PSR2" - ] - } } diff --git a/readme.md b/readme.md index 85a24a7..47d35cd 100644 --- a/readme.md +++ b/readme.md @@ -92,6 +92,9 @@ Contains an array of BanModels. - `getJoinDate(): Carbon` - `getSteamID64(): string` - `getGroupID(): int` +- `isBanned(): bool` +- `isBannedUntil(): bool` +- `hasBansHidden(): bool` - `getGroupName(): string` - `isAdmin(): bool` diff --git a/src/Models/PlayerModel.php b/src/Models/PlayerModel.php index 5b28513..be27f3b 100644 --- a/src/Models/PlayerModel.php +++ b/src/Models/PlayerModel.php @@ -56,6 +56,27 @@ class PlayerModel */ protected $groupName; + /** + * If user is banned. + * + * @var bool + */ + protected $isBanned; + + /** + * The date and time the ban will expire. + * + * @var \Carbon\Carbon + */ + protected $bannedUntil; + + /** + * If the user has their bans hidden. + * + * @var bool + */ + protected $displayBans; + /** * If user is an in-game admin. * @@ -84,6 +105,9 @@ public function __construct(array $response) $this->steamID64 = $response['steamID64']; $this->groupID = $response['groupID']; $this->groupName = $response['groupName']; + $this->isBanned = $response['banned']; + $this->bannedUntil = new Carbon($response['bannedUntil'], 'UTC'); + $this->displayBans = $response['displayBans']; $this->inGameAdmin = $response['permissions']['isGameAdmin']; } @@ -143,6 +167,30 @@ public function getGroupName(): string return $this->groupName; } + /** + * @return bool + */ + public function isBanned(): bool + { + return $this->isBanned; + } + + /** + * @return \Carbon\Carbon + */ + public function isBannedUntil(): Carbon + { + return $this->bannedUntil; + } + + /** + * @return bool + */ + public function hasBansHidden(): bool + { + return !$this->displayBans; + } + /** * @return bool */ From 279c0bcc9002223fc842d4dc171b953d37f990f9 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 16 Nov 2019 22:30:35 +0000 Subject: [PATCH 037/123] Added the ability to get the players VTC info --- Tests/PlayerTest.php | 30 ++++++++++++++++++++++++++++++ src/Models/PlayerModel.php | 23 +++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/Tests/PlayerTest.php b/Tests/PlayerTest.php index bdb3607..982a517 100644 --- a/Tests/PlayerTest.php +++ b/Tests/PlayerTest.php @@ -103,4 +103,34 @@ public function testIfTheUserIsAdmin() { $this->assertIsBool($this->player->isAdmin()); } + + /** @test */ + public function testWeCanGetThePlayersVTCId() + { + $this->assertIsInt($this->player->getVTC()->id); + } + + /** @test */ + public function testWeCanGetThePlayersVTCName() + { + $this->assertIsString($this->player->getVTC()->name); + } + + /** @test */ + public function testWeCanGetThePlayersVTCTag() + { + $this->assertIsString($this->player->getVTC()->tag); + } + + /** @test */ + public function testIfThePlayerIsInAVTC() + { + $this->assertIsBool($this->player->getVTC()->inVTC); + } + + /** @test */ + public function testWeCanGetThePlayersVTCMemberID() + { + $this->assertIsInt($this->player->getVTC()->memberID); + } } diff --git a/src/Models/PlayerModel.php b/src/Models/PlayerModel.php index be27f3b..685f458 100644 --- a/src/Models/PlayerModel.php +++ b/src/Models/PlayerModel.php @@ -3,6 +3,7 @@ namespace TruckersMP\Models; use Carbon\Carbon; +use stdClass; use TruckersMP\Exceptions\PlayerNotFoundException; class PlayerModel @@ -84,6 +85,13 @@ class PlayerModel */ protected $inGameAdmin; + /** + * The players VTC information. + * + * @var \stdClass + */ + protected $vtc; + /** * PlayerModel constructor. * @@ -109,6 +117,13 @@ public function __construct(array $response) $this->bannedUntil = new Carbon($response['bannedUntil'], 'UTC'); $this->displayBans = $response['displayBans']; $this->inGameAdmin = $response['permissions']['isGameAdmin']; + + $this->vtc = new stdClass(); + $this->vtc->id = $response['vtc']['id']; + $this->vtc->name = $response['vtc']['name']; + $this->vtc->tag = $response['vtc']['tag']; + $this->vtc->inVTC = $response['vtc']['inVTC']; + $this->vtc->memberID = $response['vtc']['memberID']; } /** @@ -198,4 +213,12 @@ public function isAdmin(): bool { return $this->inGameAdmin; } + + /** + * @return \stdClass + */ + public function getVTC(): stdClass + { + return $this->vtc; + } } From 86f0dc510a51a05a2a09144ed73549f36a8a084f Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 16 Nov 2019 22:47:08 +0000 Subject: [PATCH 038/123] Added extra properties to the ServerModel --- Tests/ServersTest.php | 8 ++++ readme.md | 4 ++ src/Models/ServerModel.php | 80 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/Tests/ServersTest.php b/Tests/ServersTest.php index ee7d0af..711fa78 100644 --- a/Tests/ServersTest.php +++ b/Tests/ServersTest.php @@ -54,16 +54,24 @@ public function testWeCanGetTheServerDetails() $this->assertIsString($server->getName()); $this->assertIsString($server->getShortName()); + if ($server->getIdPrefix() != null) { + $this->assertIsString($server->getIdPrefix()); + } + $this->assertIsBool($server->isOnline()); $this->assertIsInt($server->getPlayers()); $this->assertIsInt($server->getQueue()); $this->assertIsInt($server->getMaxPlayers()); + $this->assertIsInt($server->getDisplayOrder()); $this->assertIsBool($server->hasSpeedLimit()); $this->assertIsBool($server->hasCollisions()); $this->assertIsBool($server->canPlayersHaveCars()); $this->assertIsBool($server->canPlayersHavePoliceCars()); $this->assertIsBool($server->isAfkEnabled()); + $this->assertIsBool($server->isEvent()); + $this->assertIsBool($server->isSpecialEvent()); + $this->assertIsBool($server->isPromods()); $this->assertIsBool($server->hasSyncDelay()); } diff --git a/readme.md b/readme.md index 47d35cd..2e40399 100644 --- a/readme.md +++ b/readme.md @@ -109,6 +109,7 @@ Contains an array of BanModels. - `getPort(): int` - `getName(): string` - `getShortName(): string` +- `getIdPrefix(): string` - `isOnline(): bool` - `getPlayers(): int` - `getQueue(): int` @@ -118,6 +119,9 @@ Contains an array of BanModels. - `canPlayersHaveCars(): bool` - `canPlayersHavePoliceCars(): bool` - `isAfkEnabled(): bool` +- `isEvent(): bool` +- `isSpecialEvent(): bool` +- `isPromods(): bool` - `hasSyncDelay(): bool` ### ServersModel diff --git a/src/Models/ServerModel.php b/src/Models/ServerModel.php index 73b98d5..82cdb86 100644 --- a/src/Models/ServerModel.php +++ b/src/Models/ServerModel.php @@ -46,6 +46,13 @@ class ServerModel */ protected $shortName; + /** + * Server ID prefix. + * + * @var string|null + */ + protected $idPrefix; + /** * Server Online status. * @@ -74,6 +81,13 @@ class ServerModel */ protected $maxPlayers; + /** + * Server display order. + * + * @var int + */ + protected $displayOrder; + /** * Server speed limit? * @@ -109,6 +123,27 @@ class ServerModel */ protected $afkEnabled; + /** + * Server is an event server. + * + * @var bool + */ + protected $isEvent; + + /** + * Server is a special event. + * + * @var bool + */ + protected $isSpecialEvent; + + /** + * Server is a promods servers. + * + * @var bool + */ + protected $promods; + /** * Server sync delay (tick rate). * @@ -129,15 +164,20 @@ public function __construct(array $server) $this->port = intval($server['port']); $this->name = $server['name']; $this->shortName = $server['shortname']; + $this->idPrefix = $server['idprefix']; $this->online = boolval($server['online']); $this->players = intval($server['players']); $this->queue = intval($server['queue']); $this->maxPlayers = intval($server['maxplayers']); + $this->displayOrder = intval($server['displayorder']); $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->isEvent = boolval($server['event']); + $this->isSpecialEvent = boolval($server['specialEvent']); + $this->promods = boolval($server['promods']); $this->syncDelay = intval($server['syncdelay']); } @@ -189,6 +229,14 @@ public function getShortName(): string return $this->shortName; } + /** + * @return string|null + */ + public function getIdPrefix() + { + return $this->idPrefix; + } + /** * @return bool */ @@ -221,6 +269,14 @@ public function getMaxPlayers(): int return $this->maxPlayers; } + /** + * @return int + */ + public function getDisplayOrder(): int + { + return $this->displayOrder; + } + /** * @return bool */ @@ -261,6 +317,30 @@ public function isAfkEnabled(): bool return $this->afkEnabled; } + /** + * @return bool + */ + public function isEvent(): bool + { + return $this->isEvent; + } + + /** + * @return bool + */ + public function isSpecialEvent(): bool + { + return $this->isSpecialEvent; + } + + /** + * @return bool + */ + public function isPromods(): bool + { + return $this->promods; + } + /** * @return bool */ From 0bcb583102df4e3380c5ab26e4eefbb917b6fe43 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 16 Nov 2019 23:12:59 +0000 Subject: [PATCH 039/123] Renamed isBannedUntil to getBannedUntil --- Tests/PlayerTest.php | 2 +- readme.md | 3 ++- src/Models/PlayerModel.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Tests/PlayerTest.php b/Tests/PlayerTest.php index 982a517..9bba9a3 100644 --- a/Tests/PlayerTest.php +++ b/Tests/PlayerTest.php @@ -89,7 +89,7 @@ public function testWeCanGetIfThePlayerIsBanned() /** @test */ public function testWeCanGetWhenThePlayerIsBannedTill() { - $this->assertInstanceOf(Carbon::class, $this->player->isBannedUntil()); + $this->assertInstanceOf(Carbon::class, $this->player->getBannedUntil()); } /** @test */ diff --git a/readme.md b/readme.md index 2e40399..8acbc0e 100644 --- a/readme.md +++ b/readme.md @@ -93,7 +93,7 @@ Contains an array of BanModels. - `getSteamID64(): string` - `getGroupID(): int` - `isBanned(): bool` -- `isBannedUntil(): bool` +- `getBannedUntil(): bool` - `hasBansHidden(): bool` - `getGroupName(): string` - `isAdmin(): bool` @@ -114,6 +114,7 @@ Contains an array of BanModels. - `getPlayers(): int` - `getQueue(): int` - `getMaxPlayers(): int` +- `getDisplayOrder(): int` - `hasSpeedLimit(): bool` - `hasCollisions(): bool` - `canPlayersHaveCars(): bool` diff --git a/src/Models/PlayerModel.php b/src/Models/PlayerModel.php index 685f458..c660f3b 100644 --- a/src/Models/PlayerModel.php +++ b/src/Models/PlayerModel.php @@ -193,7 +193,7 @@ public function isBanned(): bool /** * @return \Carbon\Carbon */ - public function isBannedUntil(): Carbon + public function getBannedUntil(): Carbon { return $this->bannedUntil; } From 3d1c31b81b5838028bde17b6234a9211173902c1 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 17 Nov 2019 00:26:43 +0000 Subject: [PATCH 040/123] Temporarily removed the old models for refactor --- composer.json | 2 +- phpunit.xml | 4 +- readme.md | 4 +- src/Client.php | 6 +- src/Collections/BansCollection.php | 36 +++ src/Collections/Collection.php | 148 ++++++++++++ src/Models/Ban.php | 128 +++++++++++ src/Models/BanModel.php | 128 ----------- src/Models/BansModel.php | 41 ---- src/Models/GameTimeModel.php | 51 ----- src/Models/GroupedModel.php | 118 ---------- src/Models/PlayerModel.php | 224 ------------------ src/Models/RulesModel.php | 54 ----- src/Models/ServerModel.php | 351 ----------------------------- src/Models/ServersModel.php | 43 ---- src/Models/VersionModel.php | 88 -------- {Tests => tests}/BansTest.php | 2 +- {Tests => tests}/GameTimeTest.php | 2 +- {Tests => tests}/PlayerTest.php | 2 +- {Tests => tests}/RulesTest.php | 2 +- {Tests => tests}/ServersTest.php | 2 +- tests/TestCase.php | 24 ++ tests/Unit/BanTest.php | 146 ++++++++++++ {Tests => tests}/VersionTest.php | 2 +- 24 files changed, 496 insertions(+), 1112 deletions(-) create mode 100644 src/Collections/BansCollection.php create mode 100644 src/Collections/Collection.php create mode 100644 src/Models/Ban.php delete mode 100644 src/Models/BanModel.php delete mode 100644 src/Models/BansModel.php delete mode 100644 src/Models/GameTimeModel.php delete mode 100644 src/Models/GroupedModel.php delete mode 100644 src/Models/PlayerModel.php delete mode 100644 src/Models/RulesModel.php delete mode 100644 src/Models/ServerModel.php delete mode 100644 src/Models/ServersModel.php delete mode 100644 src/Models/VersionModel.php rename {Tests => tests}/BansTest.php (97%) rename {Tests => tests}/GameTimeTest.php (95%) rename {Tests => tests}/PlayerTest.php (98%) rename {Tests => tests}/RulesTest.php (95%) rename {Tests => tests}/ServersTest.php (98%) create mode 100644 tests/TestCase.php create mode 100644 tests/Unit/BanTest.php rename {Tests => tests}/VersionTest.php (97%) diff --git a/composer.json b/composer.json index 74af9d6..254a8cb 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ }, "autoload-dev": { "psr-4": { - "TruckersMP\\Tests\\API\\": "tests/" + "Tests\\": "tests/" } }, "scripts": { diff --git a/phpunit.xml b/phpunit.xml index 051430e..e649c1e 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,8 +1,8 @@ - - ./Tests/ + + ./tests/Unit diff --git a/readme.md b/readme.md index 8acbc0e..c90bc6c 100644 --- a/readme.md +++ b/readme.md @@ -72,8 +72,8 @@ All timestamps in this project return a [Carbon](http://carbon.nesbot.com/docs/) ## Models ### BanModel Methods -- `getExpires(): ?Carbon` -- `getCreated(): Carbon` +- `getExpirationDate(): ?Carbon` +- `getCreatedDate(): Carbon` - `isActive(): bool` - `getReason(): string` - `getAdminName(): string` diff --git a/src/Client.php b/src/Client.php index ee93469..b193219 100644 --- a/src/Client.php +++ b/src/Client.php @@ -7,8 +7,8 @@ namespace TruckersMP; +use TruckersMP\Collections\BansCollection; use TruckersMP\Helpers\RequestHelper; -use TruckersMP\Models\BansModel; use TruckersMP\Models\GameTimeModel; use TruckersMP\Models\PlayerModel; use TruckersMP\Models\RulesModel; @@ -65,9 +65,9 @@ public function player(int $id): PlayerModel * @throws \Http\Client\Exception * @return BansModel */ - public function bans(int $id): BansModel + public function bans(int $id): BansCollection { - return new BansModel( + return new BansCollection( $this->request->execute(__FUNCTION__ . '/' . $id) ); } diff --git a/src/Collections/BansCollection.php b/src/Collections/BansCollection.php new file mode 100644 index 0000000..a44a6f5 --- /dev/null +++ b/src/Collections/BansCollection.php @@ -0,0 +1,36 @@ +position = 0; + + // handle error + + foreach ($response['response'] as $key => $ban) { + $this->collection[$key] = new Ban($ban); + } + } + + /** + * Get the players bans. + * + * @param int|null $index + * @return Ban[] + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function getBans(?int $index = null): array + { + return $this->getValue($index); + } +} diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php new file mode 100644 index 0000000..63f522b --- /dev/null +++ b/src/Collections/Collection.php @@ -0,0 +1,148 @@ +collection[$index])) { + throw new IndexNotFoundException(); + } + + return $this->collection[$index]; + } + + return $this->collection; + } + + /** + * Return the current element. + * + * @return mixed + */ + public function current() + { + return $this->collection[$this->position]; + } + + /** + * Move forward to next element. + * + * @return void + */ + public function next() + { + $this->position++; + } + + /** + * Return the key of the current element. + * + * @return mixed + */ + public function key() + { + return $this->position; + } + + /** + * Checks if current position is valid. + * + * @return bool + */ + public function valid() + { + return isset($this->collection[$this->position]); + } + + /** + * Rewind the Iterator to the first element. + * + * @return void + */ + public function rewind() + { + $this->position = 0; + } + + /** + * Whether a offset exists. + * + * @param mixed $offset + * @return bool + */ + public function offsetExists($offset) + { + return isset($this->collection[$offset]); + } + + + /** + * Offset to retrieve. + * + * @param mixed $offset + * @return mixed|null + */ + public function offsetGet($offset) + { + return isset($this->collection[$offset]) ?: null; + } + + /** + * Offset to set. + * + * @param mixed $offset + * @param mixed $value + * @return \Exception|void + */ + public function offsetSet($offset, $value) + { + return new Exception($this->exceptionMessage); + } + + /** + * Offset to unset. + * + * @param mixed $offset + * @return \Exception|void + */ + public function offsetUnset($offset) + { + return new Exception($this->exceptionMessage); + } +} diff --git a/src/Models/Ban.php b/src/Models/Ban.php new file mode 100644 index 0000000..cafcb61 --- /dev/null +++ b/src/Models/Ban.php @@ -0,0 +1,128 @@ +expiration = new Carbon($ban['expiration'], 'UTC'); + } else { + $this->expiration = null; + } + + // Time Added + $this->timeAdded = new Carbon($ban['timeAdded'], 'UTC'); + + // Active + $this->active = boolval($ban['active']); + if (! is_null($this->expiration) && $this->active) { + if (! $this->expiration->greaterThan(Carbon::now('UTC'))) { + $this->active = false; + } + } + + $this->reason = $ban['reason']; + $this->adminName = $ban['adminName']; + $this->adminId = intval($ban['adminID']); + } + + /** + * @return \Carbon\Carbon|null + */ + public function getExpirationDate(): ?Carbon + { + return $this->expiration; + } + + /** + * @return \Carbon\Carbon + */ + public function getCreatedDate(): Carbon + { + return $this->timeAdded; + } + + /** + * @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/BanModel.php b/src/Models/BanModel.php deleted file mode 100644 index e3ad6f4..0000000 --- a/src/Models/BanModel.php +++ /dev/null @@ -1,128 +0,0 @@ -expires = null; - } else { - $this->expires = new Carbon($ban['expiration'], 'UTC'); - } - - // Time Added - $this->created = new Carbon($ban['timeAdded'], 'UTC'); - - // Active - $this->active = $ban['active']; - if (!is_null($this->expires) && $this->active) { - if (!$this->expires->greaterThan(Carbon::now('UTC'))) { - $this->active = false; - } - } - - $this->reason = $ban['reason']; - $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 deleted file mode 100644 index 04eddbf..0000000 --- a/src/Models/BansModel.php +++ /dev/null @@ -1,41 +0,0 @@ -position = 0; - - if ($response['error'] && - ($response['descriptor'] == 'No player ID submitted' || - $response['descriptor'] == 'Invalid user ID') - ) { - throw new PlayerNotFoundException($response['descriptor']); - } - - foreach ($response['response'] as $k => $ban) { - $this->groupedValue[$k] = new BanModel($ban); - } - } - - /** - * @param int|null $index - * @return BanModel[] - * @throws IndexNotFoundException - */ - public function getBans(?int $index = null): array - { - return $this->getGroupedValue($index); - } -} diff --git a/src/Models/GameTimeModel.php b/src/Models/GameTimeModel.php deleted file mode 100644 index 80f3077..0000000 --- a/src/Models/GameTimeModel.php +++ /dev/null @@ -1,51 +0,0 @@ -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/GroupedModel.php b/src/Models/GroupedModel.php deleted file mode 100644 index 190e76d..0000000 --- a/src/Models/GroupedModel.php +++ /dev/null @@ -1,118 +0,0 @@ -groupedValue[$index])) { - return $this->groupedValue[$index]; - } - - throw new IndexNotFoundException(); - } - - return $this->groupedValue; - } - - /** - * @return void - */ - public function rewind(): void - { - $this->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 mixed - */ - public function offsetGet($offset) - { - return isset($this->groupedValue[$offset]) ? $this->groupedValue[$offset] : null; - } -} diff --git a/src/Models/PlayerModel.php b/src/Models/PlayerModel.php deleted file mode 100644 index c660f3b..0000000 --- a/src/Models/PlayerModel.php +++ /dev/null @@ -1,224 +0,0 @@ -id = $response['id']; - $this->name = $response['name']; - $this->avatar = $response['avatar']; - $this->joinDate = new Carbon($response['joinDate'], 'UTC'); - $this->steamID64 = $response['steamID64']; - $this->groupID = $response['groupID']; - $this->groupName = $response['groupName']; - $this->isBanned = $response['banned']; - $this->bannedUntil = new Carbon($response['bannedUntil'], 'UTC'); - $this->displayBans = $response['displayBans']; - $this->inGameAdmin = $response['permissions']['isGameAdmin']; - - $this->vtc = new stdClass(); - $this->vtc->id = $response['vtc']['id']; - $this->vtc->name = $response['vtc']['name']; - $this->vtc->tag = $response['vtc']['tag']; - $this->vtc->inVTC = $response['vtc']['inVTC']; - $this->vtc->memberID = $response['vtc']['memberID']; - } - - /** - * @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 Carbon - */ - public function getJoinDate(): Carbon - { - 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 isBanned(): bool - { - return $this->isBanned; - } - - /** - * @return \Carbon\Carbon - */ - public function getBannedUntil(): Carbon - { - return $this->bannedUntil; - } - - /** - * @return bool - */ - public function hasBansHidden(): bool - { - return !$this->displayBans; - } - - /** - * @return bool - */ - public function isAdmin(): bool - { - return $this->inGameAdmin; - } - - /** - * @return \stdClass - */ - public function getVTC(): stdClass - { - return $this->vtc; - } -} diff --git a/src/Models/RulesModel.php b/src/Models/RulesModel.php deleted file mode 100644 index 528c6e8..0000000 --- a/src/Models/RulesModel.php +++ /dev/null @@ -1,54 +0,0 @@ -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 deleted file mode 100644 index 82cdb86..0000000 --- a/src/Models/ServerModel.php +++ /dev/null @@ -1,351 +0,0 @@ -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->idPrefix = $server['idprefix']; - $this->online = boolval($server['online']); - $this->players = intval($server['players']); - $this->queue = intval($server['queue']); - $this->maxPlayers = intval($server['maxplayers']); - $this->displayOrder = intval($server['displayorder']); - $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->isEvent = boolval($server['event']); - $this->isSpecialEvent = boolval($server['specialEvent']); - $this->promods = boolval($server['promods']); - $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 string|null - */ - public function getIdPrefix() - { - return $this->idPrefix; - } - - /** - * @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 int - */ - public function getDisplayOrder(): int - { - return $this->displayOrder; - } - - /** - * @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 isEvent(): bool - { - return $this->isEvent; - } - - /** - * @return bool - */ - public function isSpecialEvent(): bool - { - return $this->isSpecialEvent; - } - - /** - * @return bool - */ - public function isPromods(): bool - { - return $this->promods; - } - - /** - * @return bool - */ - public function hasSyncDelay(): bool - { - return $this->syncDelay; - } -} diff --git a/src/Models/ServersModel.php b/src/Models/ServersModel.php deleted file mode 100644 index 017b6da..0000000 --- a/src/Models/ServersModel.php +++ /dev/null @@ -1,43 +0,0 @@ -position = 0; - - if ($response['error'] == 'true' && $response['descriptor'] == 'Unable to fetch servers') { - throw new APIErrorException($response['descriptor']); - } - - foreach ($response['response'] as $k => $server) { - $this->groupedValue[$k] = new ServerModel($server); - } - } - - /** - * @param null|int $index - * @return ServerModel[] - * @throws IndexNotFoundException - */ - public function getServers(?int $index = null): array - { - return $this->getGroupedValue($index); - } -} diff --git a/src/Models/VersionModel.php b/src/Models/VersionModel.php deleted file mode 100644 index 6e11614..0000000 --- a/src/Models/VersionModel.php +++ /dev/null @@ -1,88 +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']; - } - - /** - * @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; - } -} diff --git a/Tests/BansTest.php b/tests/BansTest.php similarity index 97% rename from Tests/BansTest.php rename to tests/BansTest.php index 4360718..009fcc1 100644 --- a/Tests/BansTest.php +++ b/tests/BansTest.php @@ -1,6 +1,6 @@ client = new Client(); + } +} diff --git a/tests/Unit/BanTest.php b/tests/Unit/BanTest.php new file mode 100644 index 0000000..5700d81 --- /dev/null +++ b/tests/Unit/BanTest.php @@ -0,0 +1,146 @@ +client->bans(self::TEST_ACCOUNT); + + $this->assertInstanceOf(BansCollection::class, $bans); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testCanGetSpecificBan() + { + $bans = $this->client->bans(self::TEST_ACCOUNT); + + if (count($bans->getBans()) > 0) { + $ban = $bans->getBans()[0]; + + $this->assertInstanceOf(Ban::class, $ban); + } else { + $this->assertCount(0, $bans->getBans()); + } + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testCanHaveExpiryDate() + { + $bans = $this->client->bans(self::TEST_ACCOUNT); + + if (count($bans->getBans()) > 0) { + $ban = $bans->getBans()[0]; + + if ($ban->getExpirationDate() != null) { + $this->assertInstanceOf(Carbon::class, $ban->getExpirationDate()); + } else { + $this->assertNull($ban->getExpirationDate()); + } + } else { + $this->assertCount(0, $bans->getBans()); + } + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testHasCreatedDate() + { + $bans = $this->client->bans(self::TEST_ACCOUNT); + + if (count($bans->getBans()) > 0) { + $ban = $bans->getBans()[0]; + + $this->assertInstanceOf(Carbon::class, $ban->getCreatedDate()); + } else { + $this->assertCount(0, $bans->getBans()); + } + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testHasActiveState() + { + $bans = $this->client->bans(self::TEST_ACCOUNT); + + if (count($bans->getBans()) > 0) { + $ban = $bans->getBans()[0]; + + $this->assertIsBool($ban->isActive()); + } else { + $this->assertCount(0, $bans->getBans()); + } + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testHasReason() + { + $bans = $this->client->bans(self::TEST_ACCOUNT); + + if (count($bans->getBans()) > 0) { + $ban = $bans->getBans()[0]; + + $this->assertIsString($ban->getReason()); + } else { + $this->assertCount(0, $bans->getBans()); + } + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testHasNameOfAdmin() + { + $bans = $this->client->bans(self::TEST_ACCOUNT); + + if (count($bans->getBans()) > 0) { + $ban = $bans->getBans()[0]; + + $this->assertIsString($ban->getAdminName()); + } else { + $this->assertCount(0, $bans->getBans()); + } + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testHasIdOfAdmin() + { + $bans = $this->client->bans(self::TEST_ACCOUNT); + + if (count($bans->getBans()) > 0) { + $ban = $bans->getBans()[0]; + + $this->assertIsInt($ban->getAdminId()); + } else { + $this->assertCount(0, $bans->getBans()); + } + } +} diff --git a/Tests/VersionTest.php b/tests/VersionTest.php similarity index 97% rename from Tests/VersionTest.php rename to tests/VersionTest.php index 868766c..a65c2c3 100644 --- a/Tests/VersionTest.php +++ b/tests/VersionTest.php @@ -1,6 +1,6 @@ Date: Sun, 17 Nov 2019 01:01:36 +0000 Subject: [PATCH 041/123] Added the new Checksum model and refactored the version model --- composer.json | 2 +- src/Client.php | 9 ++- src/Models/Checksum.php | 48 +++++++++++ src/Models/Version.php | 154 ++++++++++++++++++++++++++++++++++++ tests/Unit/BanTest.php | 18 ++--- tests/Unit/ChecksumTest.php | 28 +++++++ tests/Unit/VersionTest.php | 101 +++++++++++++++++++++++ 7 files changed, 346 insertions(+), 14 deletions(-) create mode 100644 src/Models/Checksum.php create mode 100644 src/Models/Version.php create mode 100644 tests/Unit/ChecksumTest.php create mode 100644 tests/Unit/VersionTest.php diff --git a/composer.json b/composer.json index 254a8cb..433d760 100644 --- a/composer.json +++ b/composer.json @@ -64,7 +64,7 @@ "test": [ "./vendor/bin/phpunit", "./vendor/bin/phpcs src --standard=PSR2", - "./vendor/bin/phpcs Tests --standard=PSR2" + "./vendor/bin/phpcs tests/Unit --standard=PSR2" ] } } diff --git a/src/Client.php b/src/Client.php index b193219..b0fdd96 100644 --- a/src/Client.php +++ b/src/Client.php @@ -13,6 +13,7 @@ use TruckersMP\Models\PlayerModel; use TruckersMP\Models\RulesModel; use TruckersMP\Models\ServersModel; +use TruckersMP\Models\Version; use TruckersMP\Models\VersionModel; class Client @@ -63,7 +64,7 @@ public function player(int $id): PlayerModel * @param int $id * @throws \Exception * @throws \Http\Client\Exception - * @return BansModel + * @return BansCollection */ public function bans(int $id): BansCollection { @@ -113,11 +114,11 @@ public function gameTime(): GameTimeModel * * @throws \Exception * @throws \Http\Client\Exception - * @return VersionModel + * @return Version */ - public function version(): VersionModel + public function version(): Version { - return new VersionModel( + return new Version( $this->request->execute(__FUNCTION__) ); } diff --git a/src/Models/Checksum.php b/src/Models/Checksum.php new file mode 100644 index 0000000..1c2d985 --- /dev/null +++ b/src/Models/Checksum.php @@ -0,0 +1,48 @@ +dll = $dll; + $this->adb = $adb; + } + + /** + * @return string + */ + public function getDLL(): string + { + return $this->dll; + } + + /** + * @return string + */ + public function getADB(): string + { + return $this->adb; + } +} diff --git a/src/Models/Version.php b/src/Models/Version.php new file mode 100644 index 0000000..2399799 --- /dev/null +++ b/src/Models/Version.php @@ -0,0 +1,154 @@ +name = $version['name']; + $this->numeric = $version['numeric']; + $this->stage = $version['stage']; + + $this->ets2mpChecksum = new Checksum( + $version['ets2mp_checksum']['dll'], + $version['ets2mp_checksum']['adb'] + ); + + $this->atsmpChecksum = new Checksum( + $version['atsmp_checksum']['dll'], + $version['atsmp_checksum']['adb'] + ); + + $this->time = new Carbon($version['time'], 'UTC'); + $this->supportedGameVersion = $version['supported_game_version']; + $this->supportedATSGameVersion = $version['supported_ats_game_version']; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return string + */ + public function getNumeric(): string + { + return $this->numeric; + } + + /** + * @return string + */ + public function getStage(): string + { + return $this->stage; + } + + /** + * @return \TruckersMP\Models\Checksum + */ + public function getETS2MPChecksum() + { + return $this->ets2mpChecksum; + } + + /** + * @return \TruckersMP\Models\Checksum + */ + public function getATSMPChecksum() + { + return $this->atsmpChecksum; + } + + /** + * @return \Carbon\Carbon + */ + public function getTime(): Carbon + { + return $this->time; + } + + /** + * @return string + */ + public function getSupportedGameVersion(): string + { + return $this->supportedGameVersion; + } + + /** + * @return string + */ + public function getSupportedATSGameVersion(): string + { + return $this->supportedATSGameVersion; + } +} diff --git a/tests/Unit/BanTest.php b/tests/Unit/BanTest.php index 5700d81..ee4d094 100644 --- a/tests/Unit/BanTest.php +++ b/tests/Unit/BanTest.php @@ -9,12 +9,12 @@ class BanTest extends TestCase { - const TEST_ACCOUNT = 505253; + const TEST_ACCOUNT = 28159; /** * @throws \Http\Client\Exception */ - public function testCanGetAllBans() + public function testWeCanGetAllBans() { $bans = $this->client->bans(self::TEST_ACCOUNT); @@ -25,7 +25,7 @@ public function testCanGetAllBans() * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException */ - public function testCanGetSpecificBan() + public function testWeCanGetASpecificBan() { $bans = $this->client->bans(self::TEST_ACCOUNT); @@ -42,7 +42,7 @@ public function testCanGetSpecificBan() * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException */ - public function testCanHaveExpiryDate() + public function testItHasAnExpiryDate() { $bans = $this->client->bans(self::TEST_ACCOUNT); @@ -63,7 +63,7 @@ public function testCanHaveExpiryDate() * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException */ - public function testHasCreatedDate() + public function testItHasACreatedDate() { $bans = $this->client->bans(self::TEST_ACCOUNT); @@ -80,7 +80,7 @@ public function testHasCreatedDate() * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException */ - public function testHasActiveState() + public function testItHasAnActiveState() { $bans = $this->client->bans(self::TEST_ACCOUNT); @@ -97,7 +97,7 @@ public function testHasActiveState() * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException */ - public function testHasReason() + public function testItHasAReason() { $bans = $this->client->bans(self::TEST_ACCOUNT); @@ -114,7 +114,7 @@ public function testHasReason() * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException */ - public function testHasNameOfAdmin() + public function testItHasTheNameOfTheAdmin() { $bans = $this->client->bans(self::TEST_ACCOUNT); @@ -131,7 +131,7 @@ public function testHasNameOfAdmin() * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException */ - public function testHasIdOfAdmin() + public function testItHasTheIdOfTheAdmin() { $bans = $this->client->bans(self::TEST_ACCOUNT); diff --git a/tests/Unit/ChecksumTest.php b/tests/Unit/ChecksumTest.php new file mode 100644 index 0000000..edb0848 --- /dev/null +++ b/tests/Unit/ChecksumTest.php @@ -0,0 +1,28 @@ +client->version(); + + $this->assertIsString($version->getATSMPChecksum()->getDLL()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAnADB() + { + $version = $this->client->version(); + + $this->assertIsString($version->getATSMPChecksum()->getADB()); + } +} diff --git a/tests/Unit/VersionTest.php b/tests/Unit/VersionTest.php new file mode 100644 index 0000000..812b704 --- /dev/null +++ b/tests/Unit/VersionTest.php @@ -0,0 +1,101 @@ +client->version(); + + $this->assertInstanceOf(Version::class, $version); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAName() + { + $version = $this->client->version(); + + $this->assertIsString($version->getName()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasANumeric() + { + $version = $this->client->version(); + + $this->assertIsString($version->getNumeric()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAStage() + { + $version = $this->client->version(); + + $this->assertIsString($version->getStage()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAnETS2MPChecksum() + { + $version = $this->client->version(); + + $this->assertInstanceOf(Checksum::class, $version->getETS2MPChecksum()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAnATSMPChecksum() + { + $version = $this->client->version(); + + $this->assertInstanceOf(Checksum::class, $version->getATSMPChecksum()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasATime() + { + $version = $this->client->version(); + + $this->assertInstanceOf(Carbon::class, $version->getTime()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasASupportedGameVersion() + { + $version = $this->client->version(); + + $this->assertIsString($version->getSupportedGameVersion()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasASupportedATSGameVersion() + { + $version = $this->client->version(); + + $this->assertIsString($version->getSupportedATSGameVersion()); + } +} From aff8548838308d52972d4bee5cccabae2b1fedf8 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 17 Nov 2019 01:25:05 +0000 Subject: [PATCH 042/123] Refactored the Game and Rule models --- src/Client.php | 23 ++++---- .../{RequestHelper.php => Request.php} | 2 +- src/Models/GameTime.php | 53 +++++++++++++++++ src/Models/Rule.php | 47 +++++++++++++++ tests/BansTest.php | 58 ------------------- tests/GameTimeTest.php | 40 ------------- tests/RulesTest.php | 39 ------------- tests/Unit/GameTimeTest.php | 21 +++++++ tests/Unit/RuleTest.php | 42 ++++++++++++++ tests/VersionTest.php | 47 --------------- 10 files changed, 175 insertions(+), 197 deletions(-) rename src/Helpers/{RequestHelper.php => Request.php} (98%) create mode 100644 src/Models/GameTime.php create mode 100644 src/Models/Rule.php delete mode 100644 tests/BansTest.php delete mode 100644 tests/GameTimeTest.php delete mode 100644 tests/RulesTest.php create mode 100644 tests/Unit/GameTimeTest.php create mode 100644 tests/Unit/RuleTest.php delete mode 100644 tests/VersionTest.php diff --git a/src/Client.php b/src/Client.php index b0fdd96..ac60d98 100644 --- a/src/Client.php +++ b/src/Client.php @@ -8,13 +8,12 @@ namespace TruckersMP; use TruckersMP\Collections\BansCollection; -use TruckersMP\Helpers\RequestHelper; -use TruckersMP\Models\GameTimeModel; +use TruckersMP\Helpers\Request; +use TruckersMP\Models\GameTime; use TruckersMP\Models\PlayerModel; -use TruckersMP\Models\RulesModel; +use TruckersMP\Models\Rule; use TruckersMP\Models\ServersModel; use TruckersMP\Models\Version; -use TruckersMP\Models\VersionModel; class Client { @@ -22,7 +21,7 @@ class Client const API_VERSION = 'v2'; /** - * @var RequestHelper + * @var Request */ protected $request; @@ -36,7 +35,7 @@ public function __construct(array $config = []) { $url = 'https://' . self::API_ENDPOINT . '/' . self::API_VERSION . '/'; - $this->request = new RequestHelper($url, $config); + $this->request = new Request($url, $config); } /** @@ -96,11 +95,11 @@ public function servers(): ServersModel * * @throws \Exception * @throws \Http\Client\Exception - * @return GameTimeModel + * @return GameTime */ - public function gameTime(): GameTimeModel + public function gameTime(): GameTime { - return new GameTimeModel( + return new GameTime( $this->request->execute(strtolower(preg_replace('/(?request->execute(__FUNCTION__) ); } diff --git a/src/Helpers/RequestHelper.php b/src/Helpers/Request.php similarity index 98% rename from src/Helpers/RequestHelper.php rename to src/Helpers/Request.php index eebb70e..addb611 100644 --- a/src/Helpers/RequestHelper.php +++ b/src/Helpers/Request.php @@ -6,7 +6,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter; use Http\Message\MessageFactory\GuzzleMessageFactory; -class RequestHelper +class Request { /** * @var \Http\Message\MessageFactory\GuzzleMessageFactory diff --git a/src/Models/GameTime.php b/src/Models/GameTime.php new file mode 100644 index 0000000..9c28bc1 --- /dev/null +++ b/src/Models/GameTime.php @@ -0,0 +1,53 @@ +time = Carbon::create( + $time['years'], + $time['months'], + $time['days'], + $time['hours'], + $time['minutes'] + ); + } + + /** + * @return \Carbon\Carbon + */ + public function getTime(): Carbon + { + return $this->time; + } +} diff --git a/src/Models/Rule.php b/src/Models/Rule.php new file mode 100644 index 0000000..0fe44f8 --- /dev/null +++ b/src/Models/Rule.php @@ -0,0 +1,47 @@ +rules = $rules['rules']; + $this->revision = $rules['revision']; + } + + /** + * @return string + */ + public function getRules(): string + { + return $this->rules; + } + + /** + * @return int + */ + public function getRevision(): int + { + return $this->revision; + } +} diff --git a/tests/BansTest.php b/tests/BansTest.php deleted file mode 100644 index 009fcc1..0000000 --- a/tests/BansTest.php +++ /dev/null @@ -1,58 +0,0 @@ -client = new Client(); - } - - /** - * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException - */ - public function testWeCanGetTheUsersBans() - { - $bans = $this->client->bans(self::TEST_ACCOUNT); - - if (count($bans->getBans()) > 0) { - $ban = $bans->getBans()[0]; - - if ($ban->getExpires() != null) { - $this->assertInstanceOf(Carbon::class, $ban->getExpires()); - } - - $this->assertInstanceOf(Carbon::class, $ban->getCreated()); - $this->assertIsBool($ban->isActive()); - $this->assertIsString($ban->getReason()); - $this->assertIsString($ban->getAdminName()); - $this->assertIsInt($ban->getAdminID()); - - $this->assertInstanceOf(BanModel::class, $ban); - } else { - $this->assertEquals($bans->getBans(), []); - } - - $this->assertInstanceOf(BansModel::class, $bans); - } -} diff --git a/tests/GameTimeTest.php b/tests/GameTimeTest.php deleted file mode 100644 index 44f9dad..0000000 --- a/tests/GameTimeTest.php +++ /dev/null @@ -1,40 +0,0 @@ -client = new Client(); - } - - /** - * @throws \Http\Client\Exception - */ - public function testWeCanGetTheGameTime() - { - $time = $this->client->gameTime(); - - $this->assertNotEmpty($time); - - $this->assertInstanceOf(Carbon::class, $time->getTime()); - - $this->assertInstanceOf(GameTimeModel::class, $time); - } -} diff --git a/tests/RulesTest.php b/tests/RulesTest.php deleted file mode 100644 index 931819e..0000000 --- a/tests/RulesTest.php +++ /dev/null @@ -1,39 +0,0 @@ -client = new Client(); - } - - /** - * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\APIErrorException - */ - public function testWeCanGetTheRules() - { - $rules = $this->client->rules(); - - $this->assertIsString($rules->getRules()); - $this->assertIsInt($rules->getRevision()); - - $this->assertInstanceOf(RulesModel::class, $rules); - } -} diff --git a/tests/Unit/GameTimeTest.php b/tests/Unit/GameTimeTest.php new file mode 100644 index 0000000..fac3c53 --- /dev/null +++ b/tests/Unit/GameTimeTest.php @@ -0,0 +1,21 @@ +client->gameTime(); + + $this->assertInstanceOf(GameTime::class, $time); + $this->assertInstanceOf(Carbon::class, $time->getTime()); + } +} diff --git a/tests/Unit/RuleTest.php b/tests/Unit/RuleTest.php new file mode 100644 index 0000000..edab296 --- /dev/null +++ b/tests/Unit/RuleTest.php @@ -0,0 +1,42 @@ +client->rules(); + + $this->assertInstanceOf(Rule::class, $rules); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\APIErrorException + */ + public function testItHasTheRules() + { + $rules = $this->client->rules(); + + $this->assertIsString($rules->getRules()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\APIErrorException + */ + public function testItHasTheRevision() + { + $rules = $this->client->rules(); + + $this->assertIsInt($rules->getRevision()); + } +} diff --git a/tests/VersionTest.php b/tests/VersionTest.php deleted file mode 100644 index a65c2c3..0000000 --- a/tests/VersionTest.php +++ /dev/null @@ -1,47 +0,0 @@ -client = new Client(); - } - - /** - * @throws \Http\Client\Exception - */ - public function testWeCanGetTheVersionDetails() - { - $version = $this->client->version(); - - $this->assertIsString($version->getVersion()->human); - $this->assertIsString($version->getVersion()->stage); - $this->assertIsString($version->getVersion()->nummeric); - - $this->assertIsString($version->getChecksum()->atsmp->dll); - $this->assertIsString($version->getChecksum()->atsmp->adb); - $this->assertIsString($version->getChecksum()->ets2mp->dll); - $this->assertIsString($version->getChecksum()->ets2mp->adb); - - $this->assertInstanceOf(Carbon::class, $version->getReleased()); - - $this->assertIsString($version->getSupport()->ets2); - $this->assertIsString($version->getSupport()->ats); - } -} From 7d31f6d63a6d5a979ac1de7b02bd3409d2fb9471 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 17 Nov 2019 02:14:31 +0000 Subject: [PATCH 043/123] Updated the server and player model --- .gitignore | 2 +- src/Client.php | 27 +- .../{BansCollection.php => BanCollection.php} | 4 +- src/Collections/Collection.php | 2 +- src/Collections/ServerCollection.php | 36 ++ src/Models/Player.php | 195 ++++++++++ src/Models/Server.php | 351 ++++++++++++++++++ tests/PlayerTest.php | 136 ------- tests/ServersTest.php | 78 ---- tests/Unit/BanTest.php | 4 +- tests/Unit/PlayerTest.php | 132 +++++++ tests/Unit/ServerTest.php | 272 ++++++++++++++ 12 files changed, 1006 insertions(+), 233 deletions(-) rename src/Collections/{BansCollection.php => BanCollection.php} (88%) create mode 100644 src/Collections/ServerCollection.php create mode 100644 src/Models/Player.php create mode 100644 src/Models/Server.php delete mode 100644 tests/PlayerTest.php delete mode 100644 tests/ServersTest.php create mode 100644 tests/Unit/PlayerTest.php create mode 100644 tests/Unit/ServerTest.php diff --git a/.gitignore b/.gitignore index d257e62..4907691 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,6 @@ composer.phar /.idea/ # Unit Tests -/Tests/cache/ +/tests/cache/ diff --git a/src/Client.php b/src/Client.php index ac60d98..43cfda5 100644 --- a/src/Client.php +++ b/src/Client.php @@ -7,12 +7,12 @@ namespace TruckersMP; -use TruckersMP\Collections\BansCollection; +use TruckersMP\Collections\BanCollection; +use TruckersMP\Collections\ServerCollection; use TruckersMP\Helpers\Request; use TruckersMP\Models\GameTime; -use TruckersMP\Models\PlayerModel; +use TruckersMP\Models\Player; use TruckersMP\Models\Rule; -use TruckersMP\Models\ServersModel; use TruckersMP\Models\Version; class Client @@ -46,11 +46,11 @@ public function __construct(array $config = []) * @param int $id * @throws \Exception * @throws \Http\Client\Exception - * @return PlayerModel + * @return Player */ - public function player(int $id): PlayerModel + public function player(int $id): Player { - return new PlayerModel( + return new Player( $this->request->execute(__FUNCTION__ . '/' . $id) ); } @@ -61,13 +61,14 @@ public function player(int $id): PlayerModel * https://stats.truckersmp.com/api#ban_lookup * * @param int $id + * + * @return BanCollection + *@throws \Http\Client\Exception * @throws \Exception - * @throws \Http\Client\Exception - * @return BansCollection */ - public function bans(int $id): BansCollection + public function bans(int $id): BanCollection { - return new BansCollection( + return new BanCollection( $this->request->execute(__FUNCTION__ . '/' . $id) ); } @@ -79,11 +80,11 @@ public function bans(int $id): BansCollection * * @throws \Exception * @throws \Http\Client\Exception - * @return ServersModel + * @return ServerCollection */ - public function servers(): ServersModel + public function servers(): ServerCollection { - return new ServersModel( + return new ServerCollection( $this->request->execute(__FUNCTION__) ); } diff --git a/src/Collections/BansCollection.php b/src/Collections/BanCollection.php similarity index 88% rename from src/Collections/BansCollection.php rename to src/Collections/BanCollection.php index a44a6f5..e3013e5 100644 --- a/src/Collections/BansCollection.php +++ b/src/Collections/BanCollection.php @@ -4,10 +4,10 @@ use TruckersMP\Models\Ban; -class BansCollection extends Collection +class BanCollection extends Collection { /** - * Create a new BansCollection instance. + * Create a new BanCollection instance. * * @param array $response */ diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index 63f522b..179d23d 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -39,7 +39,7 @@ class Collection implements Iterator, ArrayAccess */ public function getValue(int $index = null): array { - if ($index) { + if ($index != null) { if (! isset($this->collection[$index])) { throw new IndexNotFoundException(); } diff --git a/src/Collections/ServerCollection.php b/src/Collections/ServerCollection.php new file mode 100644 index 0000000..89f0b42 --- /dev/null +++ b/src/Collections/ServerCollection.php @@ -0,0 +1,36 @@ +position = 0; + + // handle error + + foreach ($response['response'] as $key => $server) { + $this->collection[$key] = new Server($server); + } + } + + /** + * Get the servers. + * + * @param int|null $index + * @return Server[] + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function getServers(?int $index = null): array + { + return $this->getValue($index); + } +} diff --git a/src/Models/Player.php b/src/Models/Player.php new file mode 100644 index 0000000..d932c48 --- /dev/null +++ b/src/Models/Player.php @@ -0,0 +1,195 @@ +id = $player['id']; + $this->name = $player['name']; + $this->avatar = $player['avatar']; + $this->joinDate = new Carbon($player['joinDate'], 'UTC'); + $this->steamID64 = $player['steamID64']; + $this->groupID = $player['groupID']; + $this->groupName = $player['groupName']; + $this->isBanned = $player['banned']; + $this->bannedUntil = new Carbon($player['bannedUntil'], 'UTC'); + $this->displayBans = $player['displayBans']; + $this->inGameAdmin = $player['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 Carbon + */ + public function getJoinDate(): Carbon + { + 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 isBanned(): bool + { + return $this->isBanned; + } + + /** + * @return \Carbon\Carbon|null + */ + public function getBannedUntilDate(): ?Carbon + { + return $this->bannedUntil; + } + + /** + * @return bool + */ + public function hasBansHidden(): bool + { + return !$this->displayBans; + } + + /** + * @return bool + */ + public function isAdmin(): bool + { + return $this->inGameAdmin; + } +} diff --git a/src/Models/Server.php b/src/Models/Server.php new file mode 100644 index 0000000..3eb150f --- /dev/null +++ b/src/Models/Server.php @@ -0,0 +1,351 @@ +id = $server['id']; + $this->game = $server['game']; + $this->ip = $server['ip']; + $this->port = intval($server['port']); + $this->name = $server['name']; + $this->shortName = $server['shortname']; + $this->idPrefix = $server['idprefix']; + $this->online = boolval($server['online']); + $this->players = intval($server['players']); + $this->queue = intval($server['queue']); + $this->maxPlayers = intval($server['maxplayers']); + $this->displayOrder = intval($server['displayorder']); + $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->event = boolval($server['event']); + $this->specialEvent = boolval($server['specialEvent']); + $this->promods = boolval($server['promods']); + $this->syncDelay = intval($server['syncdelay']); + } + + /** + * @return int + */ + public function getId() + { + 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 string|null + */ + public function getIdPrefix(): ?string + { + return $this->idPrefix; + } + + /** + * @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 int + */ + public function getDisplayOrder(): int + { + return $this->displayOrder; + } + + /** + * @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 isEvent(): bool + { + return $this->event; + } + + /** + * @return bool + */ + public function isSpecialEvent(): bool + { + return $this->specialEvent; + } + + /** + * @return bool + */ + public function hasPromods(): bool + { + return $this->promods; + } + + /** + * @return bool + */ + public function hasSyncDelay(): bool + { + return $this->syncDelay; + } +} diff --git a/tests/PlayerTest.php b/tests/PlayerTest.php deleted file mode 100644 index e07ac60..0000000 --- a/tests/PlayerTest.php +++ /dev/null @@ -1,136 +0,0 @@ -client = new Client(); - $this->player = $this->client->player(self::TEST_ACCOUNT); - } - - /** @test */ - public function testWeCanGetThePlayer() - { - $this->assertInstanceOf(PlayerModel::class, $this->player); - } - - /** @test */ - public function testWeCanGetThePlayerId() - { - $this->assertIsInt($this->player->getId()); - } - - /** @test */ - public function testWeCanGetThePlayerName() - { - $this->assertIsString($this->player->getName()); - } - - /** @test */ - public function testWeCanGetThePlayersAvatar() - { - $this->assertIsString($this->player->getAvatar()); - } - - /** @test */ - public function testWeCanGetThePlayerJoinDate() - { - $this->assertInstanceOf(Carbon::class, $this->player->getJoinDate()); - } - - /** @test */ - public function testWeCanGetThePlayersSteamId() - { - $this->assertIsString($this->player->getSteamID64()); - } - - /** @test */ - public function testWeCanGetThePlayersGroupName() - { - $this->assertIsString($this->player->getGroupName()); - } - - /** @test */ - public function testWeCanGetThePlayersGroupID() - { - $this->assertIsInt($this->player->getGroupID()); - } - - /** @test */ - public function testWeCanGetIfThePlayerIsBanned() - { - $this->assertIsBool($this->player->isBanned()); - } - - /** @test */ - public function testWeCanGetWhenThePlayerIsBannedTill() - { - $this->assertInstanceOf(Carbon::class, $this->player->getBannedUntil()); - } - - /** @test */ - public function testWeCanGetIfThePlayersBansArePublic() - { - $this->assertIsBool($this->player->hasBansHidden()); - } - - /** @test */ - public function testIfTheUserIsAdmin() - { - $this->assertIsBool($this->player->isAdmin()); - } - - /** @test */ - public function testWeCanGetThePlayersVTCId() - { - $this->assertIsInt($this->player->getVTC()->id); - } - - /** @test */ - public function testWeCanGetThePlayersVTCName() - { - $this->assertIsString($this->player->getVTC()->name); - } - - /** @test */ - public function testWeCanGetThePlayersVTCTag() - { - $this->assertIsString($this->player->getVTC()->tag); - } - - /** @test */ - public function testIfThePlayerIsInAVTC() - { - $this->assertIsBool($this->player->getVTC()->inVTC); - } - - /** @test */ - public function testWeCanGetThePlayersVTCMemberID() - { - $this->assertIsInt($this->player->getVTC()->memberID); - } -} diff --git a/tests/ServersTest.php b/tests/ServersTest.php deleted file mode 100644 index cff1fea..0000000 --- a/tests/ServersTest.php +++ /dev/null @@ -1,78 +0,0 @@ -client = new Client(); - } - - /** - * @throws \Http\Client\Exception - */ - public function testWeCanGetAllTheServers() - { - $servers = $this->client->servers(); - - $this->assertInstanceOf(ServersModel::class, $servers); - } - - /** - * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException - */ - public function testWeCanGetTheServerDetails() - { - $servers = $this->client->servers(); - $server = $servers->getServers()[0]; - - $this->assertInstanceOf(ServerModel::class, $server); - - $this->assertIsInt($server->getId()); - $this->assertIsString($server->getGame()); - - $this->assertIsString($server->getIp()); - $this->assertIsInt($server->getPort()); - - $this->assertIsString($server->getName()); - $this->assertIsString($server->getShortName()); - - if ($server->getIdPrefix() != null) { - $this->assertIsString($server->getIdPrefix()); - } - - $this->assertIsBool($server->isOnline()); - $this->assertIsInt($server->getPlayers()); - $this->assertIsInt($server->getQueue()); - $this->assertIsInt($server->getMaxPlayers()); - $this->assertIsInt($server->getDisplayOrder()); - - $this->assertIsBool($server->hasSpeedLimit()); - $this->assertIsBool($server->hasCollisions()); - $this->assertIsBool($server->canPlayersHaveCars()); - $this->assertIsBool($server->canPlayersHavePoliceCars()); - $this->assertIsBool($server->isAfkEnabled()); - $this->assertIsBool($server->isEvent()); - $this->assertIsBool($server->isSpecialEvent()); - $this->assertIsBool($server->isPromods()); - - $this->assertIsBool($server->hasSyncDelay()); - } -} diff --git a/tests/Unit/BanTest.php b/tests/Unit/BanTest.php index ee4d094..2d3cb3a 100644 --- a/tests/Unit/BanTest.php +++ b/tests/Unit/BanTest.php @@ -4,7 +4,7 @@ use Carbon\Carbon; use Tests\TestCase; -use TruckersMP\Collections\BansCollection; +use TruckersMP\Collections\BanCollection; use TruckersMP\Models\Ban; class BanTest extends TestCase @@ -18,7 +18,7 @@ public function testWeCanGetAllBans() { $bans = $this->client->bans(self::TEST_ACCOUNT); - $this->assertInstanceOf(BansCollection::class, $bans); + $this->assertInstanceOf(BanCollection::class, $bans); } /** diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php new file mode 100644 index 0000000..7463d17 --- /dev/null +++ b/tests/Unit/PlayerTest.php @@ -0,0 +1,132 @@ +client->player(self::TEST_ACCOUNT); + + $this->assertInstanceOf(Player::class, $player); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAnId() + { + $player = $this->client->player(self::TEST_ACCOUNT); + + $this->assertIsInt($player->getId()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAName() + { + $player = $this->client->player(self::TEST_ACCOUNT); + + $this->assertIsString($player->getName()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAnAvatar() + { + $player = $this->client->player(self::TEST_ACCOUNT); + + $this->assertIsString($player->getAvatar()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAJoinDate() + { + $player = $this->client->player(self::TEST_ACCOUNT); + + $this->assertInstanceOf(Carbon::class, $player->getJoinDate()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasASteamId() + { + $player = $this->client->player(self::TEST_ACCOUNT); + + $this->assertIsString($player->getSteamID64()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAGroupName() + { + $player = $this->client->player(self::TEST_ACCOUNT); + + $this->assertIsString($player->getGroupName()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAGroupId() + { + $player = $this->client->player(self::TEST_ACCOUNT); + + $this->assertIsInt($player->getGroupID()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testIfItIsBanned() + { + $player = $this->client->player(self::TEST_ACCOUNT); + + $this->assertIsBool($player->isBanned()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasABannedUntilDate() + { + $player = $this->client->player(self::TEST_ACCOUNT); + + $this->assertInstanceOf(Carbon::class, $player->getBannedUntilDate()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testIfBansAreHidden() + { + $player = $this->client->player(self::TEST_ACCOUNT); + + $this->assertIsBool($player->hasBansHidden()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasIfAdmin() + { + $player = $this->client->player(self::TEST_ACCOUNT); + + $this->assertIsBool($player->isAdmin()); + } +} diff --git a/tests/Unit/ServerTest.php b/tests/Unit/ServerTest.php new file mode 100644 index 0000000..3487792 --- /dev/null +++ b/tests/Unit/ServerTest.php @@ -0,0 +1,272 @@ +client->servers(); + + $this->assertInstanceOf(ServerCollection::class, $servers); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testWeCanGetASpecificServer() + { + $servers = $this->client->servers(); + + if (count($servers->getServers()) > 0) { + $server = $servers->getServers()[0]; + + $this->assertInstanceOf(Server::class, $server); + } else { + $this->assertCount(0, $servers->getServers()); + } + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasAnId() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsInt($server->getId()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasAGame() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsString($server->getGame()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasAnIp() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsString($server->getIp()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasAPort() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsInt($server->getPort()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasAName() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsString($server->getName()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasAShortName() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsString($server->getShortName()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasAnIdPrefix() + { + $server = $this->client->servers()->getServers()[0]; + + if ($server->getIdPrefix() != null) { + $this->assertIsString($server->getIdPrefix()); + } else { + $this->assertNull($server->getIdPrefix()); + } + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasAnOnlineState() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsBool($server->isOnline()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasPlayers() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsInt($server->getPlayers()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasAQueue() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsInt($server->getQueue()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasMaxPlayers() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsInt($server->getMaxPlayers()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasADisplayOrder() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsInt($server->getDisplayOrder()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasASpeedLimit() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsBool($server->hasSpeedLimit()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasCollisions() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsBool($server->hasCollisions()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasCarsForPlayers() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsBool($server->canPlayersHaveCars()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasPoliceCarsForPlayers() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsBool($server->canPlayersHavePoliceCars()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasAfkEnable() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsBool($server->isAfkEnabled()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasAnEvent() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsBool($server->isEvent()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasASpecialEvent() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsBool($server->isSpecialEvent()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasPromods() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsBool($server->hasPromods()); + } + + /** + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\IndexNotFoundException + */ + public function testItHasSyncDelay() + { + $server = $this->client->servers()->getServers()[0]; + + $this->assertIsBool($server->hasSyncDelay()); + } +} From 82b61ffadb29b25a62c8c772db75cd293c6105a8 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 17 Nov 2019 02:20:20 +0000 Subject: [PATCH 044/123] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fe87355..743e839 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,6 @@ before_script: script: - vendor/bin/phpunit - vendor/bin/phpcs src --standard=PSR2 - - vendor/bin/phpcs Tests --standard=PSR2 + - vendor/bin/phpcs tests/Unit --standard=PSR2 From 20dc0830b817ed0e8f080cfa4e269c8b2c346a99 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 17 Nov 2019 09:27:26 +0000 Subject: [PATCH 045/123] Undeprecated the version method --- src/Client.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 43cfda5..9b4acc2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -106,8 +106,6 @@ public function gameTime(): GameTime } /** - * @deprecated - * * Information about the current TruckersMP version for ETS2 and ATS * * https://stats.truckersmp.com/api#truckersmp_version From 3f0e330b6e115f7f4320cac9370477e46223c8ae Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 17 Nov 2019 14:39:56 +0000 Subject: [PATCH 046/123] Added the ability to get a companies information --- src/Client.php | 17 ++ src/Models/Company.php | 335 +++++++++++++++++++++++++++++++++++++ src/Models/Game.php | 44 +++++ src/Models/Social.php | 95 +++++++++++ tests/Unit/CompanyTest.php | 252 ++++++++++++++++++++++++++++ 5 files changed, 743 insertions(+) create mode 100644 src/Models/Company.php create mode 100644 src/Models/Game.php create mode 100644 src/Models/Social.php create mode 100644 tests/Unit/CompanyTest.php diff --git a/src/Client.php b/src/Client.php index 9b4acc2..6b06c44 100644 --- a/src/Client.php +++ b/src/Client.php @@ -10,6 +10,7 @@ use TruckersMP\Collections\BanCollection; use TruckersMP\Collections\ServerCollection; use TruckersMP\Helpers\Request; +use TruckersMP\Models\Company; use TruckersMP\Models\GameTime; use TruckersMP\Models\Player; use TruckersMP\Models\Rule; @@ -105,6 +106,22 @@ public function gameTime(): GameTime ); } + /** + * Get the company information for the company with the specified ID. + * + * https://stats.truckersmp.com/api#vtc_info + * + * @param int $id + * @return \TruckersMP\Models\Company + * @throws \Http\Client\Exception + */ + public function company(int $id): Company + { + return new Company( + $this->request->execute('vtc/' . $id) + ); + } + /** * Information about the current TruckersMP version for ETS2 and ATS * diff --git a/src/Models/Company.php b/src/Models/Company.php new file mode 100644 index 0000000..73de80f --- /dev/null +++ b/src/Models/Company.php @@ -0,0 +1,335 @@ +id = $company['id']; + $this->name = $company['name']; + $this->ownerId = $company['owner_id']; + $this->ownerName = $company['owner_username']; + $this->slogan = $company['slogan']; + $this->tag = $company['tag']; + $this->logo = $company['logo']; + $this->cover = $company['cover']; + $this->information = $company['information']; + $this->rules = $company['rules']; + $this->requirements = $company['requirements']; + $this->website = $company['website']; + + $this->social = new Social( + $company['socials']['twitter'], + $company['socials']['facebook'], + $company['socials']['playstv'], + $company['socials']['discord'], + $company['socials']['youtube'] + ); + + $this->games = new Game( + $company['games']['ats'], + $company['games']['ets'] + ); + + $this->membersCount = intval($company['members_count']); + $this->recruitment = $company['recruitment']; + $this->language = $company['language']; + $this->verified = boolval($company['verified']); + $this->createdAt = new Carbon($company['created'], 'UTC'); + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return int + */ + public function getOwnerId(): int + { + return $this->ownerId; + } + + /** + * @return string + */ + public function getOwnerName(): string + { + return $this->ownerName; + } + + /** + * @return string + */ + public function getSlogan(): string + { + return $this->slogan; + } + + /** + * @return string + */ + public function getTag(): string + { + return $this->tag; + } + + /** + * @return string + */ + public function getLogo(): string + { + return $this->logo; + } + + /** + * @return string + */ + public function getCover(): string + { + return $this->cover; + } + + /** + * @return string + */ + public function getInformation(): string + { + return $this->information; + } + + /** + * @return string + */ + public function getRules(): string + { + return $this->rules; + } + + /** + * @return string + */ + public function getRequirements(): string + { + return $this->requirements; + } + + /** + * @return string + */ + public function getWebsite(): string + { + return $this->website; + } + + /** + * @return \TruckersMP\Models\Social + */ + public function getSocial(): Social + { + return $this->social; + } + + /** + * @return \TruckersMP\Models\Game + */ + public function getGames(): Game + { + return $this->games; + } + + /** + * @return int + */ + public function getMembersCount(): int + { + return $this->membersCount; + } + + /** + * @return string + */ + public function getRecruitment(): string + { + return $this->recruitment; + } + + /** + * @return string + */ + public function getLanguage(): string + { + return $this->language; + } + + /** + * @return bool + */ + public function isVerified(): bool + { + return $this->verified; + } + + /** + * @return \Carbon\Carbon + */ + public function getCreatedDate(): Carbon + { + return $this->createdAt; + } +} diff --git a/src/Models/Game.php b/src/Models/Game.php new file mode 100644 index 0000000..5c66bb4 --- /dev/null +++ b/src/Models/Game.php @@ -0,0 +1,44 @@ +ats = $ats; + $this->ets = $ets; + } + + /** + * @return bool + */ + public function isAts(): bool + { + return $this->ats; + } + + /** + * @return bool + */ + public function isEts(): bool + { + return $this->ets; + } +} diff --git a/src/Models/Social.php b/src/Models/Social.php new file mode 100644 index 0000000..52ad51d --- /dev/null +++ b/src/Models/Social.php @@ -0,0 +1,95 @@ +twitter = $twitter; + $this->facebook = $facebook; + $this->plays = $plays; + $this->discord = $discord; + $this->youtube = $youtube; + } + + /** + * @return string|null + */ + public function getTwitter(): ?string + { + return $this->twitter; + } + + /** + * @return string|null + */ + public function getFacebook(): ?string + { + return $this->facebook; + } + + /** + * @return string|null + */ + public function getPlays(): ?string + { + return $this->plays; + } + + /** + * @return string|null + */ + public function getDiscord(): ?string + { + return $this->discord; + } + + /** + * @return string|null + */ + public function getYoutube(): ?string + { + return $this->youtube; + } +} diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php new file mode 100644 index 0000000..79cb5ba --- /dev/null +++ b/tests/Unit/CompanyTest.php @@ -0,0 +1,252 @@ +client->company(self::TEST_COMPANY); + + $this->assertInstanceOf(Company::class, $company); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAnId() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsInt($company->getId()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAName() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsString($company->getName()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAnOwnerId() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsInt($company->getOwnerId()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAnOwnerName() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsString($company->getOwnerName()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasASlogan() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsString($company->getSlogan()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasATag() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsString($company->getTag()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasALogo() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsString($company->getLogo()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasACover() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsString($company->getCover()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasInformation() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsString($company->getInformation()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasRules() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsString($company->getRules()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasRequirements() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsString($company->getRequirements()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasAWebsite() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsString($company->getWebsite()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasSocialInformation() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertInstanceOf(Social::class, $company->getSocial()); + + // Twitter + if ($company->getSocial()->getTwitter() != null) { + $this->assertIsString($company->getSocial()->getTwitter()); + } else { + $this->assertNull($company->getSocial()->getTwitter()); + } + + // Facebook + if ($company->getSocial()->getFacebook() != null) { + $this->assertIsString($company->getSocial()->getFacebook()); + } else { + $this->assertNull($company->getSocial()->getFacebook()); + } + + // PlaysTV + if ($company->getSocial()->getPlays() != null) { + $this->assertIsString($company->getSocial()->getPlays()); + } else { + $this->assertNull($company->getSocial()->getPlays()); + } + + // Discord + if ($company->getSocial()->getDiscord() != null) { + $this->assertIsString($company->getSocial()->getDiscord()); + } else { + $this->assertNull($company->getSocial()->getDiscord()); + } + + // YouTube + if ($company->getSocial()->getYouTube() != null) { + $this->assertIsString($company->getSocial()->getYouTube()); + } else { + $this->assertNull($company->getSocial()->getYouTube()); + } + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasSupportedGames() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertInstanceOf(Game::class, $company->getGames()); + + $this->assertIsBool($company->getGames()->isAts()); + $this->assertIsBool($company->getGames()->isEts()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasMemberCount() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsInt($company->getMembersCount()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasARecruitmentState() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsString($company->getRecruitment()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasALanguage() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsString($company->getLanguage()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testIfItsVerified() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertIsBool($company->isVerified()); + } + + /** + * @throws \Http\Client\Exception + */ + public function testItHasACreatedDate() + { + $company = $this->client->company(self::TEST_COMPANY); + + $this->assertInstanceOf(Carbon::class, $company->getCreatedDate()); + } +} From 2b3bf75e33aa1dd60bf5ecd6dcb44ad6a53f8ff0 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 17 Nov 2019 17:16:55 +0000 Subject: [PATCH 047/123] Fixed offsetGet in the Collection class --- src/Collections/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index 179d23d..729c3c1 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -120,7 +120,7 @@ public function offsetExists($offset) */ public function offsetGet($offset) { - return isset($this->collection[$offset]) ?: null; + return $this->collection[$offset] ?? null; } /** From fb8dc9d8a17b3b4bc68f176d2a64f9f2cd54dfc3 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 17 Nov 2019 21:59:27 +0000 Subject: [PATCH 048/123] We now cache the player information --- composer.json | 3 +- composer.lock | 196 +++++++++++++++++++++++++++++++++++++- tests/TestCase.php | 32 +++++++ tests/Unit/PlayerTest.php | 24 ++--- 4 files changed, 241 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 433d760..8fe70e2 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,8 @@ "nesbot/carbon": "^1.21", "php-http/message": "^1.2", "guzzlehttp/psr7": "^1.3", - "ext-json": "*" + "ext-json": "*", + "phpfastcache/phpfastcache": "^7.1" }, "require-dev": { "phpunit/phpunit": "^7.0", diff --git a/composer.lock b/composer.lock index 06ad471..2f520af 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": "b54a90e0e918c2b5657ba9a681bce8d9", + "content-hash": "94474e0699c1a9642266bbd9fbc3210e", "packages": [ { "name": "clue/stream-filter", @@ -305,6 +305,152 @@ ], "time": "2015-12-19T14:08:53+00:00" }, + { + "name": "phpfastcache/phpfastcache", + "version": "7.1.0", + "source": { + "type": "git", + "url": "https://github.com/PHPSocialNetwork/phpfastcache.git", + "reference": "11c7b17a824925c2b99dce10df15ba67cbef132a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPSocialNetwork/phpfastcache/zipball/11c7b17a824925c2b99dce10df15ba67cbef132a", + "reference": "11c7b17a824925c2b99dce10df15ba67cbef132a", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "php": ">=7.0", + "psr/cache": "~1.0.0", + "psr/simple-cache": "~1.0.0" + }, + "conflict": { + "basho/riak": "*", + "doctrine/couchdb": "*" + }, + "suggest": { + "ext-apc": "*", + "ext-couchbase": "*", + "ext-intl": "*", + "ext-leveldb": "*", + "ext-memcache": "*", + "ext-memcached": "*", + "ext-redis": "*", + "ext-sqlite": "*", + "ext-wincache": "*", + "ext-xcache": "*", + "mongodb/mongodb": "^1.1", + "phpfastcache/couchdb": "~1.0.0", + "phpfastcache/phpssdb": "~1.0.0", + "phpfastcache/riak-client": "~1.4.4", + "predis/predis": "~1.1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Phpfastcache\\": "lib/Phpfastcache/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Georges.L", + "email": "contact@geolim4.com", + "homepage": "https://github.com/Geolim4", + "role": "Actual Project Manager/Developer" + }, + { + "name": "Khoa Bui", + "email": "khoaofgod@gmail.com", + "homepage": "https://www.phpfastcache.com", + "role": "Former Project Developer/Original Creator" + } + ], + "description": "PHP Abstract Cache Class - Reduce your database call using cache system. PhpFastCache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.", + "homepage": "https://www.phpfastcache.com", + "keywords": [ + "LevelDb", + "abstract", + "apc", + "apcu", + "cache", + "cache class", + "caching", + "cassandra", + "cookie", + "couchbase", + "couchdb", + "files cache", + "memcache", + "memcached", + "mongodb", + "mysql cache", + "pdo cache", + "php cache", + "predis", + "redis", + "ssdb", + "wincache", + "xcache", + "zend", + "zend data cache", + "zend disk cache", + "zend memory cache", + "zend server" + ], + "time": "2019-09-15T15:11:18+00:00" + }, + { + "name": "psr/cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/cache.git", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ], + "time": "2016-08-06T20:24:11+00:00" + }, { "name": "psr/http-message", "version": "1.0.1", @@ -355,6 +501,54 @@ ], "time": "2016-08-06T14:39:51+00:00" }, + { + "name": "psr/simple-cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "time": "2017-10-23T01:57:42+00:00" + }, { "name": "ralouphie/getallheaders", "version": "2.0.5", diff --git a/tests/TestCase.php b/tests/TestCase.php index e9b840d..8e911f2 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,8 @@ namespace Tests; +use Phpfastcache\CacheManager; +use Phpfastcache\Config\ConfigurationOption; use PHPUnit\Framework\TestCase as BaseTestCase; use TruckersMP\Client; @@ -12,6 +14,8 @@ class TestCase extends BaseTestCase */ protected $client; + protected $cache; + /** * Create a new TestCase instance. */ @@ -20,5 +24,33 @@ public function __construct() parent::__construct(); $this->client = new Client(); + + CacheManager::setDefaultConfig(new ConfigurationOption([ + 'path' => __DIR__ . '/cache', + ])); + + $this->cache = CacheManager::getInstance(); + } + + /** + * Get or cache the player. + * + * @param int $id + * @return \TruckersMP\Models\Player + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function player(int $id) + { + $key = 'player_' . $id; + + $cachedPlayer = $this->cache->getItem($key); + + if (! $cachedPlayer->isHit()) { + $cachedPlayer->set($this->client->player($id))->expiresAfter(600); + $this->cache->save($cachedPlayer); + } + + return $cachedPlayer->get(); } } diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index 7463d17..277311b 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -15,7 +15,7 @@ class PlayerTest extends TestCase */ public function testWeCanGetThePlayer() { - $player = $this->client->player(self::TEST_ACCOUNT); + $player = $this->player(self::TEST_ACCOUNT); $this->assertInstanceOf(Player::class, $player); } @@ -25,7 +25,7 @@ public function testWeCanGetThePlayer() */ public function testItHasAnId() { - $player = $this->client->player(self::TEST_ACCOUNT); + $player = $this->player(self::TEST_ACCOUNT); $this->assertIsInt($player->getId()); } @@ -35,7 +35,7 @@ public function testItHasAnId() */ public function testItHasAName() { - $player = $this->client->player(self::TEST_ACCOUNT); + $player = $this->player(self::TEST_ACCOUNT); $this->assertIsString($player->getName()); } @@ -45,7 +45,7 @@ public function testItHasAName() */ public function testItHasAnAvatar() { - $player = $this->client->player(self::TEST_ACCOUNT); + $player = $this->player(self::TEST_ACCOUNT); $this->assertIsString($player->getAvatar()); } @@ -55,7 +55,7 @@ public function testItHasAnAvatar() */ public function testItHasAJoinDate() { - $player = $this->client->player(self::TEST_ACCOUNT); + $player = $this->player(self::TEST_ACCOUNT); $this->assertInstanceOf(Carbon::class, $player->getJoinDate()); } @@ -65,7 +65,7 @@ public function testItHasAJoinDate() */ public function testItHasASteamId() { - $player = $this->client->player(self::TEST_ACCOUNT); + $player = $this->player(self::TEST_ACCOUNT); $this->assertIsString($player->getSteamID64()); } @@ -75,7 +75,7 @@ public function testItHasASteamId() */ public function testItHasAGroupName() { - $player = $this->client->player(self::TEST_ACCOUNT); + $player = $this->player(self::TEST_ACCOUNT); $this->assertIsString($player->getGroupName()); } @@ -85,7 +85,7 @@ public function testItHasAGroupName() */ public function testItHasAGroupId() { - $player = $this->client->player(self::TEST_ACCOUNT); + $player = $this->player(self::TEST_ACCOUNT); $this->assertIsInt($player->getGroupID()); } @@ -95,7 +95,7 @@ public function testItHasAGroupId() */ public function testIfItIsBanned() { - $player = $this->client->player(self::TEST_ACCOUNT); + $player = $this->player(self::TEST_ACCOUNT); $this->assertIsBool($player->isBanned()); } @@ -105,7 +105,7 @@ public function testIfItIsBanned() */ public function testItHasABannedUntilDate() { - $player = $this->client->player(self::TEST_ACCOUNT); + $player = $this->player(self::TEST_ACCOUNT); $this->assertInstanceOf(Carbon::class, $player->getBannedUntilDate()); } @@ -115,7 +115,7 @@ public function testItHasABannedUntilDate() */ public function testIfBansAreHidden() { - $player = $this->client->player(self::TEST_ACCOUNT); + $player = $this->player(self::TEST_ACCOUNT); $this->assertIsBool($player->hasBansHidden()); } @@ -125,7 +125,7 @@ public function testIfBansAreHidden() */ public function testItHasIfAdmin() { - $player = $this->client->player(self::TEST_ACCOUNT); + $player = $this->player(self::TEST_ACCOUNT); $this->assertIsBool($player->isAdmin()); } From d4cc609c6434d123161322e7ebdc77e7687c3f49 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 17 Nov 2019 23:16:03 +0000 Subject: [PATCH 049/123] Added caching for all endpoints during testing --- tests/TestCase.php | 135 +++++++++++++++++++++++++++++++++++- tests/Unit/BanTest.php | 24 ++++--- tests/Unit/CompanyTest.php | 60 ++++++++++------ tests/Unit/GameTimeTest.php | 3 +- tests/Unit/PlayerTest.php | 12 ++++ tests/Unit/RuleTest.php | 9 ++- tests/Unit/ServerTest.php | 69 ++++++++++++------ tests/Unit/VersionTest.php | 27 +++++--- 8 files changed, 273 insertions(+), 66 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 8e911f2..d3030fc 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,6 +6,13 @@ use Phpfastcache\Config\ConfigurationOption; use PHPUnit\Framework\TestCase as BaseTestCase; use TruckersMP\Client; +use TruckersMP\Collections\BanCollection; +use TruckersMP\Collections\ServerCollection; +use TruckersMP\Models\Company; +use TruckersMP\Models\GameTime; +use TruckersMP\Models\Player; +use TruckersMP\Models\Rule; +use TruckersMP\Models\Version; class TestCase extends BaseTestCase { @@ -14,6 +21,9 @@ class TestCase extends BaseTestCase */ protected $client; + /** + * @var \Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface + */ protected $cache; /** @@ -40,17 +50,138 @@ public function __construct() * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ - public function player(int $id) + public function player(int $id): Player { $key = 'player_' . $id; $cachedPlayer = $this->cache->getItem($key); if (! $cachedPlayer->isHit()) { - $cachedPlayer->set($this->client->player($id))->expiresAfter(600); + $cachedPlayer->set($this->client->player($id))->expiresAfter(60); $this->cache->save($cachedPlayer); } return $cachedPlayer->get(); } + + /** + * Get or cache the bans for the player. + * + * @param int $id + * @return \TruckersMP\Collections\BanCollection + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function bans(int $id): BanCollection + { + $key = 'bans_' . $id; + + $cachedBans = $this->cache->getItem($key); + + if (! $cachedBans->isHit()) { + $cachedBans->set($this->client->bans($id))->expiresAfter(60); + $this->cache->save($cachedBans); + } + + return $cachedBans->get(); + } + + /** + * Get or cache the servers. + * + * @return ServerCollection + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function servers(): ServerCollection + { + $cachedServers = $this->cache->getItem('servers'); + + if (! $cachedServers->isHit()) { + $cachedServers->set($this->client->servers())->expiresAfter(60); + $this->cache->save($cachedServers); + } + + return $cachedServers->get(); + } + + /** + * Get or cache the game in time. + * + * @return \TruckersMP\Models\GameTime + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function gameTime(): GameTime + { + $cachedGameTime = $this->cache->getItem('game_time'); + + if (! $cachedGameTime->isHit()) { + $cachedGameTime->set($this->client->gameTime())->expiresAfter(60); + $this->cache->save($cachedGameTime); + } + + return $cachedGameTime->get(); + } + + /** + * Get or cache the company. + * + * @param int $id + * @return \TruckersMP\Models\Company + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function company(int $id): Company + { + $key = 'company_' . $id; + + $cachedCompany = $this->cache->getItem($key); + + if (! $cachedCompany->isHit()) { + $cachedCompany->set($this->client->company($id))->expiresAfter(60); + $this->cache->save($cachedCompany); + } + + return $cachedCompany->get(); + } + + /** + * Get or cache the version. + * + * @return \TruckersMP\Models\Version + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function version(): Version + { + $cachedVersion = $this->cache->getItem('version'); + + if (! $cachedVersion->isHit()) { + $cachedVersion->set($this->client->version())->expiresAfter(60); + $this->cache->save($cachedVersion); + } + + return $cachedVersion->get(); + } + + /** + * Get or cache the rules. + * + * @return \TruckersMP\Models\Rule + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\APIErrorException + */ + public function rules(): Rule + { + $cachedRules = $this->cache->getItem('rules'); + + if (! $cachedRules->isHit()) { + $cachedRules->set($this->client->rules())->expiresAfter(60); + $this->cache->save($cachedRules); + } + + return $cachedRules->get(); + } } diff --git a/tests/Unit/BanTest.php b/tests/Unit/BanTest.php index 2d3cb3a..ddaf100 100644 --- a/tests/Unit/BanTest.php +++ b/tests/Unit/BanTest.php @@ -13,10 +13,11 @@ class BanTest extends TestCase /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testWeCanGetAllBans() { - $bans = $this->client->bans(self::TEST_ACCOUNT); + $bans = $this->bans(self::TEST_ACCOUNT); $this->assertInstanceOf(BanCollection::class, $bans); } @@ -24,10 +25,11 @@ public function testWeCanGetAllBans() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testWeCanGetASpecificBan() { - $bans = $this->client->bans(self::TEST_ACCOUNT); + $bans = $this->bans(self::TEST_ACCOUNT); if (count($bans->getBans()) > 0) { $ban = $bans->getBans()[0]; @@ -41,10 +43,11 @@ public function testWeCanGetASpecificBan() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnExpiryDate() { - $bans = $this->client->bans(self::TEST_ACCOUNT); + $bans = $this->bans(self::TEST_ACCOUNT); if (count($bans->getBans()) > 0) { $ban = $bans->getBans()[0]; @@ -62,10 +65,11 @@ public function testItHasAnExpiryDate() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasACreatedDate() { - $bans = $this->client->bans(self::TEST_ACCOUNT); + $bans = $this->bans(self::TEST_ACCOUNT); if (count($bans->getBans()) > 0) { $ban = $bans->getBans()[0]; @@ -79,10 +83,11 @@ public function testItHasACreatedDate() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnActiveState() { - $bans = $this->client->bans(self::TEST_ACCOUNT); + $bans = $this->bans(self::TEST_ACCOUNT); if (count($bans->getBans()) > 0) { $ban = $bans->getBans()[0]; @@ -96,10 +101,11 @@ public function testItHasAnActiveState() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAReason() { - $bans = $this->client->bans(self::TEST_ACCOUNT); + $bans = $this->bans(self::TEST_ACCOUNT); if (count($bans->getBans()) > 0) { $ban = $bans->getBans()[0]; @@ -113,10 +119,11 @@ public function testItHasAReason() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasTheNameOfTheAdmin() { - $bans = $this->client->bans(self::TEST_ACCOUNT); + $bans = $this->bans(self::TEST_ACCOUNT); if (count($bans->getBans()) > 0) { $ban = $bans->getBans()[0]; @@ -130,10 +137,11 @@ public function testItHasTheNameOfTheAdmin() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasTheIdOfTheAdmin() { - $bans = $this->client->bans(self::TEST_ACCOUNT); + $bans = $this->bans(self::TEST_ACCOUNT); if (count($bans->getBans()) > 0) { $ban = $bans->getBans()[0]; diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index 79cb5ba..07fe776 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -14,140 +14,154 @@ class CompanyTest extends TestCase /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testWeCanGetACompany() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertInstanceOf(Company::class, $company); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnId() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsInt($company->getId()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAName() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsString($company->getName()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnOwnerId() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsInt($company->getOwnerId()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnOwnerName() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsString($company->getOwnerName()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasASlogan() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsString($company->getSlogan()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasATag() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsString($company->getTag()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasALogo() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsString($company->getLogo()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasACover() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsString($company->getCover()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasInformation() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsString($company->getInformation()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasRules() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsString($company->getRules()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasRequirements() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsString($company->getRequirements()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAWebsite() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsString($company->getWebsite()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasSocialInformation() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertInstanceOf(Social::class, $company->getSocial()); @@ -189,10 +203,11 @@ public function testItHasSocialInformation() /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasSupportedGames() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertInstanceOf(Game::class, $company->getGames()); @@ -202,50 +217,55 @@ public function testItHasSupportedGames() /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasMemberCount() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsInt($company->getMembersCount()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasARecruitmentState() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsString($company->getRecruitment()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasALanguage() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsString($company->getLanguage()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testIfItsVerified() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertIsBool($company->isVerified()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasACreatedDate() { - $company = $this->client->company(self::TEST_COMPANY); + $company = $this->company(self::TEST_COMPANY); $this->assertInstanceOf(Carbon::class, $company->getCreatedDate()); } diff --git a/tests/Unit/GameTimeTest.php b/tests/Unit/GameTimeTest.php index fac3c53..de0c1f1 100644 --- a/tests/Unit/GameTimeTest.php +++ b/tests/Unit/GameTimeTest.php @@ -10,10 +10,11 @@ class GameTimeTest extends TestCase { /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testWeCanGetTheGameTime() { - $time = $this->client->gameTime(); + $time = $this->gameTime(); $this->assertInstanceOf(GameTime::class, $time); $this->assertInstanceOf(Carbon::class, $time->getTime()); diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index 277311b..d399622 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -12,6 +12,7 @@ class PlayerTest extends TestCase /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testWeCanGetThePlayer() { @@ -22,6 +23,7 @@ public function testWeCanGetThePlayer() /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnId() { @@ -32,6 +34,7 @@ public function testItHasAnId() /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAName() { @@ -42,6 +45,7 @@ public function testItHasAName() /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnAvatar() { @@ -52,6 +56,7 @@ public function testItHasAnAvatar() /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAJoinDate() { @@ -62,6 +67,7 @@ public function testItHasAJoinDate() /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasASteamId() { @@ -72,6 +78,7 @@ public function testItHasASteamId() /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAGroupName() { @@ -82,6 +89,7 @@ public function testItHasAGroupName() /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAGroupId() { @@ -92,6 +100,7 @@ public function testItHasAGroupId() /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testIfItIsBanned() { @@ -102,6 +111,7 @@ public function testIfItIsBanned() /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasABannedUntilDate() { @@ -112,6 +122,7 @@ public function testItHasABannedUntilDate() /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testIfBansAreHidden() { @@ -122,6 +133,7 @@ public function testIfBansAreHidden() /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasIfAdmin() { diff --git a/tests/Unit/RuleTest.php b/tests/Unit/RuleTest.php index edab296..da86e30 100644 --- a/tests/Unit/RuleTest.php +++ b/tests/Unit/RuleTest.php @@ -10,10 +10,11 @@ class RuleTest extends TestCase /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\APIErrorException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testWeCanGetTheRules() { - $rules = $this->client->rules(); + $rules = $this->rules(); $this->assertInstanceOf(Rule::class, $rules); } @@ -21,10 +22,11 @@ public function testWeCanGetTheRules() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\APIErrorException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasTheRules() { - $rules = $this->client->rules(); + $rules = $this->rules(); $this->assertIsString($rules->getRules()); } @@ -32,10 +34,11 @@ public function testItHasTheRules() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\APIErrorException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasTheRevision() { - $rules = $this->client->rules(); + $rules = $this->rules(); $this->assertIsInt($rules->getRevision()); } diff --git a/tests/Unit/ServerTest.php b/tests/Unit/ServerTest.php index 3487792..37c5f58 100644 --- a/tests/Unit/ServerTest.php +++ b/tests/Unit/ServerTest.php @@ -10,10 +10,11 @@ class ServerTest extends TestCase { /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testWeCanGetAllServers() { - $servers = $this->client->servers(); + $servers = $this->servers(); $this->assertInstanceOf(ServerCollection::class, $servers); } @@ -21,10 +22,11 @@ public function testWeCanGetAllServers() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testWeCanGetASpecificServer() { - $servers = $this->client->servers(); + $servers = $this->servers(); if (count($servers->getServers()) > 0) { $server = $servers->getServers()[0]; @@ -38,10 +40,11 @@ public function testWeCanGetASpecificServer() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnId() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsInt($server->getId()); } @@ -49,10 +52,11 @@ public function testItHasAnId() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAGame() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsString($server->getGame()); } @@ -60,10 +64,11 @@ public function testItHasAGame() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnIp() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsString($server->getIp()); } @@ -71,10 +76,11 @@ public function testItHasAnIp() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAPort() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsInt($server->getPort()); } @@ -82,10 +88,11 @@ public function testItHasAPort() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAName() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsString($server->getName()); } @@ -93,10 +100,11 @@ public function testItHasAName() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAShortName() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsString($server->getShortName()); } @@ -104,10 +112,11 @@ public function testItHasAShortName() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnIdPrefix() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; if ($server->getIdPrefix() != null) { $this->assertIsString($server->getIdPrefix()); @@ -119,10 +128,11 @@ public function testItHasAnIdPrefix() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnOnlineState() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsBool($server->isOnline()); } @@ -130,10 +140,11 @@ public function testItHasAnOnlineState() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasPlayers() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsInt($server->getPlayers()); } @@ -141,10 +152,11 @@ public function testItHasPlayers() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAQueue() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsInt($server->getQueue()); } @@ -152,10 +164,11 @@ public function testItHasAQueue() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasMaxPlayers() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsInt($server->getMaxPlayers()); } @@ -163,10 +176,11 @@ public function testItHasMaxPlayers() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasADisplayOrder() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsInt($server->getDisplayOrder()); } @@ -174,10 +188,11 @@ public function testItHasADisplayOrder() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasASpeedLimit() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsBool($server->hasSpeedLimit()); } @@ -185,10 +200,11 @@ public function testItHasASpeedLimit() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasCollisions() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsBool($server->hasCollisions()); } @@ -196,10 +212,11 @@ public function testItHasCollisions() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasCarsForPlayers() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsBool($server->canPlayersHaveCars()); } @@ -207,10 +224,11 @@ public function testItHasCarsForPlayers() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasPoliceCarsForPlayers() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsBool($server->canPlayersHavePoliceCars()); } @@ -218,10 +236,11 @@ public function testItHasPoliceCarsForPlayers() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAfkEnable() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsBool($server->isAfkEnabled()); } @@ -229,10 +248,11 @@ public function testItHasAfkEnable() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnEvent() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsBool($server->isEvent()); } @@ -240,10 +260,11 @@ public function testItHasAnEvent() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasASpecialEvent() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsBool($server->isSpecialEvent()); } @@ -251,10 +272,11 @@ public function testItHasASpecialEvent() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasPromods() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsBool($server->hasPromods()); } @@ -262,10 +284,11 @@ public function testItHasPromods() /** * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasSyncDelay() { - $server = $this->client->servers()->getServers()[0]; + $server = $this->servers()->getServers()[0]; $this->assertIsBool($server->hasSyncDelay()); } diff --git a/tests/Unit/VersionTest.php b/tests/Unit/VersionTest.php index 812b704..40feae9 100644 --- a/tests/Unit/VersionTest.php +++ b/tests/Unit/VersionTest.php @@ -11,90 +11,99 @@ class VersionTest extends TestCase { /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testWeCanGetTheVersion() { - $version = $this->client->version(); + $version = $this->version(); $this->assertInstanceOf(Version::class, $version); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAName() { - $version = $this->client->version(); + $version = $this->version(); $this->assertIsString($version->getName()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasANumeric() { - $version = $this->client->version(); + $version = $this->version(); $this->assertIsString($version->getNumeric()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAStage() { - $version = $this->client->version(); + $version = $this->version(); $this->assertIsString($version->getStage()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnETS2MPChecksum() { - $version = $this->client->version(); + $version = $this->version(); $this->assertInstanceOf(Checksum::class, $version->getETS2MPChecksum()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnATSMPChecksum() { - $version = $this->client->version(); + $version = $this->version(); $this->assertInstanceOf(Checksum::class, $version->getATSMPChecksum()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasATime() { - $version = $this->client->version(); + $version = $this->version(); $this->assertInstanceOf(Carbon::class, $version->getTime()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasASupportedGameVersion() { - $version = $this->client->version(); + $version = $this->version(); $this->assertIsString($version->getSupportedGameVersion()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasASupportedATSGameVersion() { - $version = $this->client->version(); + $version = $this->version(); $this->assertIsString($version->getSupportedATSGameVersion()); } From 11b32ec221287ee4d917bc9600733581101d38c4 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Mon, 18 Nov 2019 19:00:53 +0000 Subject: [PATCH 050/123] Added the ability to get the recent and featured companies --- src/Client.php | 8 ++++ src/Collections/BanCollection.php | 2 +- src/Collections/CompanyCollection.php | 60 +++++++++++++++++++++++++++ src/Collections/ServerCollection.php | 2 +- src/Models/Company.php | 30 +++++++++++--- tests/TestCase.php | 13 ++++++ tests/Unit/CompanyTest.php | 29 +++++++++++++ 7 files changed, 136 insertions(+), 8 deletions(-) create mode 100644 src/Collections/CompanyCollection.php diff --git a/src/Client.php b/src/Client.php index 6b06c44..81959b9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -8,6 +8,7 @@ namespace TruckersMP; use TruckersMP\Collections\BanCollection; +use TruckersMP\Collections\CompanyCollection; use TruckersMP\Collections\ServerCollection; use TruckersMP\Helpers\Request; use TruckersMP\Models\Company; @@ -106,6 +107,13 @@ public function gameTime(): GameTime ); } + public function companies(): CompanyCollection + { + return new CompanyCollection( + $this->request->execute('vtc') + ); + } + /** * Get the company information for the company with the specified ID. * diff --git a/src/Collections/BanCollection.php b/src/Collections/BanCollection.php index e3013e5..651bea0 100644 --- a/src/Collections/BanCollection.php +++ b/src/Collections/BanCollection.php @@ -15,7 +15,7 @@ public function __construct(array $response) { $this->position = 0; - // handle error + // TODO: handle any errors / exceptions foreach ($response['response'] as $key => $ban) { $this->collection[$key] = new Ban($ban); diff --git a/src/Collections/CompanyCollection.php b/src/Collections/CompanyCollection.php new file mode 100644 index 0000000..c429eb2 --- /dev/null +++ b/src/Collections/CompanyCollection.php @@ -0,0 +1,60 @@ + $recentCompany) { + $this->recentCompanies[$key] = new Company($recentCompany); + } + + foreach ($response['response']['featured'] as $key => $featuredCompany) { + $this->featuredCompanies[$key] = new Company($featuredCompany); + } + } + + /** + * Get the recent companies. + * + * @return Company[] + */ + public function getRecent() + { + return $this->recentCompanies; + } + + /** + * Get the featured companies. + * + * @return Company[] + */ + public function getFeatured() + { + return $this->featuredCompanies; + } +} diff --git a/src/Collections/ServerCollection.php b/src/Collections/ServerCollection.php index 89f0b42..c5db1d3 100644 --- a/src/Collections/ServerCollection.php +++ b/src/Collections/ServerCollection.php @@ -15,7 +15,7 @@ public function __construct(array $response) { $this->position = 0; - // handle error + // TODO: handle any errors / exceptions foreach ($response['response'] as $key => $server) { $this->collection[$key] = new Server($server); diff --git a/src/Models/Company.php b/src/Models/Company.php index 73de80f..afdb876 100644 --- a/src/Models/Company.php +++ b/src/Models/Company.php @@ -146,7 +146,9 @@ class Company */ public function __construct(array $company) { - $company = $company['response']; + if (isset($company['response'])) { + $company = $company['response']; + } $this->id = $company['id']; $this->name = $company['name']; @@ -154,11 +156,27 @@ public function __construct(array $company) $this->ownerName = $company['owner_username']; $this->slogan = $company['slogan']; $this->tag = $company['tag']; - $this->logo = $company['logo']; - $this->cover = $company['cover']; - $this->information = $company['information']; - $this->rules = $company['rules']; - $this->requirements = $company['requirements']; + + if (array_key_exists('logo', $company)) { + $this->logo = $company['logo']; + } + + if (array_key_exists('cover', $company)) { + $this->cover = $company['cover']; + } + + if (array_key_exists('information', $company)) { + $this->information = $company['information']; + } + + if (array_key_exists('rules', $company)) { + $this->rules = $company['rules']; + } + + if (array_key_exists('requirements', $company)) { + $this->requirements = $company['requirements']; + } + $this->website = $company['website']; $this->social = new Social( diff --git a/tests/TestCase.php b/tests/TestCase.php index d3030fc..16e459e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\TestCase as BaseTestCase; use TruckersMP\Client; use TruckersMP\Collections\BanCollection; +use TruckersMP\Collections\CompanyCollection; use TruckersMP\Collections\ServerCollection; use TruckersMP\Models\Company; use TruckersMP\Models\GameTime; @@ -124,6 +125,18 @@ public function gameTime(): GameTime return $cachedGameTime->get(); } + public function companies(): CompanyCollection + { + $cachedCompanies = $this->cache->getItem('cache'); + + if (! $cachedCompanies->isHit()) { + $cachedCompanies->set($this->client->companies())->expiresAfter(60); + $this->cache->save($cachedCompanies); + } + + return $cachedCompanies->get(); + } + /** * Get or cache the company. * diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index 07fe776..9642b9e 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use Tests\TestCase; +use TruckersMP\Collections\CompanyCollection; use TruckersMP\Models\Company; use TruckersMP\Models\Game; use TruckersMP\Models\Social; @@ -12,6 +13,34 @@ class CompanyTest extends TestCase { const TEST_COMPANY = 1; + /** @test */ + public function testWeCanGetTheCompanies() + { + $companies = $this->companies(); + + $this->assertInstanceOf(CompanyCollection::class, $companies); + } + + /** @test */ + public function testWeCanGetTheRecentCompanies() + { + $companies = $this->companies()->getRecent(); + + $this->assertNotEmpty($companies); + + $this->assertInstanceOf(Company::class, $companies[0]); + } + + /** @test */ + public function testWeCanGetTheFeaturedCompanies() + { + $companies = $this->companies()->getFeatured(); + + $this->assertNotEmpty($companies); + + $this->assertInstanceOf(Company::class, $companies[0]); + } + /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException From adf691bb695f25bf9a000a7d7530fa2a78793552 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Mon, 18 Nov 2019 22:02:55 +0000 Subject: [PATCH 051/123] Created a request class for each method --- src/Client.php | 127 ++++++------------ src/Collections/BanCollection.php | 36 ----- src/Collections/Collection.php | 148 --------------------- src/Collections/CompanyCollection.php | 60 --------- src/Collections/ServerCollection.php | 36 ----- src/Exceptions/APIErrorException.php | 7 - src/Exceptions/IndexNotFoundException.php | 7 - src/Exceptions/PlayerNotFoundException.php | 7 - src/Helpers/Request.php | 52 -------- src/Requests/BanRequest.php | 58 ++++++++ src/Requests/CompanyRequest.php | 53 ++++++++ src/Requests/GameTimeRequest.php | 32 +++++ src/Requests/PlayerRequest.php | 51 +++++++ src/Requests/Request.php | 71 ++++++++++ src/Requests/RuleRequest.php | 31 +++++ src/Requests/ServerRequest.php | 38 ++++++ src/Requests/VersionRequest.php | 31 +++++ tests/TestCase.php | 82 +++++------- tests/Unit/BanTest.php | 60 ++++----- tests/Unit/ChecksumTest.php | 6 +- tests/Unit/CompanyTest.php | 16 +-- tests/Unit/ServerTest.php | 65 ++++----- 22 files changed, 503 insertions(+), 571 deletions(-) delete mode 100644 src/Collections/BanCollection.php delete mode 100644 src/Collections/Collection.php delete mode 100644 src/Collections/CompanyCollection.php delete mode 100644 src/Collections/ServerCollection.php delete mode 100644 src/Exceptions/APIErrorException.php delete mode 100644 src/Exceptions/IndexNotFoundException.php delete mode 100644 src/Exceptions/PlayerNotFoundException.php delete mode 100644 src/Helpers/Request.php create mode 100644 src/Requests/BanRequest.php create mode 100644 src/Requests/CompanyRequest.php create mode 100644 src/Requests/GameTimeRequest.php create mode 100644 src/Requests/PlayerRequest.php create mode 100644 src/Requests/Request.php create mode 100644 src/Requests/RuleRequest.php create mode 100644 src/Requests/ServerRequest.php create mode 100644 src/Requests/VersionRequest.php diff --git a/src/Client.php b/src/Client.php index 81959b9..82a27a4 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1,149 +1,110 @@ request = new Request($url, $config); + $this->config = $config; } /** - * Get player information by ID. + * Get the information for the player with the specified ID. * * https://stats.truckersmp.com/api#players_lookup * * @param int $id - * @throws \Exception - * @throws \Http\Client\Exception - * @return Player + * @return \TruckersMP\Requests\PlayerRequest */ - public function player(int $id): Player + public function player(int $id): PlayerRequest { - return new Player( - $this->request->execute(__FUNCTION__ . '/' . $id) - ); + return new PlayerRequest($this->config, $id); } /** - * Get bans information by player ID. + * Get the bans for the player with the specified ID. * * https://stats.truckersmp.com/api#ban_lookup * * @param int $id * - * @return BanCollection - *@throws \Http\Client\Exception - * @throws \Exception + * @return \TruckersMP\Requests\BanRequest */ - public function bans(int $id): BanCollection + public function bans(int $id): BanRequest { - return new BanCollection( - $this->request->execute(__FUNCTION__ . '/' . $id) - ); + return new BanRequest($this->config, $id); } /** - * Get server information. + * Get the information about the servers. * * https://stats.truckersmp.com/api#servers_list * - * @throws \Exception - * @throws \Http\Client\Exception - * @return ServerCollection + * @return \TruckersMP\Requests\ServerRequest */ - public function servers(): ServerCollection + public function servers(): ServerRequest { - return new ServerCollection( - $this->request->execute(__FUNCTION__) - ); + return new ServerRequest($this->config); } /** - * Get the current game time + * Get the current game time. * * https://stats.truckersmp.com/api#game_time * - * @throws \Exception - * @throws \Http\Client\Exception - * @return GameTime + * @return \TruckersMP\Requests\GameTimeRequest */ - public function gameTime(): GameTime + public function gameTime(): \TruckersMP\Requests\GameTimeRequest { - return new GameTime( - $this->request->execute(strtolower(preg_replace('/(?request->execute('vtc') - ); + return new GameTimeRequest($this->config); } /** - * Get the company information for the company with the specified ID. + * Get the information for the company with the specified ID. * * https://stats.truckersmp.com/api#vtc_info * * @param int $id - * @return \TruckersMP\Models\Company - * @throws \Http\Client\Exception + * + * @return \TruckersMP\Requests\CompanyRequest */ - public function company(int $id): Company + public function company(int $id): CompanyRequest { - return new Company( - $this->request->execute('vtc/' . $id) - ); + return new CompanyRequest($this->config, $id); } /** - * Information about the current TruckersMP version for ETS2 and ATS + * Get the TruckersMP version for ETS2 and ATS. * * https://stats.truckersmp.com/api#truckersmp_version * - * @throws \Exception - * @throws \Http\Client\Exception - * @return Version + * @return \TruckersMP\Requests\VersionRequest */ - public function version(): Version + public function version(): VersionRequest { - return new Version( - $this->request->execute(__FUNCTION__) - ); + return new VersionRequest($this->config); } /** @@ -151,14 +112,10 @@ public function version(): Version * * https://stats.truckersmp.com/api#truckersmp_rules * - * @throws \Http\Client\Exception - * @throws Exceptions\APIErrorException - * @return Rule + * @return \TruckersMP\Requests\RuleRequest */ - public function rules(): Rule + public function rules(): RuleRequest { - return new Rule( - $this->request->execute(__FUNCTION__) - ); + return new RuleRequest($this->config); } } diff --git a/src/Collections/BanCollection.php b/src/Collections/BanCollection.php deleted file mode 100644 index 651bea0..0000000 --- a/src/Collections/BanCollection.php +++ /dev/null @@ -1,36 +0,0 @@ -position = 0; - - // TODO: handle any errors / exceptions - - foreach ($response['response'] as $key => $ban) { - $this->collection[$key] = new Ban($ban); - } - } - - /** - * Get the players bans. - * - * @param int|null $index - * @return Ban[] - * @throws \TruckersMP\Exceptions\IndexNotFoundException - */ - public function getBans(?int $index = null): array - { - return $this->getValue($index); - } -} diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php deleted file mode 100644 index 729c3c1..0000000 --- a/src/Collections/Collection.php +++ /dev/null @@ -1,148 +0,0 @@ -collection[$index])) { - throw new IndexNotFoundException(); - } - - return $this->collection[$index]; - } - - return $this->collection; - } - - /** - * Return the current element. - * - * @return mixed - */ - public function current() - { - return $this->collection[$this->position]; - } - - /** - * Move forward to next element. - * - * @return void - */ - public function next() - { - $this->position++; - } - - /** - * Return the key of the current element. - * - * @return mixed - */ - public function key() - { - return $this->position; - } - - /** - * Checks if current position is valid. - * - * @return bool - */ - public function valid() - { - return isset($this->collection[$this->position]); - } - - /** - * Rewind the Iterator to the first element. - * - * @return void - */ - public function rewind() - { - $this->position = 0; - } - - /** - * Whether a offset exists. - * - * @param mixed $offset - * @return bool - */ - public function offsetExists($offset) - { - return isset($this->collection[$offset]); - } - - - /** - * Offset to retrieve. - * - * @param mixed $offset - * @return mixed|null - */ - public function offsetGet($offset) - { - return $this->collection[$offset] ?? null; - } - - /** - * Offset to set. - * - * @param mixed $offset - * @param mixed $value - * @return \Exception|void - */ - public function offsetSet($offset, $value) - { - return new Exception($this->exceptionMessage); - } - - /** - * Offset to unset. - * - * @param mixed $offset - * @return \Exception|void - */ - public function offsetUnset($offset) - { - return new Exception($this->exceptionMessage); - } -} diff --git a/src/Collections/CompanyCollection.php b/src/Collections/CompanyCollection.php deleted file mode 100644 index c429eb2..0000000 --- a/src/Collections/CompanyCollection.php +++ /dev/null @@ -1,60 +0,0 @@ - $recentCompany) { - $this->recentCompanies[$key] = new Company($recentCompany); - } - - foreach ($response['response']['featured'] as $key => $featuredCompany) { - $this->featuredCompanies[$key] = new Company($featuredCompany); - } - } - - /** - * Get the recent companies. - * - * @return Company[] - */ - public function getRecent() - { - return $this->recentCompanies; - } - - /** - * Get the featured companies. - * - * @return Company[] - */ - public function getFeatured() - { - return $this->featuredCompanies; - } -} diff --git a/src/Collections/ServerCollection.php b/src/Collections/ServerCollection.php deleted file mode 100644 index c5db1d3..0000000 --- a/src/Collections/ServerCollection.php +++ /dev/null @@ -1,36 +0,0 @@ -position = 0; - - // TODO: handle any errors / exceptions - - foreach ($response['response'] as $key => $server) { - $this->collection[$key] = new Server($server); - } - } - - /** - * Get the servers. - * - * @param int|null $index - * @return Server[] - * @throws \TruckersMP\Exceptions\IndexNotFoundException - */ - public function getServers(?int $index = null): array - { - return $this->getValue($index); - } -} diff --git a/src/Exceptions/APIErrorException.php b/src/Exceptions/APIErrorException.php deleted file mode 100644 index 3dd7956..0000000 --- a/src/Exceptions/APIErrorException.php +++ /dev/null @@ -1,7 +0,0 @@ -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(string $uri): array - { - $request = $this->message->createRequest('GET', $this->apiEndpoint . $uri); - $result = $this->adapter->sendRequest($request); - - return json_decode((string)$result->getBody(), true, 512, JSON_BIGINT_AS_STRING); - } -} diff --git a/src/Requests/BanRequest.php b/src/Requests/BanRequest.php new file mode 100644 index 0000000..fde35fb --- /dev/null +++ b/src/Requests/BanRequest.php @@ -0,0 +1,58 @@ +id = $id; + } + + /** + * Get the endpoint of the request. + * + * @return string + */ + public function getEndpoint(): string + { + return 'bans/' . $this->id; + } + + /** + * Get the data for the request. + * + * @return \TruckersMP\Models\Ban[] + * @throws \Http\Client\Exception + */ + public function get(): array + { + $bans = []; + $results = $this->call(); + + // TODO: handle any errors / exceptions + + foreach ($results['response'] as $key => $ban) { + $bans[$key] = new Ban($ban); + } + + return $bans; + } +} diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php new file mode 100644 index 0000000..70f10a4 --- /dev/null +++ b/src/Requests/CompanyRequest.php @@ -0,0 +1,53 @@ +id = $id; + } + + /** + * Get the endpoint of the request. + * + * @return string + */ + public function getEndpoint(): string + { + return 'vtc/' . $this->id; + } + + /** + * Get the data for the request. + * + * @return Company + * @throws \Http\Client\Exception + */ + public function get(): Company + { + return new Company( + $this->call() + ); + } +} diff --git a/src/Requests/GameTimeRequest.php b/src/Requests/GameTimeRequest.php new file mode 100644 index 0000000..87996d1 --- /dev/null +++ b/src/Requests/GameTimeRequest.php @@ -0,0 +1,32 @@ +call() + ); + } +} diff --git a/src/Requests/PlayerRequest.php b/src/Requests/PlayerRequest.php new file mode 100644 index 0000000..5a83b97 --- /dev/null +++ b/src/Requests/PlayerRequest.php @@ -0,0 +1,51 @@ +id = $id; + } + + /** + * Get the endpoint of the request. + * + * @return string + */ + public function getEndpoint(): string + { + return 'player/' . $this->id; + } + + /** + * Get the data for the request. + * + * @return Player + * @throws \Http\Client\Exception + */ + public function get(): Player + { + return new Player( + $this->call() + ); + } +} diff --git a/src/Requests/Request.php b/src/Requests/Request.php new file mode 100644 index 0000000..6c7e450 --- /dev/null +++ b/src/Requests/Request.php @@ -0,0 +1,71 @@ +message = new GuzzleMessageFactory(); + $this->adapter = new GuzzleAdapter( + new GuzzleClient($config) + ); + + $this->url = 'https://' . self::API_ENDPOINT . '/' . self::API_VERSION . '/'; + } + + /** + * Get the endpoint of the request. + * + * @return string + */ + abstract public function getEndpoint(): string; + + /** + * Get the data for the request. + * + * @return mixed + */ + abstract public function get(); + + /** + * Call the API endpoint and get the result. + * + * @return array + * @throws \Http\Client\Exception + */ + public function call(): array + { + $request = $this->message->createRequest('GET', $this->url . $this->getEndpoint()); + $result = $this->adapter->sendRequest($request); + + return json_decode((string)$result->getBody(), true, 512, JSON_BIGINT_AS_STRING); + } +} diff --git a/src/Requests/RuleRequest.php b/src/Requests/RuleRequest.php new file mode 100644 index 0000000..fd83237 --- /dev/null +++ b/src/Requests/RuleRequest.php @@ -0,0 +1,31 @@ +call() + ); + } +} diff --git a/src/Requests/ServerRequest.php b/src/Requests/ServerRequest.php new file mode 100644 index 0000000..c6c73b8 --- /dev/null +++ b/src/Requests/ServerRequest.php @@ -0,0 +1,38 @@ +call(); + + // TODO: handle any errors / exceptions + + foreach ($results['response'] as $key => $server) { + $servers[$key] = new Server($server); + } + + return $servers; + } +} diff --git a/src/Requests/VersionRequest.php b/src/Requests/VersionRequest.php new file mode 100644 index 0000000..5706171 --- /dev/null +++ b/src/Requests/VersionRequest.php @@ -0,0 +1,31 @@ +call() + ); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 16e459e..ed823a7 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,9 +6,6 @@ use Phpfastcache\Config\ConfigurationOption; use PHPUnit\Framework\TestCase as BaseTestCase; use TruckersMP\Client; -use TruckersMP\Collections\BanCollection; -use TruckersMP\Collections\CompanyCollection; -use TruckersMP\Collections\ServerCollection; use TruckersMP\Models\Company; use TruckersMP\Models\GameTime; use TruckersMP\Models\Player; @@ -17,6 +14,8 @@ class TestCase extends BaseTestCase { + const CACHE_SECONDS = 3600; + /** * @var \TruckersMP\Client */ @@ -29,6 +28,13 @@ class TestCase extends BaseTestCase /** * Create a new TestCase instance. + * + * @throws \Phpfastcache\Exceptions\PhpfastcacheDriverCheckException + * @throws \Phpfastcache\Exceptions\PhpfastcacheDriverException + * @throws \Phpfastcache\Exceptions\PhpfastcacheDriverNotFoundException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException + * @throws \ReflectionException */ public function __construct() { @@ -44,21 +50,20 @@ public function __construct() } /** - * Get or cache the player. + * Get or cache the given player. + * + * @param int $id * - * @param int $id * @return \TruckersMP\Models\Player * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function player(int $id): Player { - $key = 'player_' . $id; - - $cachedPlayer = $this->cache->getItem($key); + $cachedPlayer = $this->cache->getItem('player_' . $id); if (! $cachedPlayer->isHit()) { - $cachedPlayer->set($this->client->player($id))->expiresAfter(60); + $cachedPlayer->set($this->client->player($id)->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedPlayer); } @@ -68,19 +73,18 @@ public function player(int $id): Player /** * Get or cache the bans for the player. * - * @param int $id - * @return \TruckersMP\Collections\BanCollection - * @throws \Http\Client\Exception + * @param int $id + * + * @return \TruckersMP\Models\Ban[] * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \Http\Client\Exception */ - public function bans(int $id): BanCollection + public function bans(int $id): array { - $key = 'bans_' . $id; - - $cachedBans = $this->cache->getItem($key); + $cachedBans = $this->cache->getItem('bans_' . $id); if (! $cachedBans->isHit()) { - $cachedBans->set($this->client->bans($id))->expiresAfter(60); + $cachedBans->set($this->client->bans($id)->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedBans); } @@ -88,18 +92,18 @@ public function bans(int $id): BanCollection } /** - * Get or cache the servers. + * Get or cache the server request. * - * @return ServerCollection + * @return \TruckersMP\Models\Server[] * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ - public function servers(): ServerCollection + public function servers(): array { $cachedServers = $this->cache->getItem('servers'); if (! $cachedServers->isHit()) { - $cachedServers->set($this->client->servers())->expiresAfter(60); + $cachedServers->set($this->client->servers()->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedServers); } @@ -107,7 +111,7 @@ public function servers(): ServerCollection } /** - * Get or cache the game in time. + * Get or cache the game time. * * @return \TruckersMP\Models\GameTime * @throws \Http\Client\Exception @@ -118,41 +122,28 @@ public function gameTime(): GameTime $cachedGameTime = $this->cache->getItem('game_time'); if (! $cachedGameTime->isHit()) { - $cachedGameTime->set($this->client->gameTime())->expiresAfter(60); + $cachedGameTime->set($this->client->gameTime()->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedGameTime); } return $cachedGameTime->get(); } - public function companies(): CompanyCollection - { - $cachedCompanies = $this->cache->getItem('cache'); - - if (! $cachedCompanies->isHit()) { - $cachedCompanies->set($this->client->companies())->expiresAfter(60); - $this->cache->save($cachedCompanies); - } - - return $cachedCompanies->get(); - } - /** - * Get or cache the company. + * Get or cache the company with the specified id. + * + * @param int $id * - * @param int $id * @return \TruckersMP\Models\Company - * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \Http\Client\Exception */ public function company(int $id): Company { - $key = 'company_' . $id; - - $cachedCompany = $this->cache->getItem($key); + $cachedCompany = $this->cache->getItem('company_' . $id); if (! $cachedCompany->isHit()) { - $cachedCompany->set($this->client->company($id))->expiresAfter(60); + $cachedCompany->set($this->client->company($id)->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedCompany); } @@ -160,7 +151,7 @@ public function company(int $id): Company } /** - * Get or cache the version. + * Get or cache the TruckersMP version. * * @return \TruckersMP\Models\Version * @throws \Http\Client\Exception @@ -171,7 +162,7 @@ public function version(): Version $cachedVersion = $this->cache->getItem('version'); if (! $cachedVersion->isHit()) { - $cachedVersion->set($this->client->version())->expiresAfter(60); + $cachedVersion->set($this->client->version()->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedVersion); } @@ -184,14 +175,13 @@ public function version(): Version * @return \TruckersMP\Models\Rule * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\APIErrorException */ public function rules(): Rule { $cachedRules = $this->cache->getItem('rules'); if (! $cachedRules->isHit()) { - $cachedRules->set($this->client->rules())->expiresAfter(60); + $cachedRules->set($this->client->rules()->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedRules); } diff --git a/tests/Unit/BanTest.php b/tests/Unit/BanTest.php index ddaf100..e1c8200 100644 --- a/tests/Unit/BanTest.php +++ b/tests/Unit/BanTest.php @@ -19,24 +19,10 @@ public function testWeCanGetAllBans() { $bans = $this->bans(self::TEST_ACCOUNT); - $this->assertInstanceOf(BanCollection::class, $bans); - } + $this->assertIsArray($bans); - /** - * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException - * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - */ - public function testWeCanGetASpecificBan() - { - $bans = $this->bans(self::TEST_ACCOUNT); - - if (count($bans->getBans()) > 0) { - $ban = $bans->getBans()[0]; - - $this->assertInstanceOf(Ban::class, $ban); - } else { - $this->assertCount(0, $bans->getBans()); + if (count($bans) > 0) { + $this->assertInstanceOf(Ban::class, $bans[0]); } } @@ -49,8 +35,8 @@ public function testItHasAnExpiryDate() { $bans = $this->bans(self::TEST_ACCOUNT); - if (count($bans->getBans()) > 0) { - $ban = $bans->getBans()[0]; + if (count($bans) > 0) { + $ban = $bans[0]; if ($ban->getExpirationDate() != null) { $this->assertInstanceOf(Carbon::class, $ban->getExpirationDate()); @@ -58,7 +44,7 @@ public function testItHasAnExpiryDate() $this->assertNull($ban->getExpirationDate()); } } else { - $this->assertCount(0, $bans->getBans()); + $this->assertCount(0, $bans); } } @@ -71,12 +57,12 @@ public function testItHasACreatedDate() { $bans = $this->bans(self::TEST_ACCOUNT); - if (count($bans->getBans()) > 0) { - $ban = $bans->getBans()[0]; + if (count($bans) > 0) { + $ban = $bans[0]; $this->assertInstanceOf(Carbon::class, $ban->getCreatedDate()); } else { - $this->assertCount(0, $bans->getBans()); + $this->assertCount(0, $bans); } } @@ -89,12 +75,12 @@ public function testItHasAnActiveState() { $bans = $this->bans(self::TEST_ACCOUNT); - if (count($bans->getBans()) > 0) { - $ban = $bans->getBans()[0]; + if (count($bans) > 0) { + $ban = $bans[0]; $this->assertIsBool($ban->isActive()); } else { - $this->assertCount(0, $bans->getBans()); + $this->assertCount(0, $bans); } } @@ -107,48 +93,48 @@ public function testItHasAReason() { $bans = $this->bans(self::TEST_ACCOUNT); - if (count($bans->getBans()) > 0) { - $ban = $bans->getBans()[0]; + if (count($bans) > 0) { + $ban = $bans[0]; $this->assertIsString($ban->getReason()); } else { - $this->assertCount(0, $bans->getBans()); + $this->assertCount(0, $bans); } } /** - * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \Http\Client\Exception */ public function testItHasTheNameOfTheAdmin() { $bans = $this->bans(self::TEST_ACCOUNT); - if (count($bans->getBans()) > 0) { - $ban = $bans->getBans()[0]; + if (count($bans) > 0) { + $ban = $bans[0]; $this->assertIsString($ban->getAdminName()); } else { - $this->assertCount(0, $bans->getBans()); + $this->assertCount(0, $bans); } } /** - * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \Http\Client\Exception */ public function testItHasTheIdOfTheAdmin() { $bans = $this->bans(self::TEST_ACCOUNT); - if (count($bans->getBans()) > 0) { - $ban = $bans->getBans()[0]; + if (count($bans) > 0) { + $ban = $bans[0]; $this->assertIsInt($ban->getAdminId()); } else { - $this->assertCount(0, $bans->getBans()); + $this->assertCount(0, $bans); } } } diff --git a/tests/Unit/ChecksumTest.php b/tests/Unit/ChecksumTest.php index edb0848..eece854 100644 --- a/tests/Unit/ChecksumTest.php +++ b/tests/Unit/ChecksumTest.php @@ -8,20 +8,22 @@ class ChecksumTest extends TestCase { /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasADLL() { - $version = $this->client->version(); + $version = $this->version(); $this->assertIsString($version->getATSMPChecksum()->getDLL()); } /** * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testItHasAnADB() { - $version = $this->client->version(); + $version = $this->version(); $this->assertIsString($version->getATSMPChecksum()->getADB()); } diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index 9642b9e..4b20596 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -14,43 +14,43 @@ class CompanyTest extends TestCase const TEST_COMPANY = 1; /** @test */ - public function testWeCanGetTheCompanies() + /**public function testWeCanGetTheCompanies() { $companies = $this->companies(); $this->assertInstanceOf(CompanyCollection::class, $companies); - } + }*/ /** @test */ - public function testWeCanGetTheRecentCompanies() + /*public function testWeCanGetTheRecentCompanies() { $companies = $this->companies()->getRecent(); $this->assertNotEmpty($companies); $this->assertInstanceOf(Company::class, $companies[0]); - } + }*/ /** @test */ - public function testWeCanGetTheFeaturedCompanies() + /*public function testWeCanGetTheFeaturedCompanies() { $companies = $this->companies()->getFeatured(); $this->assertNotEmpty($companies); $this->assertInstanceOf(Company::class, $companies[0]); - } + }*/ /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ - public function testWeCanGetACompany() + /*public function testWeCanGetACompany() { $company = $this->company(self::TEST_COMPANY); $this->assertInstanceOf(Company::class, $company); - } + }*/ /** * @throws \Http\Client\Exception diff --git a/tests/Unit/ServerTest.php b/tests/Unit/ServerTest.php index 37c5f58..3191c3a 100644 --- a/tests/Unit/ServerTest.php +++ b/tests/Unit/ServerTest.php @@ -3,7 +3,6 @@ namespace Tests\Unit; use Tests\TestCase; -use TruckersMP\Collections\ServerCollection; use TruckersMP\Models\Server; class ServerTest extends TestCase @@ -12,28 +11,14 @@ class ServerTest extends TestCase * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ - public function testWeCanGetAllServers() + public function testWeCanGetAllTheServers() { $servers = $this->servers(); - $this->assertInstanceOf(ServerCollection::class, $servers); - } + $this->assertIsArray($servers); - /** - * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException - * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - */ - public function testWeCanGetASpecificServer() - { - $servers = $this->servers(); - - if (count($servers->getServers()) > 0) { - $server = $servers->getServers()[0]; - - $this->assertInstanceOf(Server::class, $server); - } else { - $this->assertCount(0, $servers->getServers()); + if (count($servers) > 0) { + $this->assertInstanceOf(Server::class, $servers[0]); } } @@ -44,7 +29,7 @@ public function testWeCanGetASpecificServer() */ public function testItHasAnId() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsInt($server->getId()); } @@ -56,7 +41,7 @@ public function testItHasAnId() */ public function testItHasAGame() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsString($server->getGame()); } @@ -68,7 +53,7 @@ public function testItHasAGame() */ public function testItHasAnIp() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsString($server->getIp()); } @@ -80,7 +65,7 @@ public function testItHasAnIp() */ public function testItHasAPort() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsInt($server->getPort()); } @@ -92,7 +77,7 @@ public function testItHasAPort() */ public function testItHasAName() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsString($server->getName()); } @@ -104,7 +89,7 @@ public function testItHasAName() */ public function testItHasAShortName() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsString($server->getShortName()); } @@ -116,7 +101,7 @@ public function testItHasAShortName() */ public function testItHasAnIdPrefix() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; if ($server->getIdPrefix() != null) { $this->assertIsString($server->getIdPrefix()); @@ -132,7 +117,7 @@ public function testItHasAnIdPrefix() */ public function testItHasAnOnlineState() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsBool($server->isOnline()); } @@ -144,7 +129,7 @@ public function testItHasAnOnlineState() */ public function testItHasPlayers() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsInt($server->getPlayers()); } @@ -156,7 +141,7 @@ public function testItHasPlayers() */ public function testItHasAQueue() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsInt($server->getQueue()); } @@ -168,7 +153,7 @@ public function testItHasAQueue() */ public function testItHasMaxPlayers() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsInt($server->getMaxPlayers()); } @@ -180,7 +165,7 @@ public function testItHasMaxPlayers() */ public function testItHasADisplayOrder() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsInt($server->getDisplayOrder()); } @@ -192,7 +177,7 @@ public function testItHasADisplayOrder() */ public function testItHasASpeedLimit() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsBool($server->hasSpeedLimit()); } @@ -204,7 +189,7 @@ public function testItHasASpeedLimit() */ public function testItHasCollisions() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsBool($server->hasCollisions()); } @@ -216,7 +201,7 @@ public function testItHasCollisions() */ public function testItHasCarsForPlayers() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsBool($server->canPlayersHaveCars()); } @@ -228,7 +213,7 @@ public function testItHasCarsForPlayers() */ public function testItHasPoliceCarsForPlayers() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsBool($server->canPlayersHavePoliceCars()); } @@ -240,7 +225,7 @@ public function testItHasPoliceCarsForPlayers() */ public function testItHasAfkEnable() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsBool($server->isAfkEnabled()); } @@ -252,7 +237,7 @@ public function testItHasAfkEnable() */ public function testItHasAnEvent() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsBool($server->isEvent()); } @@ -264,7 +249,7 @@ public function testItHasAnEvent() */ public function testItHasASpecialEvent() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsBool($server->isSpecialEvent()); } @@ -276,7 +261,7 @@ public function testItHasASpecialEvent() */ public function testItHasPromods() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsBool($server->hasPromods()); } @@ -288,7 +273,7 @@ public function testItHasPromods() */ public function testItHasSyncDelay() { - $server = $this->servers()->getServers()[0]; + $server = $this->servers()[0]; $this->assertIsBool($server->hasSyncDelay()); } From 30259677ab0f4f17c6121618c3f04e1c072e3eff Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Mon, 18 Nov 2019 22:11:08 +0000 Subject: [PATCH 052/123] Fixed an issue with styling in CompanyRequest --- src/Requests/CompanyRequest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index 70f10a4..3fcb56f 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -1,9 +1,7 @@ Date: Mon, 18 Nov 2019 22:32:09 +0000 Subject: [PATCH 053/123] Added comments to all the constants --- src/Requests/Request.php | 11 +++++++++-- tests/TestCase.php | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Requests/Request.php b/src/Requests/Request.php index 6c7e450..9afa5d1 100644 --- a/src/Requests/Request.php +++ b/src/Requests/Request.php @@ -8,8 +8,15 @@ abstract class Request { - const API_ENDPOINT = 'api.truckersmp.com'; - const API_VERSION = 'v2'; + /** + * The API endpoint URL to retrieve the data form. + */ + private const API_ENDPOINT = 'api.truckersmp.com'; + + /** + * The version of the API to use. + */ + private const API_VERSION = 'v2'; /** * @var \Http\Message\MessageFactory\GuzzleMessageFactory diff --git a/tests/TestCase.php b/tests/TestCase.php index ed823a7..c8bc311 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -14,7 +14,10 @@ class TestCase extends BaseTestCase { - const CACHE_SECONDS = 3600; + /** + * The number of seconds we should cache the data for. + */ + private const CACHE_SECONDS = 3600; /** * @var \TruckersMP\Client From 407164d8af704a76b058811b6c2d50a005726df1 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Mon, 18 Nov 2019 22:50:30 +0000 Subject: [PATCH 054/123] Added a server collection --- src/Collections/Collection.php | 74 ++++++++++++++++++++++++++++ src/Collections/ServerCollection.php | 24 +++++++++ src/Requests/ServerRequest.php | 15 +++--- 3 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 src/Collections/Collection.php create mode 100644 src/Collections/ServerCollection.php diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php new file mode 100644 index 0000000..fb4adaa --- /dev/null +++ b/src/Collections/Collection.php @@ -0,0 +1,74 @@ +items; + } + + /** + * Determine if an item exists at an offset. + * + * @param mixed $key + * @return bool + */ + public function offsetExists($key) + { + return array_key_exists($key, $this->items); + } + + /** + * Get an item at a given offset. + * + * @param mixed $key + * @return mixed + */ + public function offsetGet($key) + { + return $this->items[$key]; + } + + /** + * Set the item at a given offset. + * + * @param mixed $key + * @param mixed $value + * @return void + */ + public function offsetSet($key, $value) + { + if (is_null($key)) { + $this->items[] = $value; + } else { + $this->items[$key] = $value; + } + } + + /** + * Unset the item at a given offset. + * + * @param string $key + * @return void + */ + public function offsetUnset($key) + { + unset($this->items[$key]); + } +} diff --git a/src/Collections/ServerCollection.php b/src/Collections/ServerCollection.php new file mode 100644 index 0000000..253fb1d --- /dev/null +++ b/src/Collections/ServerCollection.php @@ -0,0 +1,24 @@ + $server) { + $this->items[$key] = new Server($server); + } + } +} diff --git a/src/Requests/ServerRequest.php b/src/Requests/ServerRequest.php index c6c73b8..aefda32 100644 --- a/src/Requests/ServerRequest.php +++ b/src/Requests/ServerRequest.php @@ -2,7 +2,9 @@ namespace TruckersMP\Requests; +use TruckersMP\Collections\ServerCollection; use TruckersMP\Models\Server; +use function GuzzleHttp\Promise\all; class ServerRequest extends Request { @@ -24,15 +26,10 @@ public function getEndpoint(): string */ public function get(): array { - $servers = []; - $results = $this->call(); + $servers = new ServerCollection( + $this->call() + ); - // TODO: handle any errors / exceptions - - foreach ($results['response'] as $key => $server) { - $servers[$key] = new Server($server); - } - - return $servers; + return $servers->all(); } } From f355f039ea5bf60a52dc2de07bab24e2021bf944 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Mon, 18 Nov 2019 23:09:32 +0000 Subject: [PATCH 055/123] Renamed the all() method to get() --- src/Collections/Collection.php | 4 ++-- src/Requests/ServerRequest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index fb4adaa..88b281d 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -14,11 +14,11 @@ abstract class Collection implements ArrayAccess protected $items = []; /** - * Return all the items in the collection. + * Get the items in the collection. * * @return mixed */ - public function all() + public function get() { return $this->items; } diff --git a/src/Requests/ServerRequest.php b/src/Requests/ServerRequest.php index aefda32..bbde0a3 100644 --- a/src/Requests/ServerRequest.php +++ b/src/Requests/ServerRequest.php @@ -30,6 +30,6 @@ public function get(): array $this->call() ); - return $servers->all(); + return $servers->get(); } } From 5a6a09fa6fd2f33b9428c2b7a3b81184491352ac Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 19 Nov 2019 09:04:22 +0000 Subject: [PATCH 056/123] We now only return the ServerCollection for the ServerRequest --- src/Collections/Collection.php | 77 ++++++++++++++++++++++++++-- src/Collections/ServerCollection.php | 2 - src/Requests/ServerRequest.php | 8 ++- tests/TestCase.php | 5 +- tests/Unit/ServerTest.php | 5 +- 5 files changed, 81 insertions(+), 16 deletions(-) diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index 88b281d..30c444b 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -3,8 +3,10 @@ namespace TruckersMP\Collections; use ArrayAccess; +use Countable; +use Iterator; -abstract class Collection implements ArrayAccess +class Collection implements ArrayAccess, Iterator, Countable { /** * The items contained in the collection. @@ -14,13 +16,18 @@ abstract class Collection implements ArrayAccess protected $items = []; /** - * Get the items in the collection. + * The current position in the collection. * - * @return mixed + * @var int + */ + protected $position; + + /** + * Create a new Collection instance. */ - public function get() + public function __construct() { - return $this->items; + $this->position = 0; } /** @@ -71,4 +78,64 @@ public function offsetUnset($key) { unset($this->items[$key]); } + + /** + * Return the current element. + * + * @return mixed + */ + public function current() + { + return $this->items[$this->position]; + } + + /** + * Move forward to next element. + * + * @return void + */ + public function next() + { + ++$this->position; + } + + /** + * Return the key of the current element. + * + * @return int + */ + public function key(): int + { + return $this->position; + } + + /** + * Checks if current position is valid. + * + * @return bool + */ + public function valid(): bool + { + return isset($this->items[$this->position]); + } + + /** + * Rewind the Iterator to the first element. + * + * @return void + */ + public function rewind() + { + $this->position = 0; + } + + /** + * Count elements of an object. + * + * @return int + */ + public function count(): int + { + return count($this->items); + } } diff --git a/src/Collections/ServerCollection.php b/src/Collections/ServerCollection.php index 253fb1d..38a47a7 100644 --- a/src/Collections/ServerCollection.php +++ b/src/Collections/ServerCollection.php @@ -1,9 +1,7 @@ call() ); - - return $servers->get(); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index c8bc311..bd1eed9 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,6 +6,7 @@ use Phpfastcache\Config\ConfigurationOption; use PHPUnit\Framework\TestCase as BaseTestCase; use TruckersMP\Client; +use TruckersMP\Collections\ServerCollection; use TruckersMP\Models\Company; use TruckersMP\Models\GameTime; use TruckersMP\Models\Player; @@ -97,11 +98,11 @@ public function bans(int $id): array /** * Get or cache the server request. * - * @return \TruckersMP\Models\Server[] + * @return \TruckersMP\Collections\ServerCollection|\TruckersMP\Models\Server[] * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ - public function servers(): array + public function servers(): ServerCollection { $cachedServers = $this->cache->getItem('servers'); diff --git a/tests/Unit/ServerTest.php b/tests/Unit/ServerTest.php index 3191c3a..4fd55a1 100644 --- a/tests/Unit/ServerTest.php +++ b/tests/Unit/ServerTest.php @@ -3,6 +3,7 @@ namespace Tests\Unit; use Tests\TestCase; +use TruckersMP\Collections\ServerCollection; use TruckersMP\Models\Server; class ServerTest extends TestCase @@ -15,9 +16,9 @@ public function testWeCanGetAllTheServers() { $servers = $this->servers(); - $this->assertIsArray($servers); + $this->assertInstanceOf(ServerCollection::class, $servers); - if (count($servers) > 0) { + if ($servers->count() > 0) { $this->assertInstanceOf(Server::class, $servers[0]); } } From 961eb1e9cd697f68157c4000143615138ddf4b18 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 19 Nov 2019 09:53:40 +0000 Subject: [PATCH 057/123] Added the ability to get the companies news posts --- src/Client.php | 3 +- src/Collections/NewsCollection.php | 24 ++++++ src/Collections/ServerCollection.php | 2 + src/Models/Post.php | 111 +++++++++++++++++++++++++++ src/Requests/CompanyRequest.php | 20 +++++ src/Requests/NewsRequest.php | 50 ++++++++++++ tests/TestCase.php | 22 ++++++ tests/Unit/BanTest.php | 6 +- tests/Unit/CompanyTest.php | 3 + tests/Unit/NewsTest.php | 32 ++++++++ tests/Unit/PlayerTest.php | 5 +- 11 files changed, 273 insertions(+), 5 deletions(-) create mode 100644 src/Collections/NewsCollection.php create mode 100644 src/Models/Post.php create mode 100644 src/Requests/NewsRequest.php create mode 100644 tests/Unit/NewsTest.php diff --git a/src/Client.php b/src/Client.php index 82a27a4..98a06dd 100644 --- a/src/Client.php +++ b/src/Client.php @@ -2,7 +2,6 @@ namespace TruckersMP; -use TruckersMP\Models\GameTime; use TruckersMP\Requests\BanRequest; use TruckersMP\Requests\CompanyRequest; use TruckersMP\Requests\GameTimeRequest; @@ -76,7 +75,7 @@ public function servers(): ServerRequest * * @return \TruckersMP\Requests\GameTimeRequest */ - public function gameTime(): \TruckersMP\Requests\GameTimeRequest + public function gameTime(): GameTimeRequest { return new GameTimeRequest($this->config); } diff --git a/src/Collections/NewsCollection.php b/src/Collections/NewsCollection.php new file mode 100644 index 0000000..71b344d --- /dev/null +++ b/src/Collections/NewsCollection.php @@ -0,0 +1,24 @@ + $post) { + $this->items[$key] = new Post($post); + } + } +} diff --git a/src/Collections/ServerCollection.php b/src/Collections/ServerCollection.php index 38a47a7..4e71cf4 100644 --- a/src/Collections/ServerCollection.php +++ b/src/Collections/ServerCollection.php @@ -13,6 +13,8 @@ class ServerCollection extends Collection */ public function __construct(array $response) { + parent::__construct(); + // TODO: handle any errors or exceptions foreach ($response['response'] as $key => $server) { diff --git a/src/Models/Post.php b/src/Models/Post.php new file mode 100644 index 0000000..29d3736 --- /dev/null +++ b/src/Models/Post.php @@ -0,0 +1,111 @@ +id = $post['id']; + $this->title = $post['title']; + $this->summary = $post['content_summary']; + $this->authorId = $post['author_id']; + $this->author = $post['author']; + $this->pinned = $post['pinned']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @return string + */ + public function getSummary(): string + { + return $this->summary; + } + + /** + * @return int + */ + public function getAuthorId(): int + { + return $this->authorId; + } + + /** + * @return string + */ + public function getAuthor(): string + { + return $this->author; + } + + /** + * @return bool + */ + public function isPinned(): bool + { + return $this->pinned; + } +} diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index 3fcb56f..0e97f06 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -13,6 +13,13 @@ class CompanyRequest extends Request */ protected $id; + /** + * The configuration to use for Guzzle. + * + * @var array + */ + protected $config = []; + /** * Create a new CompanyRequest instance. * @@ -48,4 +55,17 @@ public function get(): Company $this->call() ); } + + /** + * Get the news posts for the company. + * + * @return \TruckersMP\Requests\NewsRequest + */ + public function news() + { + return new NewsRequest( + $this->config, + $this->id + ); + } } diff --git a/src/Requests/NewsRequest.php b/src/Requests/NewsRequest.php new file mode 100644 index 0000000..94629fd --- /dev/null +++ b/src/Requests/NewsRequest.php @@ -0,0 +1,50 @@ +id = $id; + } + + /** + * Get the endpoint of the request. + * + * @return string + */ + public function getEndpoint(): string + { + return 'vtc/' . $this->id . '/news'; + } + + /** + * Get the data for the request. + * + * @return mixed + * @throws \Http\Client\Exception + */ + public function get() + { + return new NewsCollection( + $this->call() + ); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index bd1eed9..ada5de9 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,6 +6,7 @@ use Phpfastcache\Config\ConfigurationOption; use PHPUnit\Framework\TestCase as BaseTestCase; use TruckersMP\Client; +use TruckersMP\Collections\NewsCollection; use TruckersMP\Collections\ServerCollection; use TruckersMP\Models\Company; use TruckersMP\Models\GameTime; @@ -154,6 +155,27 @@ public function company(int $id): Company return $cachedCompany->get(); } + /** + * Get the news posts for the specified company. + * + * @param int $id + * + * @return NewsCollection|\TruckersMP\Models\Post[] + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function companyNews(int $id): NewsCollection + { + $cachedNews = $this->cache->getItem('company_news_' . $id); + + if (! $cachedNews->isHit()) { + $cachedNews->set($this->client->company($id)->news()->get())->expiresAfter(self::CACHE_SECONDS); + $this->cache->save($cachedNews); + } + + return $cachedNews->get(); + } + /** * Get or cache the TruckersMP version. * diff --git a/tests/Unit/BanTest.php b/tests/Unit/BanTest.php index e1c8200..02ced29 100644 --- a/tests/Unit/BanTest.php +++ b/tests/Unit/BanTest.php @@ -4,12 +4,14 @@ use Carbon\Carbon; use Tests\TestCase; -use TruckersMP\Collections\BanCollection; use TruckersMP\Models\Ban; class BanTest extends TestCase { - const TEST_ACCOUNT = 28159; + /** + * The ID of the player to use in the tests. + */ + private const TEST_ACCOUNT = 28159; /** * @throws \Http\Client\Exception diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index 4b20596..9da7780 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -11,6 +11,9 @@ class CompanyTest extends TestCase { + /** + * The ID of the company to use in the tests. + */ const TEST_COMPANY = 1; /** @test */ diff --git a/tests/Unit/NewsTest.php b/tests/Unit/NewsTest.php new file mode 100644 index 0000000..1a33d3d --- /dev/null +++ b/tests/Unit/NewsTest.php @@ -0,0 +1,32 @@ +companyNews(self::TEST_COMPANY); + + $this->assertInstanceOf(NewsCollection::class, $posts); + + if ($posts->count() > 0) { + $post = $posts[0]; + + $this->assertInstanceOf(Post::class, $post); + } + } +} diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index d399622..9a95dad 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -8,7 +8,10 @@ class PlayerTest extends TestCase { - const TEST_ACCOUNT = 28159; + /** + * The ID of the player to use in the tests. + */ + private const TEST_ACCOUNT = 28159; /** * @throws \Http\Client\Exception From 090eb9bc3f32d8fe93de09e16b35d18cd21c1c8b Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 19 Nov 2019 10:08:28 +0000 Subject: [PATCH 058/123] Renamed Post model to CompanyPost --- src/Collections/NewsCollection.php | 4 ++-- src/Models/{Post.php => CompanyPost.php} | 2 +- tests/TestCase.php | 2 +- tests/Unit/CompanyTest.php | 2 +- tests/Unit/NewsTest.php | 5 ++--- 5 files changed, 7 insertions(+), 8 deletions(-) rename src/Models/{Post.php => CompanyPost.php} (98%) diff --git a/src/Collections/NewsCollection.php b/src/Collections/NewsCollection.php index 71b344d..e435278 100644 --- a/src/Collections/NewsCollection.php +++ b/src/Collections/NewsCollection.php @@ -2,7 +2,7 @@ namespace TruckersMP\Collections; -use TruckersMP\Models\Post; +use TruckersMP\Models\CompanyPost; class NewsCollection extends Collection { @@ -18,7 +18,7 @@ public function __construct(array $response) // TODO: handle any errors or exceptions foreach ($response['response']['news'] as $key => $post) { - $this->items[$key] = new Post($post); + $this->items[$key] = new CompanyPost($post); } } } diff --git a/src/Models/Post.php b/src/Models/CompanyPost.php similarity index 98% rename from src/Models/Post.php rename to src/Models/CompanyPost.php index 29d3736..d8da145 100644 --- a/src/Models/Post.php +++ b/src/Models/CompanyPost.php @@ -2,7 +2,7 @@ namespace TruckersMP\Models; -class Post +class CompanyPost { /** * The ID of the post. diff --git a/tests/TestCase.php b/tests/TestCase.php index ada5de9..b0d7e8d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -160,7 +160,7 @@ public function company(int $id): Company * * @param int $id * - * @return NewsCollection|\TruckersMP\Models\Post[] + * @return NewsCollection|\TruckersMP\Models\CompanyPost[] * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index 9da7780..8c2749e 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -14,7 +14,7 @@ class CompanyTest extends TestCase /** * The ID of the company to use in the tests. */ - const TEST_COMPANY = 1; + private const TEST_COMPANY = 1; /** @test */ /**public function testWeCanGetTheCompanies() diff --git a/tests/Unit/NewsTest.php b/tests/Unit/NewsTest.php index 1a33d3d..a1bf477 100644 --- a/tests/Unit/NewsTest.php +++ b/tests/Unit/NewsTest.php @@ -4,14 +4,13 @@ use Tests\TestCase; use TruckersMP\Collections\NewsCollection; -use TruckersMP\Models\Post; class NewsTest extends TestCase { /** * The ID of the company to use in the tests. */ - const TEST_COMPANY = 1; + private const TEST_COMPANY = 1; /** * @throws \Http\Client\Exception @@ -26,7 +25,7 @@ public function testWeCanGetAllTheNewsPosts() if ($posts->count() > 0) { $post = $posts[0]; - $this->assertInstanceOf(Post::class, $post); + $this->assertInstanceOf(CompanyPost::class, $post); } } } From 101ca0e3856a5460983038aa1f02a8f363b8f813 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 19 Nov 2019 10:17:00 +0000 Subject: [PATCH 059/123] Renamed news() to posts() in company request --- .../{NewsCollection.php => PostsCollection.php} | 2 +- .../{NewsRequest.php => CompanyPostsRequest.php} | 6 +++--- src/Requests/CompanyRequest.php | 6 +++--- tests/TestCase.php | 8 ++++---- tests/Unit/{NewsTest.php => CompanyPostTest.php} | 9 +++++---- 5 files changed, 16 insertions(+), 15 deletions(-) rename src/Collections/{NewsCollection.php => PostsCollection.php} (91%) rename src/Requests/{NewsRequest.php => CompanyPostsRequest.php} (85%) rename tests/Unit/{NewsTest.php => CompanyPostTest.php} (70%) diff --git a/src/Collections/NewsCollection.php b/src/Collections/PostsCollection.php similarity index 91% rename from src/Collections/NewsCollection.php rename to src/Collections/PostsCollection.php index e435278..3c8b762 100644 --- a/src/Collections/NewsCollection.php +++ b/src/Collections/PostsCollection.php @@ -4,7 +4,7 @@ use TruckersMP\Models\CompanyPost; -class NewsCollection extends Collection +class PostsCollection extends Collection { /** * Create a new NewsCollection instance. diff --git a/src/Requests/NewsRequest.php b/src/Requests/CompanyPostsRequest.php similarity index 85% rename from src/Requests/NewsRequest.php rename to src/Requests/CompanyPostsRequest.php index 94629fd..a8dacbf 100644 --- a/src/Requests/NewsRequest.php +++ b/src/Requests/CompanyPostsRequest.php @@ -2,9 +2,9 @@ namespace TruckersMP\Requests; -use TruckersMP\Collections\NewsCollection; +use TruckersMP\Collections\PostsCollection; -class NewsRequest extends Request +class CompanyPostsRequest extends Request { /** * The ID of the requested company. @@ -43,7 +43,7 @@ public function getEndpoint(): string */ public function get() { - return new NewsCollection( + return new PostsCollection( $this->call() ); } diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index 0e97f06..020d979 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -59,11 +59,11 @@ public function get(): Company /** * Get the news posts for the company. * - * @return \TruckersMP\Requests\NewsRequest + * @return \TruckersMP\Requests\CompanyPostsRequest */ - public function news() + public function posts() { - return new NewsRequest( + return new CompanyPostsRequest( $this->config, $this->id ); diff --git a/tests/TestCase.php b/tests/TestCase.php index b0d7e8d..aaaf041 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,7 +6,7 @@ use Phpfastcache\Config\ConfigurationOption; use PHPUnit\Framework\TestCase as BaseTestCase; use TruckersMP\Client; -use TruckersMP\Collections\NewsCollection; +use TruckersMP\Collections\PostsCollection; use TruckersMP\Collections\ServerCollection; use TruckersMP\Models\Company; use TruckersMP\Models\GameTime; @@ -160,16 +160,16 @@ public function company(int $id): Company * * @param int $id * - * @return NewsCollection|\TruckersMP\Models\CompanyPost[] + * @return PostsCollection|\TruckersMP\Models\CompanyPost[] * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ - public function companyNews(int $id): NewsCollection + public function companyNews(int $id): PostsCollection { $cachedNews = $this->cache->getItem('company_news_' . $id); if (! $cachedNews->isHit()) { - $cachedNews->set($this->client->company($id)->news()->get())->expiresAfter(self::CACHE_SECONDS); + $cachedNews->set($this->client->company($id)->posts()->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedNews); } diff --git a/tests/Unit/NewsTest.php b/tests/Unit/CompanyPostTest.php similarity index 70% rename from tests/Unit/NewsTest.php rename to tests/Unit/CompanyPostTest.php index a1bf477..88d84bd 100644 --- a/tests/Unit/NewsTest.php +++ b/tests/Unit/CompanyPostTest.php @@ -3,14 +3,15 @@ namespace Tests\Unit; use Tests\TestCase; -use TruckersMP\Collections\NewsCollection; +use TruckersMP\Collections\PostsCollection; +use TruckersMP\Models\CompanyPost; -class NewsTest extends TestCase +class CompanyPostTest extends TestCase { /** * The ID of the company to use in the tests. */ - private const TEST_COMPANY = 1; + private const TEST_COMPANY = 17; /** * @throws \Http\Client\Exception @@ -20,7 +21,7 @@ public function testWeCanGetAllTheNewsPosts() { $posts = $this->companyNews(self::TEST_COMPANY); - $this->assertInstanceOf(NewsCollection::class, $posts); + $this->assertInstanceOf(PostsCollection::class, $posts); if ($posts->count() > 0) { $post = $posts[0]; From 087bacaa6c5576df7ffe029b4a3c217afb74b521 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 19 Nov 2019 19:50:15 +0000 Subject: [PATCH 060/123] Added the ability to get a companies post --- src/Models/CompanyPost.php | 26 +++++ .../NewsRequest.php} | 5 +- src/Requests/Companies/PostRequest.php | 61 ++++++++++++ src/Requests/CompanyRequest.php | 24 ++++- tests/TestCase.php | 31 +++++- tests/Unit/CompanyPostTest.php | 95 ++++++++++++++++++- 6 files changed, 234 insertions(+), 8 deletions(-) rename src/Requests/{CompanyPostsRequest.php => Companies/NewsRequest.php} (88%) create mode 100644 src/Requests/Companies/PostRequest.php diff --git a/src/Models/CompanyPost.php b/src/Models/CompanyPost.php index d8da145..12b5b61 100644 --- a/src/Models/CompanyPost.php +++ b/src/Models/CompanyPost.php @@ -25,6 +25,13 @@ class CompanyPost */ protected $summary; + /** + * The content of the post. + * + * @var string + */ + protected $content; + /** * The ID of the author who wrote the post. * @@ -53,9 +60,20 @@ class CompanyPost */ public function __construct(array $post) { + // If the data is being passed directly from an API call, then we need to get + // the data from the response element. + if (isset($post['response'])) { + $post = $post['response']; + } + $this->id = $post['id']; $this->title = $post['title']; $this->summary = $post['content_summary']; + + if (isset($post['content'])) { + $this->content = $post['content']; + } + $this->authorId = $post['author_id']; $this->author = $post['author']; $this->pinned = $post['pinned']; @@ -85,6 +103,14 @@ public function getSummary(): string return $this->summary; } + /** + * @return string + */ + public function getContent(): string + { + return $this->content; + } + /** * @return int */ diff --git a/src/Requests/CompanyPostsRequest.php b/src/Requests/Companies/NewsRequest.php similarity index 88% rename from src/Requests/CompanyPostsRequest.php rename to src/Requests/Companies/NewsRequest.php index a8dacbf..a939981 100644 --- a/src/Requests/CompanyPostsRequest.php +++ b/src/Requests/Companies/NewsRequest.php @@ -1,10 +1,11 @@ companyId = $companyId; + $this->postId = $postId; + } + + /** + * Get the endpoint of the request. + * + * @return string + */ + public function getEndpoint(): string + { + return 'vtc/' . $this->companyId . '/news/' . $this->postId; + } + + /** + * Get the data for the request. + * + * @return CompanyPost + * @throws \Http\Client\Exception + */ + public function get(): CompanyPost + { + return new CompanyPost( + $this->call() + ); + } +} diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index 020d979..e9b49bd 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -3,6 +3,8 @@ namespace TruckersMP\Requests; use TruckersMP\Models\Company; +use TruckersMP\Requests\Companies\NewsRequest; +use TruckersMP\Requests\Companies\PostRequest; class CompanyRequest extends Request { @@ -59,13 +61,29 @@ public function get(): Company /** * Get the news posts for the company. * - * @return \TruckersMP\Requests\CompanyPostsRequest + * @return \TruckersMP\Requests\Companies\NewsRequest */ - public function posts() + public function posts(): NewsRequest { - return new CompanyPostsRequest( + return new NewsRequest( $this->config, $this->id ); } + + /** + * Get the post for the company with the specified ID. + * + * @param int $id + * + * @return \TruckersMP\Requests\Companies\PostRequest + */ + public function post(int $id): PostRequest + { + return new PostRequest( + $this->config, + $this->id, + $id + ); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index aaaf041..02ee631 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,10 +9,12 @@ use TruckersMP\Collections\PostsCollection; use TruckersMP\Collections\ServerCollection; use TruckersMP\Models\Company; +use TruckersMP\Models\CompanyPost; use TruckersMP\Models\GameTime; use TruckersMP\Models\Player; use TruckersMP\Models\Rule; use TruckersMP\Models\Version; +use TruckersMP\Requests\Companies\PostRequest; class TestCase extends BaseTestCase { @@ -164,9 +166,9 @@ public function company(int $id): Company * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ - public function companyNews(int $id): PostsCollection + public function companyPosts(int $id): PostsCollection { - $cachedNews = $this->cache->getItem('company_news_' . $id); + $cachedNews = $this->cache->getItem('company_posts_' . $id); if (! $cachedNews->isHit()) { $cachedNews->set($this->client->company($id)->posts()->get())->expiresAfter(self::CACHE_SECONDS); @@ -176,6 +178,31 @@ public function companyNews(int $id): PostsCollection return $cachedNews->get(); } + /** + * Get or Cache the specified company post. + * + * @param int $companyId + * @param int $postId + * + * @return CompanyPost + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function companyPost(int $companyId, int $postId): CompanyPost + { + $cachedPost = $this->cache->getItem('company_' . $companyId . '_post_' . $postId); + + if (! $cachedPost->isHit()) { + $cachedPost->set( + $this->client->company($companyId)->post($postId)->get() + )->expiresAfter(self::CACHE_SECONDS); + + $this->cache->save($cachedPost); + } + + return $cachedPost->get(); + } + /** * Get or cache the TruckersMP version. * diff --git a/tests/Unit/CompanyPostTest.php b/tests/Unit/CompanyPostTest.php index 88d84bd..40f22f2 100644 --- a/tests/Unit/CompanyPostTest.php +++ b/tests/Unit/CompanyPostTest.php @@ -13,13 +13,18 @@ class CompanyPostTest extends TestCase */ private const TEST_COMPANY = 17; + /** + * The ID of the post to use in the tests. + */ + private const TEST_POST = 121; + /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ public function testWeCanGetAllTheNewsPosts() { - $posts = $this->companyNews(self::TEST_COMPANY); + $posts = $this->companyPosts(self::TEST_COMPANY); $this->assertInstanceOf(PostsCollection::class, $posts); @@ -29,4 +34,92 @@ public function testWeCanGetAllTheNewsPosts() $this->assertInstanceOf(CompanyPost::class, $post); } } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testWeCanGetAPost() + { + $post = $this->companyPost(self::TEST_COMPANY, self::TEST_POST); + + $this->assertInstanceOf(CompanyPost::class, $post); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testItHasAnId() + { + $post = $this->companyPost(self::TEST_COMPANY, self::TEST_POST); + + $this->assertIsInt($post->getId()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testItHasATitle() + { + $post = $this->companyPost(self::TEST_COMPANY, self::TEST_POST); + + $this->assertIsString($post->getTitle()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testItHasASummary() + { + $post = $this->companyPost(self::TEST_COMPANY, self::TEST_POST); + + $this->assertIsString($post->getSummary()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testItHasCotent() + { + $post = $this->companyPost(self::TEST_COMPANY, self::TEST_POST); + + $this->assertIsString($post->getContent()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testItHasAnAuthorId() + { + $post = $this->companyPost(self::TEST_COMPANY, self::TEST_POST); + + $this->assertIsInt($post->getAuthorId()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testItHasAnAuthor() + { + $post = $this->companyPost(self::TEST_COMPANY, self::TEST_POST); + + $this->assertIsString($post->getAuthor()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testIfThePostIsPinned() + { + $post = $this->companyPost(self::TEST_COMPANY, self::TEST_POST); + + $this->assertIsBool($post->isPinned()); + } } From a75b8d9f534bdf558a9b8bd1bdd9d91c2cda00b7 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 19 Nov 2019 20:12:45 +0000 Subject: [PATCH 061/123] Reimplemented the ability to get recent and featured companies --- src/Client.php | 14 +++++++ src/Collections/CompanyCollection.php | 25 ++++++++++++ src/Requests/CompaniesRequest.php | 56 +++++++++++++++++++++++++++ tests/TestCase.php | 39 +++++++++++++++++++ tests/Unit/CompanyTest.php | 38 +++++++++--------- 5 files changed, 152 insertions(+), 20 deletions(-) create mode 100644 src/Collections/CompanyCollection.php create mode 100644 src/Requests/CompaniesRequest.php diff --git a/src/Client.php b/src/Client.php index 98a06dd..851c61a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -2,7 +2,9 @@ namespace TruckersMP; +use TruckersMP\Collections\CompanyCollection; use TruckersMP\Requests\BanRequest; +use TruckersMP\Requests\CompaniesRequest; use TruckersMP\Requests\CompanyRequest; use TruckersMP\Requests\GameTimeRequest; use TruckersMP\Requests\PlayerRequest; @@ -80,6 +82,18 @@ public function gameTime(): GameTimeRequest return new GameTimeRequest($this->config); } + /** + * Get the recent and featured companies. + * + * https://stats.truckersmp.com/api#vtc_index + * + * @return \TruckersMP\Requests\CompaniesRequest + */ + public function companies(): CompaniesRequest + { + return new CompaniesRequest($this->config); + } + /** * Get the information for the company with the specified ID. * diff --git a/src/Collections/CompanyCollection.php b/src/Collections/CompanyCollection.php new file mode 100644 index 0000000..a7f1815 --- /dev/null +++ b/src/Collections/CompanyCollection.php @@ -0,0 +1,25 @@ + $company) { + $this->items[$key] = new Company($company); + } + } +} diff --git a/src/Requests/CompaniesRequest.php b/src/Requests/CompaniesRequest.php new file mode 100644 index 0000000..91ef8c6 --- /dev/null +++ b/src/Requests/CompaniesRequest.php @@ -0,0 +1,56 @@ +call(), + 'recent' + ); + } + + /** + * Get the featured companies. + * + * @return \TruckersMP\Collections\CompanyCollection + * @throws \Http\Client\Exception + */ + public function featured(): CompanyCollection + { + return new CompanyCollection( + $this->call(), + 'featured', + ); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 02ee631..282e69e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,6 +6,7 @@ use Phpfastcache\Config\ConfigurationOption; use PHPUnit\Framework\TestCase as BaseTestCase; use TruckersMP\Client; +use TruckersMP\Collections\CompanyCollection; use TruckersMP\Collections\PostsCollection; use TruckersMP\Collections\ServerCollection; use TruckersMP\Models\Company; @@ -136,6 +137,44 @@ public function gameTime(): GameTime return $cachedGameTime->get(); } + /** + * Get or cache the recent companies. + * + * @return \TruckersMP\Collections\CompanyCollection|Company[] + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function recentCompanies(): CompanyCollection + { + $cachedCompanies = $this->cache->getItem('recent_companies'); + + if (! $cachedCompanies->isHit()) { + $cachedCompanies->set($this->client->companies()->recent()); + $this->cache->save($cachedCompanies); + } + + return $cachedCompanies->get(); + } + + /** + * Get or cache the featured companies. + * + * @return \TruckersMP\Collections\CompanyCollection + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function featuredCompanies(): CompanyCollection + { + $cachedCompanies = $this->cache->getItem('featured_companies'); + + if (! $cachedCompanies->isHit()) { + $cachedCompanies->set($this->client->companies()->featured()); + $this->cache->save($cachedCompanies); + } + + return $cachedCompanies->get(); + } + /** * Get or cache the company with the specified id. * diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index 8c2749e..90cbccf 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -16,44 +16,42 @@ class CompanyTest extends TestCase */ private const TEST_COMPANY = 1; - /** @test */ - /**public function testWeCanGetTheCompanies() - { - $companies = $this->companies(); - - $this->assertInstanceOf(CompanyCollection::class, $companies); - }*/ - - /** @test */ - /*public function testWeCanGetTheRecentCompanies() + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testWeCanGetTheRecentCompanies() { - $companies = $this->companies()->getRecent(); + $companies = $this->recentCompanies(); $this->assertNotEmpty($companies); - $this->assertInstanceOf(Company::class, $companies[0]); - }*/ + $this->assertInstanceOf(CompanyCollection::class, $companies); + } - /** @test */ - /*public function testWeCanGetTheFeaturedCompanies() + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testWeCanGetTheFeaturedCompanies() { - $companies = $this->companies()->getFeatured(); + $companies = $this->featuredCompanies(); $this->assertNotEmpty($companies); - $this->assertInstanceOf(Company::class, $companies[0]); - }*/ + $this->assertInstanceOf(CompanyCollection::class, $companies); + } /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException */ - /*public function testWeCanGetACompany() + public function testWeCanGetACompany() { $company = $this->company(self::TEST_COMPANY); $this->assertInstanceOf(Company::class, $company); - }*/ + } /** * @throws \Http\Client\Exception From a56d201fbe4d566c667fa9af348a7911dc041618 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 19 Nov 2019 20:53:05 +0000 Subject: [PATCH 062/123] Added the ability to get the company roles --- src/Collections/CompanyCollection.php | 2 +- src/Collections/PostsCollection.php | 2 +- src/Collections/RoleCollection.php | 24 +++++ src/Models/CompanyRole.php | 119 ++++++++++++++++++++++++ src/Requests/Companies/NewsRequest.php | 13 +-- src/Requests/Companies/RoleRequest.php | 60 ++++++++++++ src/Requests/Companies/RolesRequest.php | 52 +++++++++++ src/Requests/CompanyRequest.php | 31 ++++++ tests/TestCase.php | 48 ++++++++++ tests/Unit/CompanyRoleTest.php | 115 +++++++++++++++++++++++ 10 files changed, 458 insertions(+), 8 deletions(-) create mode 100644 src/Collections/RoleCollection.php create mode 100644 src/Models/CompanyRole.php create mode 100644 src/Requests/Companies/RoleRequest.php create mode 100644 src/Requests/Companies/RolesRequest.php create mode 100644 tests/Unit/CompanyRoleTest.php diff --git a/src/Collections/CompanyCollection.php b/src/Collections/CompanyCollection.php index a7f1815..f543dfe 100644 --- a/src/Collections/CompanyCollection.php +++ b/src/Collections/CompanyCollection.php @@ -7,7 +7,7 @@ class CompanyCollection extends Collection { /** - * Create a new CompanyCollection instance. + * Create a new Collection instance. * * @param array $response * @param string $type diff --git a/src/Collections/PostsCollection.php b/src/Collections/PostsCollection.php index 3c8b762..a9a27dc 100644 --- a/src/Collections/PostsCollection.php +++ b/src/Collections/PostsCollection.php @@ -7,7 +7,7 @@ class PostsCollection extends Collection { /** - * Create a new NewsCollection instance. + * Create a new Collection instance. * * @param array $response */ diff --git a/src/Collections/RoleCollection.php b/src/Collections/RoleCollection.php new file mode 100644 index 0000000..c78e45a --- /dev/null +++ b/src/Collections/RoleCollection.php @@ -0,0 +1,24 @@ + $role) { + $this->items[$key] = new CompanyRole($role); + } + } +} diff --git a/src/Models/CompanyRole.php b/src/Models/CompanyRole.php new file mode 100644 index 0000000..1fe5b98 --- /dev/null +++ b/src/Models/CompanyRole.php @@ -0,0 +1,119 @@ +id = $role['id']; + $this->name = $role['name']; + $this->order = $role['order']; + $this->owner = $role['owner']; + $this->createdAt = new Carbon($role['created_at'], 'UTC'); + $this->updatedAt = new Carbon($role['updated_at'], 'UTC'); + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return int + */ + public function getOrder(): int + { + return $this->order; + } + + /** + * @return bool + */ + public function isOwner(): bool + { + return $this->owner; + } + + /** + * @return \Carbon\Carbon + */ + public function getCreatedAt(): \Carbon\Carbon + { + return $this->createdAt; + } + + /** + * @return \Carbon\Carbon + */ + public function getUpdatedAt(): \Carbon\Carbon + { + return $this->updatedAt; + } +} diff --git a/src/Requests/Companies/NewsRequest.php b/src/Requests/Companies/NewsRequest.php index a939981..75d8630 100644 --- a/src/Requests/Companies/NewsRequest.php +++ b/src/Requests/Companies/NewsRequest.php @@ -12,18 +12,19 @@ class NewsRequest extends Request * * @var int */ - protected $id; + protected $companyId; /** * Create a new NewsRequest instance. * * @param array $config + * @param int $companyId */ - public function __construct(array $config, int $id) + public function __construct(array $config, int $companyId) { parent::__construct($config); - $this->id = $id; + $this->companyId = $companyId; } /** @@ -33,16 +34,16 @@ public function __construct(array $config, int $id) */ public function getEndpoint(): string { - return 'vtc/' . $this->id . '/news'; + return 'vtc/' . $this->companyId . '/news'; } /** * Get the data for the request. * - * @return mixed + * @return PostsCollection|\TruckersMP\Models\CompanyPost[] * @throws \Http\Client\Exception */ - public function get() + public function get(): PostsCollection { return new PostsCollection( $this->call() diff --git a/src/Requests/Companies/RoleRequest.php b/src/Requests/Companies/RoleRequest.php new file mode 100644 index 0000000..8681e94 --- /dev/null +++ b/src/Requests/Companies/RoleRequest.php @@ -0,0 +1,60 @@ +companyId = $companyId; + $this->roleId = $roleId; + } + + /** + * Get the endpoint of the request. + * + * @return string + */ + public function getEndpoint(): string + { + return 'vtc/' . $this->companyId . '/role/' . $this->roleId; + } + + /** + * Get the data for the request. + * + * @return CompanyRole + * @throws \Http\Client\Exception + */ + public function get(): CompanyRole + { + return new CompanyRole( + $this->call() + ); + } +} diff --git a/src/Requests/Companies/RolesRequest.php b/src/Requests/Companies/RolesRequest.php new file mode 100644 index 0000000..7d4241e --- /dev/null +++ b/src/Requests/Companies/RolesRequest.php @@ -0,0 +1,52 @@ +companyId = $companyId; + } + + /** + * Get the endpoint of the request. + * + * @return string + */ + public function getEndpoint(): string + { + return 'vtc/' . $this->companyId . '/roles'; + } + + /** + * Get the data for the request. + * + * @return RoleCollection|\TruckersMP\Models\CompanyRole[] + * @throws \Http\Client\Exception + */ + public function get(): RoleCollection + { + return new RoleCollection( + $this->call() + ); + } +} diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index e9b49bd..ea2ed2f 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -5,6 +5,8 @@ use TruckersMP\Models\Company; use TruckersMP\Requests\Companies\NewsRequest; use TruckersMP\Requests\Companies\PostRequest; +use TruckersMP\Requests\Companies\RoleRequest; +use TruckersMP\Requests\Companies\RolesRequest; class CompanyRequest extends Request { @@ -86,4 +88,33 @@ public function post(int $id): PostRequest $id ); } + + /** + * Get the roles for the company. + * + * @return \TruckersMP\Requests\Companies\RolesRequest + */ + public function roles(): RolesRequest + { + return new RolesRequest( + $this->config, + $this->id + ); + } + + /** + * Get the requested company role. + * + * @param int $id + * + * @return \TruckersMP\Requests\Companies\RoleRequest + */ + public function role(int $id): RoleRequest + { + return new RoleRequest( + $this->config, + $this->id, + $id + ); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 282e69e..ce15476 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,9 +8,11 @@ use TruckersMP\Client; use TruckersMP\Collections\CompanyCollection; use TruckersMP\Collections\PostsCollection; +use TruckersMP\Collections\RoleCollection; use TruckersMP\Collections\ServerCollection; use TruckersMP\Models\Company; use TruckersMP\Models\CompanyPost; +use TruckersMP\Models\CompanyRole; use TruckersMP\Models\GameTime; use TruckersMP\Models\Player; use TruckersMP\Models\Rule; @@ -242,6 +244,52 @@ public function companyPost(int $companyId, int $postId): CompanyPost return $cachedPost->get(); } + /** + * Get or cache the company roles. + * + * @param int $companyId + * + * @return \TruckersMP\Collections\RoleCollection|\TruckersMP\Models\CompanyRole[] + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function companyRoles(int $companyId): RoleCollection + { + $cachedRoles = $this->cache->getItem('company_roles_' . $companyId); + + if (! $cachedRoles->isHit()) { + $cachedRoles->set($this->client->company($companyId)->roles()->get())->expiresAfter(self::CACHE_SECONDS); + $this->cache->save($cachedRoles); + } + + return $cachedRoles->get(); + } + + /** + * Get or cache the company role. + * + * @param int $companyId + * @param int $roleId + * + * @return \TruckersMP\Models\CompanyRole + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function companyRole(int $companyId, int $roleId): CompanyRole + { + $cachedRoles = $this->cache->getItem('company_' . $roleId . '_roles_' . $companyId); + + if (! $cachedRoles->isHit()) { + $cachedRoles->set( + $this->client->company($companyId)->role($roleId)->get() + )->expiresAfter(self::CACHE_SECONDS); + + $this->cache->save($cachedRoles); + } + + return $cachedRoles->get(); + } + /** * Get or cache the TruckersMP version. * diff --git a/tests/Unit/CompanyRoleTest.php b/tests/Unit/CompanyRoleTest.php new file mode 100644 index 0000000..58258c8 --- /dev/null +++ b/tests/Unit/CompanyRoleTest.php @@ -0,0 +1,115 @@ +companyRoles(self::TEST_COMPANY); + + $this->assertInstanceOf(RoleCollection::class, $roles); + + if ($roles->count() > 0) { + $role = $roles[0]; + + $this->assertInstanceOf(CompanyRole::class, $role); + } + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testWeCanGetARole() + { + $role = $this->companyRole(self::TEST_COMPANY, self::TEST_ROLE); + + $this->assertInstanceOf(CompanyRole::class, $role); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testItHasAnId() + { + $role = $this->companyRole(self::TEST_COMPANY, self::TEST_ROLE); + + $this->assertIsInt($role->getId()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testItHasAName() + { + $role = $this->companyRole(self::TEST_COMPANY, self::TEST_ROLE); + + $this->assertIsString($role->getName()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testItHasAnOrder() + { + $role = $this->companyRole(self::TEST_COMPANY, self::TEST_ROLE); + + $this->assertIsInt($role->getOrder()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testIfItIsAnOwner() + { + $role = $this->companyRole(self::TEST_COMPANY, self::TEST_ROLE); + + $this->assertIsBool($role->isOwner()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testItHasACreatedAtDate() + { + $role = $this->companyRole(self::TEST_COMPANY, self::TEST_ROLE); + + $this->assertInstanceOf(Carbon::class, $role->getCreatedAt()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + */ + public function testItHasAnUpdatedAtDate() + { + $role = $this->companyRole(self::TEST_COMPANY, self::TEST_ROLE); + + $this->assertInstanceOf(Carbon::class, $role->getUpdatedAt()); + } +} From 41da13274972e00f0ed27ed5f29c6f635196e759 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 23 Nov 2019 20:32:56 +0000 Subject: [PATCH 063/123] We now handle errors if an invalid request is made --- src/ApiErrorHandler.php | 40 ++++++++++++++++++++++++ src/Exceptions/PageNotFoundException.php | 9 ++++++ src/Exceptions/RequestException.php | 9 ++++++ src/Requests/BanRequest.php | 2 ++ src/Requests/Companies/NewsRequest.php | 2 ++ src/Requests/Companies/PostRequest.php | 2 ++ src/Requests/Companies/RoleRequest.php | 2 ++ src/Requests/Companies/RolesRequest.php | 2 ++ src/Requests/CompaniesRequest.php | 2 ++ src/Requests/CompanyRequest.php | 2 ++ src/Requests/GameTimeRequest.php | 2 ++ src/Requests/PlayerRequest.php | 2 ++ src/Requests/Request.php | 12 ++++++- src/Requests/RuleRequest.php | 2 ++ src/Requests/ServerRequest.php | 2 ++ src/Requests/VersionRequest.php | 2 ++ tests/TestCase.php | 28 +++++++++++++++-- 17 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 src/ApiErrorHandler.php create mode 100644 src/Exceptions/PageNotFoundException.php create mode 100644 src/Exceptions/RequestException.php diff --git a/src/ApiErrorHandler.php b/src/ApiErrorHandler.php new file mode 100644 index 0000000..9828d2d --- /dev/null +++ b/src/ApiErrorHandler.php @@ -0,0 +1,40 @@ +message->createRequest('GET', $this->url . $this->getEndpoint()); - $result = $this->adapter->sendRequest($request); + $result = null; + + try { + $result = $this->adapter->sendRequest($request); + } catch (HttpException $exception) { + ApiErrorHandler::check($exception->getResponse()->getBody(), $exception->getCode()); + } return json_decode((string)$result->getBody(), true, 512, JSON_BIGINT_AS_STRING); } diff --git a/src/Requests/RuleRequest.php b/src/Requests/RuleRequest.php index fd83237..f95fad7 100644 --- a/src/Requests/RuleRequest.php +++ b/src/Requests/RuleRequest.php @@ -21,6 +21,8 @@ public function getEndpoint(): string * * @return Rule * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function get(): Rule { diff --git a/src/Requests/ServerRequest.php b/src/Requests/ServerRequest.php index 5a47159..79e3750 100644 --- a/src/Requests/ServerRequest.php +++ b/src/Requests/ServerRequest.php @@ -23,6 +23,8 @@ public function getEndpoint(): string * * @return \TruckersMP\Collections\ServerCollection|Server[] * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function get(): ServerCollection { diff --git a/src/Requests/VersionRequest.php b/src/Requests/VersionRequest.php index 5706171..6d949bb 100644 --- a/src/Requests/VersionRequest.php +++ b/src/Requests/VersionRequest.php @@ -21,6 +21,8 @@ public function getEndpoint(): string * * @return Version * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function get(): Version { diff --git a/tests/TestCase.php b/tests/TestCase.php index ce15476..bca068e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -67,6 +67,8 @@ public function __construct() * @return \TruckersMP\Models\Player * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function player(int $id): Player { @@ -86,8 +88,10 @@ public function player(int $id): Player * @param int $id * * @return \TruckersMP\Models\Ban[] - * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function bans(int $id): array { @@ -107,6 +111,8 @@ public function bans(int $id): array * @return \TruckersMP\Collections\ServerCollection|\TruckersMP\Models\Server[] * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function servers(): ServerCollection { @@ -126,6 +132,8 @@ public function servers(): ServerCollection * @return \TruckersMP\Models\GameTime * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function gameTime(): GameTime { @@ -145,6 +153,8 @@ public function gameTime(): GameTime * @return \TruckersMP\Collections\CompanyCollection|Company[] * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function recentCompanies(): CompanyCollection { @@ -183,8 +193,10 @@ public function featuredCompanies(): CompanyCollection * @param int $id * * @return \TruckersMP\Models\Company - * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function company(int $id): Company { @@ -206,6 +218,8 @@ public function company(int $id): Company * @return PostsCollection|\TruckersMP\Models\CompanyPost[] * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function companyPosts(int $id): PostsCollection { @@ -228,6 +242,8 @@ public function companyPosts(int $id): PostsCollection * @return CompanyPost * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function companyPost(int $companyId, int $postId): CompanyPost { @@ -252,6 +268,8 @@ public function companyPost(int $companyId, int $postId): CompanyPost * @return \TruckersMP\Collections\RoleCollection|\TruckersMP\Models\CompanyRole[] * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function companyRoles(int $companyId): RoleCollection { @@ -274,6 +292,8 @@ public function companyRoles(int $companyId): RoleCollection * @return \TruckersMP\Models\CompanyRole * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function companyRole(int $companyId, int $roleId): CompanyRole { @@ -296,6 +316,8 @@ public function companyRole(int $companyId, int $roleId): CompanyRole * @return \TruckersMP\Models\Version * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function version(): Version { @@ -315,6 +337,8 @@ public function version(): Version * @return \TruckersMP\Models\Rule * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function rules(): Rule { From 3731994d3b8196ac99ffd41a7b5b69a88a910478 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 23 Nov 2019 20:57:36 +0000 Subject: [PATCH 064/123] Fixed issue with getting featured companies --- src/Requests/CompaniesRequest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Requests/CompaniesRequest.php b/src/Requests/CompaniesRequest.php index 4325541..421053c 100644 --- a/src/Requests/CompaniesRequest.php +++ b/src/Requests/CompaniesRequest.php @@ -19,6 +19,7 @@ public function getEndpoint(): string /** * Get the data for the request. * + * * @return mixed */ public function get() @@ -52,7 +53,7 @@ public function featured(): CompanyCollection { return new CompanyCollection( $this->call(), - 'featured', + 'featured' ); } } From fa1bc5cc4351cb59134ecdc847cd45268d1d1504 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 23 Nov 2019 21:46:02 +0000 Subject: [PATCH 065/123] Renamed the call method to send on the request class --- src/Models/Company.php | 4 ---- src/Models/CompanyPost.php | 6 ------ src/Models/CompanyRole.php | 6 ------ src/Models/Player.php | 2 -- src/Requests/BanRequest.php | 2 +- src/Requests/Companies/NewsRequest.php | 2 +- src/Requests/Companies/PostRequest.php | 2 +- src/Requests/Companies/RoleRequest.php | 2 +- src/Requests/Companies/RolesRequest.php | 2 +- src/Requests/CompaniesRequest.php | 6 ++++-- src/Requests/CompanyRequest.php | 2 +- src/Requests/GameTimeRequest.php | 2 +- src/Requests/PlayerRequest.php | 2 +- src/Requests/Request.php | 4 ++-- src/Requests/RuleRequest.php | 2 +- src/Requests/ServerRequest.php | 2 +- src/Requests/VersionRequest.php | 2 +- 17 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/Models/Company.php b/src/Models/Company.php index afdb876..c4a1524 100644 --- a/src/Models/Company.php +++ b/src/Models/Company.php @@ -146,10 +146,6 @@ class Company */ public function __construct(array $company) { - if (isset($company['response'])) { - $company = $company['response']; - } - $this->id = $company['id']; $this->name = $company['name']; $this->ownerId = $company['owner_id']; diff --git a/src/Models/CompanyPost.php b/src/Models/CompanyPost.php index 12b5b61..abf8649 100644 --- a/src/Models/CompanyPost.php +++ b/src/Models/CompanyPost.php @@ -60,12 +60,6 @@ class CompanyPost */ public function __construct(array $post) { - // If the data is being passed directly from an API call, then we need to get - // the data from the response element. - if (isset($post['response'])) { - $post = $post['response']; - } - $this->id = $post['id']; $this->title = $post['title']; $this->summary = $post['content_summary']; diff --git a/src/Models/CompanyRole.php b/src/Models/CompanyRole.php index 1fe5b98..eb3540d 100644 --- a/src/Models/CompanyRole.php +++ b/src/Models/CompanyRole.php @@ -55,12 +55,6 @@ class CompanyRole */ public function __construct(array $role) { - // If the data is being passed directly from an API call, then we need to get - // the data from the response element. - if (isset($role['response'])) { - $role = $role['response']; - } - $this->id = $role['id']; $this->name = $role['name']; $this->order = $role['order']; diff --git a/src/Models/Player.php b/src/Models/Player.php index d932c48..b9e3bab 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -90,8 +90,6 @@ class Player */ public function __construct(array $player) { - $player = $player['response']; - $this->id = $player['id']; $this->name = $player['name']; $this->avatar = $player['avatar']; diff --git a/src/Requests/BanRequest.php b/src/Requests/BanRequest.php index 8da90e1..96d81c6 100644 --- a/src/Requests/BanRequest.php +++ b/src/Requests/BanRequest.php @@ -47,7 +47,7 @@ public function getEndpoint(): string public function get(): array { $bans = []; - $results = $this->call(); + $results = $this->send(); // TODO: handle any errors / exceptions diff --git a/src/Requests/Companies/NewsRequest.php b/src/Requests/Companies/NewsRequest.php index 08b954e..bacb7c1 100644 --- a/src/Requests/Companies/NewsRequest.php +++ b/src/Requests/Companies/NewsRequest.php @@ -48,7 +48,7 @@ public function getEndpoint(): string public function get(): PostsCollection { return new PostsCollection( - $this->call() + $this->send() ); } } diff --git a/src/Requests/Companies/PostRequest.php b/src/Requests/Companies/PostRequest.php index f22dd6b..a946d11 100644 --- a/src/Requests/Companies/PostRequest.php +++ b/src/Requests/Companies/PostRequest.php @@ -57,7 +57,7 @@ public function getEndpoint(): string public function get(): CompanyPost { return new CompanyPost( - $this->call() + $this->send()['response'] ); } } diff --git a/src/Requests/Companies/RoleRequest.php b/src/Requests/Companies/RoleRequest.php index 48dc1a4..a491ad1 100644 --- a/src/Requests/Companies/RoleRequest.php +++ b/src/Requests/Companies/RoleRequest.php @@ -56,7 +56,7 @@ public function getEndpoint(): string public function get(): CompanyRole { return new CompanyRole( - $this->call() + $this->send()['response'] ); } } diff --git a/src/Requests/Companies/RolesRequest.php b/src/Requests/Companies/RolesRequest.php index 2412e6f..9e16a3e 100644 --- a/src/Requests/Companies/RolesRequest.php +++ b/src/Requests/Companies/RolesRequest.php @@ -48,7 +48,7 @@ public function getEndpoint(): string public function get(): RoleCollection { return new RoleCollection( - $this->call() + $this->send() ); } } diff --git a/src/Requests/CompaniesRequest.php b/src/Requests/CompaniesRequest.php index 421053c..380cdc6 100644 --- a/src/Requests/CompaniesRequest.php +++ b/src/Requests/CompaniesRequest.php @@ -38,7 +38,7 @@ public function get() public function recent(): CompanyCollection { return new CompanyCollection( - $this->call(), + $this->send(), 'recent' ); } @@ -48,11 +48,13 @@ public function recent(): CompanyCollection * * @return \TruckersMP\Collections\CompanyCollection * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function featured(): CompanyCollection { return new CompanyCollection( - $this->call(), + $this->send(), 'featured' ); } diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index bdb7c51..f4bacc3 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -58,7 +58,7 @@ public function getEndpoint(): string public function get(): Company { return new Company( - $this->call() + $this->send()['response'] ); } diff --git a/src/Requests/GameTimeRequest.php b/src/Requests/GameTimeRequest.php index d14fd30..ebf4089 100644 --- a/src/Requests/GameTimeRequest.php +++ b/src/Requests/GameTimeRequest.php @@ -28,7 +28,7 @@ public function getEndpoint(): string public function get(): GameTime { return new GameTime( - $this->call() + $this->send() ); } } diff --git a/src/Requests/PlayerRequest.php b/src/Requests/PlayerRequest.php index 6a1635f..49c766d 100644 --- a/src/Requests/PlayerRequest.php +++ b/src/Requests/PlayerRequest.php @@ -47,7 +47,7 @@ public function getEndpoint(): string public function get(): Player { return new Player( - $this->call() + $this->send()['response'] ); } } diff --git a/src/Requests/Request.php b/src/Requests/Request.php index 89be6e0..182d6c5 100644 --- a/src/Requests/Request.php +++ b/src/Requests/Request.php @@ -65,14 +65,14 @@ abstract public function getEndpoint(): string; abstract public function get(); /** - * Call the API endpoint and get the result. + * Send the request to the API endpoint and get the result. * * @return array * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException */ - public function call(): array + public function send(): array { $request = $this->message->createRequest('GET', $this->url . $this->getEndpoint()); $result = null; diff --git a/src/Requests/RuleRequest.php b/src/Requests/RuleRequest.php index f95fad7..b50e0c8 100644 --- a/src/Requests/RuleRequest.php +++ b/src/Requests/RuleRequest.php @@ -27,7 +27,7 @@ public function getEndpoint(): string public function get(): Rule { return new Rule( - $this->call() + $this->send() ); } } diff --git a/src/Requests/ServerRequest.php b/src/Requests/ServerRequest.php index 79e3750..86dd0e6 100644 --- a/src/Requests/ServerRequest.php +++ b/src/Requests/ServerRequest.php @@ -29,7 +29,7 @@ public function getEndpoint(): string public function get(): ServerCollection { return new ServerCollection( - $this->call() + $this->send() ); } } diff --git a/src/Requests/VersionRequest.php b/src/Requests/VersionRequest.php index 6d949bb..b5a45ed 100644 --- a/src/Requests/VersionRequest.php +++ b/src/Requests/VersionRequest.php @@ -27,7 +27,7 @@ public function getEndpoint(): string public function get(): Version { return new Version( - $this->call() + $this->send()['response'] ); } } From 25d48b1e9404bd0a273f1d8f4cc1e97c9d70bb17 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 23 Nov 2019 21:50:14 +0000 Subject: [PATCH 066/123] Fixed an issue with the VersionRequest --- src/Requests/VersionRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Requests/VersionRequest.php b/src/Requests/VersionRequest.php index b5a45ed..44b7eea 100644 --- a/src/Requests/VersionRequest.php +++ b/src/Requests/VersionRequest.php @@ -27,7 +27,7 @@ public function getEndpoint(): string public function get(): Version { return new Version( - $this->send()['response'] + $this->send() ); } } From aedaf79077a7215d31ee3100de44a1c5ed2253a6 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 23 Nov 2019 22:21:19 +0000 Subject: [PATCH 067/123] Changed the way we get the recent and featured companies --- src/Collections/CompanyCollection.php | 9 ++-- src/Models/Companies.php | 67 +++++++++++++++++++++++ src/Requests/CompaniesRequest.php | 36 ++----------- src/Requests/CompanyRequest.php | 2 +- tests/TestCase.php | 26 ++------- tests/Unit/CompanyTest.php | 77 ++++++++++++++++++++++++++- 6 files changed, 154 insertions(+), 63 deletions(-) create mode 100644 src/Models/Companies.php diff --git a/src/Collections/CompanyCollection.php b/src/Collections/CompanyCollection.php index f543dfe..2dada44 100644 --- a/src/Collections/CompanyCollection.php +++ b/src/Collections/CompanyCollection.php @@ -9,16 +9,13 @@ class CompanyCollection extends Collection /** * Create a new Collection instance. * - * @param array $response - * @param string $type + * @param array $companies */ - public function __construct(array $response, string $type) + public function __construct(array $companies) { parent::__construct(); - // TODO: handle any errors or exceptions - - foreach ($response['response'][$type] as $key => $company) { + foreach ($companies as $key => $company) { $this->items[$key] = new Company($company); } } diff --git a/src/Models/Companies.php b/src/Models/Companies.php new file mode 100644 index 0000000..1b554f9 --- /dev/null +++ b/src/Models/Companies.php @@ -0,0 +1,67 @@ +recent = new CompanyCollection($response['recent']); + + $this->featured = new CompanyCollection($response['featured']); + + $this->featuredCovered = new CompanyCollection($response['featured_cover']); + } + + /** + * @return \TruckersMP\Collections\CompanyCollection + */ + public function getRecent(): CompanyCollection + { + return $this->recent; + } + + /** + * @return \TruckersMP\Collections\CompanyCollection + */ + public function getFeatured(): CompanyCollection + { + return $this->featured; + } + + /** + * @return \TruckersMP\Collections\CompanyCollection + */ + public function getFeaturedCovered(): \TruckersMP\Collections\CompanyCollection + { + return $this->featuredCovered; + } +} diff --git a/src/Requests/CompaniesRequest.php b/src/Requests/CompaniesRequest.php index 380cdc6..1718ea7 100644 --- a/src/Requests/CompaniesRequest.php +++ b/src/Requests/CompaniesRequest.php @@ -2,7 +2,7 @@ namespace TruckersMP\Requests; -use TruckersMP\Collections\CompanyCollection; +use TruckersMP\Models\Companies; class CompaniesRequest extends Request { @@ -19,43 +19,15 @@ public function getEndpoint(): string /** * Get the data for the request. * - * * @return mixed - */ - public function get() - { - // TODO: Implement get() method. - } - - /** - * Get the recent companies. - * - * @return \TruckersMP\Collections\CompanyCollection - * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException - */ - public function recent(): CompanyCollection - { - return new CompanyCollection( - $this->send(), - 'recent' - ); - } - - /** - * Get the featured companies. - * - * @return \TruckersMP\Collections\CompanyCollection * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException */ - public function featured(): CompanyCollection + public function get(): Companies { - return new CompanyCollection( - $this->send(), - 'featured' + return new Companies( + $this->send()['response'] ); } } diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index f4bacc3..145391a 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -58,7 +58,7 @@ public function getEndpoint(): string public function get(): Company { return new Company( - $this->send()['response'] + $this->send()['responseW'] ); } diff --git a/tests/TestCase.php b/tests/TestCase.php index bca068e..107bdf4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -10,6 +10,7 @@ use TruckersMP\Collections\PostsCollection; use TruckersMP\Collections\RoleCollection; use TruckersMP\Collections\ServerCollection; +use TruckersMP\Models\Companies; use TruckersMP\Models\Company; use TruckersMP\Models\CompanyPost; use TruckersMP\Models\CompanyRole; @@ -150,37 +151,18 @@ public function gameTime(): GameTime /** * Get or cache the recent companies. * - * @return \TruckersMP\Collections\CompanyCollection|Company[] + * @return \TruckersMP\Models\Companies * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException */ - public function recentCompanies(): CompanyCollection + public function companies(): Companies { $cachedCompanies = $this->cache->getItem('recent_companies'); if (! $cachedCompanies->isHit()) { - $cachedCompanies->set($this->client->companies()->recent()); - $this->cache->save($cachedCompanies); - } - - return $cachedCompanies->get(); - } - - /** - * Get or cache the featured companies. - * - * @return \TruckersMP\Collections\CompanyCollection - * @throws \Http\Client\Exception - * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - */ - public function featuredCompanies(): CompanyCollection - { - $cachedCompanies = $this->cache->getItem('featured_companies'); - - if (! $cachedCompanies->isHit()) { - $cachedCompanies->set($this->client->companies()->featured()); + $cachedCompanies->set($this->client->companies()->get()); $this->cache->save($cachedCompanies); } diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index 90cbccf..35c280b 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -5,6 +5,7 @@ use Carbon\Carbon; use Tests\TestCase; use TruckersMP\Collections\CompanyCollection; +use TruckersMP\Models\Companies; use TruckersMP\Models\Company; use TruckersMP\Models\Game; use TruckersMP\Models\Social; @@ -19,10 +20,25 @@ class CompanyTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testWeCanGetTheCompanies() + { + $companies = $this->companies(); + + $this->assertInstanceOf(Companies::class, $companies); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testWeCanGetTheRecentCompanies() { - $companies = $this->recentCompanies(); + $companies = $this->companies()->getRecent(); $this->assertNotEmpty($companies); @@ -32,10 +48,27 @@ public function testWeCanGetTheRecentCompanies() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testWeCanGetTheFeaturedCompanies() { - $companies = $this->featuredCompanies(); + $companies = $this->companies()->getFeatured(); + + $this->assertNotEmpty($companies); + + $this->assertInstanceOf(CompanyCollection::class, $companies); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testWeCanGetTheFeaturedCoverCompanies() + { + $companies = $this->companies()->getFeaturedCovered(); $this->assertNotEmpty($companies); @@ -45,6 +78,8 @@ public function testWeCanGetTheFeaturedCompanies() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testWeCanGetACompany() { @@ -56,6 +91,8 @@ public function testWeCanGetACompany() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnId() { @@ -67,6 +104,8 @@ public function testItHasAnId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAName() { @@ -78,6 +117,8 @@ public function testItHasAName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnOwnerId() { @@ -89,6 +130,8 @@ public function testItHasAnOwnerId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnOwnerName() { @@ -100,6 +143,8 @@ public function testItHasAnOwnerName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasASlogan() { @@ -111,6 +156,8 @@ public function testItHasASlogan() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasATag() { @@ -122,6 +169,8 @@ public function testItHasATag() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasALogo() { @@ -133,6 +182,8 @@ public function testItHasALogo() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasACover() { @@ -144,6 +195,8 @@ public function testItHasACover() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasInformation() { @@ -155,6 +208,8 @@ public function testItHasInformation() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasRules() { @@ -166,6 +221,8 @@ public function testItHasRules() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasRequirements() { @@ -177,6 +234,8 @@ public function testItHasRequirements() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAWebsite() { @@ -188,6 +247,8 @@ public function testItHasAWebsite() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasSocialInformation() { @@ -234,6 +295,8 @@ public function testItHasSocialInformation() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasSupportedGames() { @@ -248,6 +311,8 @@ public function testItHasSupportedGames() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasMemberCount() { @@ -259,6 +324,8 @@ public function testItHasMemberCount() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasARecruitmentState() { @@ -270,6 +337,8 @@ public function testItHasARecruitmentState() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasALanguage() { @@ -281,6 +350,8 @@ public function testItHasALanguage() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testIfItsVerified() { @@ -292,6 +363,8 @@ public function testIfItsVerified() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasACreatedDate() { From b9fa711646e862e18d6f7f0a1cb9422cce663da6 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 24 Nov 2019 12:56:18 +0000 Subject: [PATCH 068/123] Fixed a type in the CompanyRequest class --- src/Requests/CompanyRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index 145391a..f4bacc3 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -58,7 +58,7 @@ public function getEndpoint(): string public function get(): Company { return new Company( - $this->send()['responseW'] + $this->send()['response'] ); } From 48da0ac0db967a900f705021c4b8386f733cedfb Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Mon, 25 Nov 2019 21:24:46 +0000 Subject: [PATCH 069/123] Update composer packages to latest version --- composer.json | 8 +- composer.lock | 517 +++++++++++++++++++++++++------------------------- 2 files changed, 265 insertions(+), 260 deletions(-) diff --git a/composer.json b/composer.json index 8fe70e2..fbb86de 100644 --- a/composer.json +++ b/composer.json @@ -37,11 +37,11 @@ ], "require": { "php": ">=7.1.0", - "nesbot/carbon": "^1.21", - "php-http/message": "^1.2", - "guzzlehttp/psr7": "^1.3", + "nesbot/carbon": "^2.16", "ext-json": "*", - "phpfastcache/phpfastcache": "^7.1" + "phpfastcache/phpfastcache": "^7.1", + "php-http/message": "^1.8", + "guzzlehttp/psr7": "^1.6" }, "require-dev": { "phpunit/phpunit": "^7.0", diff --git a/composer.lock b/composer.lock index 2f520af..a21ac0d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "94474e0699c1a9642266bbd9fbc3210e", + "content-hash": "ba66ac65346ff31be0772b912a130196", "packages": [ { "name": "clue/stream-filter", - "version": "v1.4.0", + "version": "v1.4.1", "source": { "type": "git", "url": "https://github.com/clue/php-stream-filter.git", - "reference": "d80fdee9b3a7e0d16fc330a22f41f3ad0eeb09d0" + "reference": "5a58cc30a8bd6a4eb8f856adf61dd3e013f53f71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/clue/php-stream-filter/zipball/d80fdee9b3a7e0d16fc330a22f41f3ad0eeb09d0", - "reference": "d80fdee9b3a7e0d16fc330a22f41f3ad0eeb09d0", + "url": "https://api.github.com/repos/clue/php-stream-filter/zipball/5a58cc30a8bd6a4eb8f856adf61dd3e013f53f71", + "reference": "5a58cc30a8bd6a4eb8f856adf61dd3e013f53f71", "shasum": "" }, "require": { @@ -32,7 +32,7 @@ "Clue\\StreamFilter\\": "src/" }, "files": [ - "src/functions.php" + "src/functions_include.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -56,37 +56,41 @@ "stream_filter_append", "stream_filter_register" ], - "time": "2017-08-18T09:54:01+00:00" + "time": "2019-04-09T12:31:48+00:00" }, { "name": "guzzlehttp/psr7", - "version": "1.5.2", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "9f83dded91781a01c63574e387eaa769be769115" + "reference": "239400de7a173fe9901b9ac7c06497751f00727a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/9f83dded91781a01c63574e387eaa769be769115", - "reference": "9f83dded91781a01c63574e387eaa769be769115", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a", + "reference": "239400de7a173fe9901b9ac7c06497751f00727a", "shasum": "" }, "require": { "php": ">=5.4.0", "psr/http-message": "~1.0", - "ralouphie/getallheaders": "^2.0.5" + "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" }, "provide": { "psr/http-message-implementation": "1.0" }, "require-dev": { + "ext-zlib": "*", "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" }, + "suggest": { + "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.5-dev" + "dev-master": "1.6-dev" } }, "autoload": { @@ -123,35 +127,43 @@ "uri", "url" ], - "time": "2018-12-04T20:46:45+00:00" + "time": "2019-07-01T23:21:34+00:00" }, { "name": "nesbot/carbon", - "version": "1.36.2", + "version": "2.27.0", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "cd324b98bc30290f233dd0e75e6ce49f7ab2a6c9" + "reference": "13b8485a8690f103bf19cba64879c218b102b726" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/cd324b98bc30290f233dd0e75e6ce49f7ab2a6c9", - "reference": "cd324b98bc30290f233dd0e75e6ce49f7ab2a6c9", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/13b8485a8690f103bf19cba64879c218b102b726", + "reference": "13b8485a8690f103bf19cba64879c218b102b726", "shasum": "" }, "require": { - "php": ">=5.3.9", - "symfony/translation": "~2.6 || ~3.0 || ~4.0" + "ext-json": "*", + "php": "^7.1.8 || ^8.0", + "symfony/translation": "^3.4 || ^4.0 || ^5.0" }, "require-dev": { - "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." + "friendsofphp/php-cs-fixer": "^2.14 || ^3.0", + "kylekatarnls/multi-tester": "^1.1", + "phpmd/phpmd": "dev-php-7.1-compatibility", + "phpstan/phpstan": "^0.11", + "phpunit/phpunit": "^7.5 || ^8.0", + "squizlabs/php_codesniffer": "^3.4" }, + "bin": [ + "bin/carbon" + ], "type": "library", "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + }, "laravel": { "providers": [ "Carbon\\Laravel\\ServiceProvider" @@ -160,7 +172,7 @@ }, "autoload": { "psr-4": { - "": "src/" + "Carbon\\": "src/Carbon/" } }, "notification-url": "https://packagist.org/downloads/", @@ -172,34 +184,38 @@ "name": "Brian Nesbitt", "email": "brian@nesbot.com", "homepage": "http://nesbot.com" + }, + { + "name": "kylekatarnls", + "homepage": "http://github.com/kylekatarnls" } ], - "description": "A simple API extension for DateTime.", + "description": "An API extension for DateTime that supports 281 different languages.", "homepage": "http://carbon.nesbot.com", "keywords": [ "date", "datetime", "time" ], - "time": "2018-12-28T10:07:33+00:00" + "time": "2019-11-20T06:59:06+00:00" }, { "name": "php-http/message", - "version": "1.7.2", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/php-http/message.git", - "reference": "b159ffe570dffd335e22ef0b91a946eacb182fa1" + "reference": "ce8f43ac1e294b54aabf5808515c3554a19c1e1c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-http/message/zipball/b159ffe570dffd335e22ef0b91a946eacb182fa1", - "reference": "b159ffe570dffd335e22ef0b91a946eacb182fa1", + "url": "https://api.github.com/repos/php-http/message/zipball/ce8f43ac1e294b54aabf5808515c3554a19c1e1c", + "reference": "ce8f43ac1e294b54aabf5808515c3554a19c1e1c", "shasum": "" }, "require": { "clue/stream-filter": "^1.4", - "php": "^5.4 || ^7.0", + "php": "^7.1", "php-http/message-factory": "^1.0.2", "psr/http-message": "^1.0" }, @@ -225,7 +241,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6-dev" + "dev-master": "1.8-dev" } }, "autoload": { @@ -253,7 +269,7 @@ "message", "psr-7" ], - "time": "2018-11-01T09:32:41+00:00" + "time": "2019-08-05T06:55:08+00:00" }, { "name": "php-http/message-factory", @@ -551,24 +567,24 @@ }, { "name": "ralouphie/getallheaders", - "version": "2.0.5", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa" + "reference": "120b605dfeb996808c31b6477290a714d356e822" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/5601c8a83fbba7ef674a7369456d12f1e0d0eafa", - "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", "shasum": "" }, "require": { - "php": ">=5.3" + "php": ">=5.6" }, "require-dev": { - "phpunit/phpunit": "~3.7.0", - "satooshi/php-coveralls": ">=1.0" + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" }, "type": "library", "autoload": { @@ -587,48 +603,40 @@ } ], "description": "A polyfill for getallheaders.", - "time": "2016-02-11T07:05:27+00:00" + "time": "2019-03-08T08:55:37+00:00" }, { - "name": "symfony/contracts", - "version": "v1.0.2", + "name": "symfony/polyfill-mbstring", + "version": "v1.12.0", "source": { "type": "git", - "url": "https://github.com/symfony/contracts.git", - "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf" + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/contracts/zipball/1aa7ab2429c3d594dd70689604b5cf7421254cdf", - "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b42a2f66e8f1b15ccf25652c3424265923eb4f17", + "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17", "shasum": "" }, "require": { - "php": "^7.1.3" - }, - "require-dev": { - "psr/cache": "^1.0", - "psr/container": "^1.0" + "php": ">=5.3.3" }, "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": "" + "ext-mbstring": "For best performance" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "1.12-dev" } }, "autoload": { "psr-4": { - "Symfony\\Contracts\\": "" + "Symfony\\Polyfill\\Mbstring\\": "" }, - "exclude-from-classmap": [ - "**/Tests/" + "files": [ + "bootstrap.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -645,50 +653,74 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "A set of abstractions extracted out of the Symfony components", + "description": "Symfony polyfill for the Mbstring extension", "homepage": "https://symfony.com", "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" ], - "time": "2018-12-05T08:06:11+00:00" + "time": "2019-08-06T08:03:45+00:00" }, { - "name": "symfony/polyfill-mbstring", - "version": "v1.11.0", + "name": "symfony/translation", + "version": "v5.0.0", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "fe5e94c604826c35a32fa832f35bd036b6799609" + "url": "https://github.com/symfony/translation.git", + "reference": "e86df1b0f1672362ecf96023faf2c42241c41330" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fe5e94c604826c35a32fa832f35bd036b6799609", - "reference": "fe5e94c604826c35a32fa832f35bd036b6799609", + "url": "https://api.github.com/repos/symfony/translation/zipball/e86df1b0f1672362ecf96023faf2c42241c41330", + "reference": "e86df1b0f1672362ecf96023faf2c42241c41330", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.2.5", + "symfony/polyfill-mbstring": "~1.0", + "symfony/translation-contracts": "^2" + }, + "conflict": { + "symfony/config": "<4.4", + "symfony/dependency-injection": "<5.0", + "symfony/http-kernel": "<5.0", + "symfony/twig-bundle": "<5.0", + "symfony/yaml": "<4.4" + }, + "provide": { + "symfony/translation-implementation": "2.0" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "^4.4|^5.0", + "symfony/console": "^4.4|^5.0", + "symfony/dependency-injection": "^5.0", + "symfony/finder": "^4.4|^5.0", + "symfony/http-kernel": "^5.0", + "symfony/intl": "^4.4|^5.0", + "symfony/service-contracts": "^1.1.2|^2", + "symfony/yaml": "^4.4|^5.0" }, "suggest": { - "ext-mbstring": "For best performance" + "psr/log-implementation": "To use logging capability in translator", + "symfony/config": "", + "symfony/yaml": "" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.11-dev" + "dev-master": "5.0-dev" } }, "autoload": { "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" + "Symfony\\Component\\Translation\\": "" }, - "files": [ - "bootstrap.php" + "exclude-from-classmap": [ + "/Tests/" ] }, "notification-url": "https://packagist.org/downloads/", @@ -697,79 +729,48 @@ ], "authors": [ { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" + "name": "Fabien Potencier", + "email": "fabien@symfony.com" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony polyfill for the Mbstring extension", + "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "mbstring", - "polyfill", - "portable", - "shim" - ], - "time": "2019-02-06T07:57:58+00:00" + "time": "2019-11-18T17:27:11+00:00" }, { - "name": "symfony/translation", - "version": "v4.2.4", + "name": "symfony/translation-contracts", + "version": "v2.0.0", "source": { "type": "git", - "url": "https://github.com/symfony/translation.git", - "reference": "748464177a77011f8f4cdd076773862ce4915f8f" + "url": "https://github.com/symfony/translation-contracts.git", + "reference": "8feb81e6bb1a42d6a3b1429c751d291eb6d05297" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/748464177a77011f8f4cdd076773862ce4915f8f", - "reference": "748464177a77011f8f4cdd076773862ce4915f8f", + "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/8feb81e6bb1a42d6a3b1429c751d291eb6d05297", + "reference": "8feb81e6bb1a42d6a3b1429c751d291eb6d05297", "shasum": "" }, "require": { - "php": "^7.1.3", - "symfony/contracts": "^1.0.2", - "symfony/polyfill-mbstring": "~1.0" - }, - "conflict": { - "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": "~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" + "php": "^7.2.9" }, "suggest": { - "psr/log-implementation": "To use logging capability in translator", - "symfony/config": "", - "symfony/yaml": "" + "symfony/translation-implementation": "" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "2.0-dev" } }, "autoload": { "psr-4": { - "Symfony\\Component\\Translation\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] + "Symfony\\Contracts\\Translation\\": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -777,32 +778,40 @@ ], "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" + "name": "Nicolas Grekas", + "email": "p@tchwork.com" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony Translation Component", + "description": "Generic abstractions related to translation", "homepage": "https://symfony.com", - "time": "2019-02-27T03:31:50+00:00" + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "time": "2019-11-09T09:18:34+00:00" } ], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.2.0", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "a2c590166b2133a4633738648b6b064edae0814a" + "reference": "ae466f726242e637cebdd526a7d991b9433bacf1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", - "reference": "a2c590166b2133a4633738648b6b064edae0814a", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/ae466f726242e637cebdd526a7d991b9433bacf1", + "reference": "ae466f726242e637cebdd526a7d991b9433bacf1", "shasum": "" }, "require": { @@ -845,31 +854,32 @@ "constructor", "instantiate" ], - "time": "2019-03-17T17:37:11+00:00" + "time": "2019-10-21T16:45:58+00:00" }, { "name": "guzzlehttp/guzzle", - "version": "6.3.3", + "version": "6.4.1", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" + "reference": "0895c932405407fd3a7368b6910c09a24d26db11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/0895c932405407fd3a7368b6910c09a24d26db11", + "reference": "0895c932405407fd3a7368b6910c09a24d26db11", "shasum": "" }, "require": { + "ext-json": "*", "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.4", + "guzzlehttp/psr7": "^1.6.1", "php": ">=5.5" }, "require-dev": { "ext-curl": "*", "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", - "psr/log": "^1.0" + "psr/log": "^1.1" }, "suggest": { "psr/log": "Required for using the Log middleware" @@ -881,12 +891,12 @@ } }, "autoload": { - "files": [ - "src/functions_include.php" - ], "psr-4": { "GuzzleHttp\\": "src/" - } + }, + "files": [ + "src/functions_include.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -910,7 +920,7 @@ "rest", "web service" ], - "time": "2018-04-22T15:46:56+00:00" + "time": "2019-10-23T15:58:00+00:00" }, { "name": "guzzlehttp/promises", @@ -965,16 +975,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.8.1", + "version": "1.9.3", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", - "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea", + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea", "shasum": "" }, "require": { @@ -1009,7 +1019,7 @@ "object", "object graph" ], - "time": "2018-06-11T23:09:50+00:00" + "time": "2019-08-09T12:45:53+00:00" }, { "name": "phar-io/manifest", @@ -1281,35 +1291,33 @@ }, { "name": "phpdocumentor/reflection-common", - "version": "1.0.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", "shasum": "" }, "require": { - "php": ">=5.5" + "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": "^4.6" + "phpunit/phpunit": "~6" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src" - ] + "phpDocumentor\\Reflection\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -1331,30 +1339,30 @@ "reflection", "static analysis" ], - "time": "2017-09-11T18:02:19+00:00" + "time": "2018-08-07T13:53:10+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.0", + "version": "4.3.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08" + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e", + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e", "shasum": "" }, "require": { "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0.0", - "phpdocumentor/type-resolver": "^0.4.0", + "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", + "phpdocumentor/type-resolver": "~0.4 || ^1.0.0", "webmozart/assert": "^1.0" }, "require-dev": { - "doctrine/instantiator": "~1.0.5", + "doctrine/instantiator": "^1.0.5", "mockery/mockery": "^1.0", "phpunit/phpunit": "^6.4" }, @@ -1382,41 +1390,40 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-11-30T07:14:17+00:00" + "time": "2019-09-12T14:27:41+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "0.4.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", "shasum": "" }, "require": { - "php": "^5.5 || ^7.0", - "phpdocumentor/reflection-common": "^1.0" + "php": "^7.1", + "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^5.2||^4.8.24" + "ext-tokenizer": "^7.1", + "mockery/mockery": "~1", + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -1429,26 +1436,27 @@ "email": "me@mikevanriel.com" } ], - "time": "2017-07-14T14:27:02+00:00" + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "time": "2019-08-22T18:11:29+00:00" }, { "name": "phpspec/prophecy", - "version": "1.8.0", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/f6811d96d97bdf400077a0cc100ae56aa32b9203", + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0", "sebastian/comparator": "^1.1|^2.0|^3.0", "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, @@ -1463,8 +1471,8 @@ } }, "autoload": { - "psr-0": { - "Prophecy\\": "src/" + "psr-4": { + "Prophecy\\": "src/Prophecy" } }, "notification-url": "https://packagist.org/downloads/", @@ -1492,7 +1500,7 @@ "spy", "stub" ], - "time": "2018-08-05T17:53:17+00:00" + "time": "2019-10-03T11:07:50+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1650,16 +1658,16 @@ }, { "name": "phpunit/php-timer", - "version": "2.1.1", + "version": "2.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059" + "reference": "1038454804406b0b5f5f520358e78c1c2f71501e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b389aebe1b8b0578430bda0c7c95a829608e059", - "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/1038454804406b0b5f5f520358e78c1c2f71501e", + "reference": "1038454804406b0b5f5f520358e78c1c2f71501e", "shasum": "" }, "require": { @@ -1695,20 +1703,20 @@ "keywords": [ "timer" ], - "time": "2019-02-20T10:12:59+00:00" + "time": "2019-06-07T04:22:29+00:00" }, { "name": "phpunit/php-token-stream", - "version": "3.0.1", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18" + "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c99e3be9d3e85f60646f152f9002d46ed7770d18", - "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/995192df77f63a59e47f025390d2d1fdf8f425ff", + "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff", "shasum": "" }, "require": { @@ -1721,7 +1729,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -1744,20 +1752,20 @@ "keywords": [ "tokenizer" ], - "time": "2018-10-30T05:52:18+00:00" + "time": "2019-09-17T06:23:10+00:00" }, { "name": "phpunit/phpunit", - "version": "7.5.8", + "version": "7.5.17", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c29c0525cf4572c11efe1db49a8b8aee9dfac58a" + "reference": "4c92a15296e58191a4cd74cff3b34fc8e374174a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c29c0525cf4572c11efe1db49a8b8aee9dfac58a", - "reference": "c29c0525cf4572c11efe1db49a8b8aee9dfac58a", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4c92a15296e58191a4cd74cff3b34fc8e374174a", + "reference": "4c92a15296e58191a4cd74cff3b34fc8e374174a", "shasum": "" }, "require": { @@ -1828,7 +1836,7 @@ "testing", "xunit" ], - "time": "2019-03-26T13:23:54+00:00" + "time": "2019-10-28T10:37:36+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -1997,16 +2005,16 @@ }, { "name": "sebastian/environment", - "version": "4.1.0", + "version": "4.2.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "6fda8ce1974b62b14935adc02a9ed38252eca656" + "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6fda8ce1974b62b14935adc02a9ed38252eca656", - "reference": "6fda8ce1974b62b14935adc02a9ed38252eca656", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/464c90d7bdf5ad4e8a6aea15c091fec0603d4368", + "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368", "shasum": "" }, "require": { @@ -2021,7 +2029,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -2046,20 +2054,20 @@ "environment", "hhvm" ], - "time": "2019-02-01T05:27:49+00:00" + "time": "2019-11-20T08:46:58+00:00" }, { "name": "sebastian/exporter", - "version": "3.1.0", + "version": "3.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "234199f4528de6d12aaa58b612e98f7d36adb937" + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937", - "reference": "234199f4528de6d12aaa58b612e98f7d36adb937", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", "shasum": "" }, "require": { @@ -2086,6 +2094,10 @@ "BSD-3-Clause" ], "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, { "name": "Jeff Welch", "email": "whatthejeff@gmail.com" @@ -2094,17 +2106,13 @@ "name": "Volker Dusch", "email": "github@wallbash.com" }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, { "name": "Adam Harvey", "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" } ], "description": "Provides the functionality to export PHP variables for visualization", @@ -2113,7 +2121,7 @@ "export", "exporter" ], - "time": "2017-04-03T13:19:02+00:00" + "time": "2019-09-14T09:02:43+00:00" }, { "name": "sebastian/global-state", @@ -2476,16 +2484,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.11.0", + "version": "v1.12.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "82ebae02209c21113908c229e9883c419720738a" + "reference": "550ebaac289296ce228a706d0867afc34687e3f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", - "reference": "82ebae02209c21113908c229e9883c419720738a", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4", "shasum": "" }, "require": { @@ -2497,7 +2505,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.11-dev" + "dev-master": "1.12-dev" } }, "autoload": { @@ -2514,12 +2522,12 @@ ], "authors": [ { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" }, { - "name": "Gert de Pagter", - "email": "backendtea@gmail.com" + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], "description": "Symfony polyfill for ctype functions", @@ -2530,20 +2538,20 @@ "polyfill", "portable" ], - "time": "2019-02-06T07:57:58+00:00" + "time": "2019-08-06T08:03:45+00:00" }, { "name": "theseer/tokenizer", - "version": "1.1.0", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b" + "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/cb2f008f3f05af2893a87208fe6a6c4985483f8b", - "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/11336f6f84e16a720dae9d8e6ed5019efa85a0f9", + "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9", "shasum": "" }, "require": { @@ -2570,36 +2578,33 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", - "time": "2017-04-07T12:08:54+00:00" + "time": "2019-06-13T22:48:21+00:00" }, { "name": "webmozart/assert", - "version": "1.4.0", + "version": "1.6.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" + "reference": "573381c0a64f155a0d9a23f4b0c797194805b925" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", + "url": "https://api.github.com/repos/webmozart/assert/zipball/573381c0a64f155a0d9a23f4b0c797194805b925", + "reference": "573381c0a64f155a0d9a23f4b0c797194805b925", "shasum": "" }, "require": { "php": "^5.3.3 || ^7.0", "symfony/polyfill-ctype": "^1.8" }, + "conflict": { + "vimeo/psalm": "<3.6.0" + }, "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" + "phpunit/phpunit": "^4.8.36 || ^7.5.13" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, "autoload": { "psr-4": { "Webmozart\\Assert\\": "src/" @@ -2621,7 +2626,7 @@ "check", "validate" ], - "time": "2018-12-25T11:19:39+00:00" + "time": "2019-11-24T13:36:37+00:00" } ], "aliases": [], From 4c772cae401d415c3961c5c7c851126c87c49789 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Mon, 25 Nov 2019 22:03:10 +0000 Subject: [PATCH 070/123] Renamed the Companies model and refactored some requests --- src/Client.php | 1 + src/Collections/PostsCollection.php | 4 +-- src/Collections/RoleCollection.php | 4 +-- src/Collections/ServerCollection.php | 4 +-- src/Models/Ban.php | 4 ++- src/Models/Checksum.php | 9 +++--- src/Models/Company.php | 8 ++--- .../{Companies.php => CompanyIndex.php} | 4 +-- src/Models/CompanyRole.php | 8 +++-- src/Models/Player.php | 26 +++++++++++++--- src/Models/Social.php | 28 ++++++----------- src/Models/Version.php | 8 ++--- src/Requests/Companies/NewsRequest.php | 2 +- src/Requests/Companies/RolesRequest.php | 2 +- src/Requests/CompaniesRequest.php | 6 ++-- src/Requests/ServerRequest.php | 2 +- tests/TestCase.php | 9 +++--- tests/Unit/CompanyTest.php | 4 +-- tests/Unit/PlayerTest.php | 30 ++++++++++++++++++- 19 files changed, 97 insertions(+), 66 deletions(-) rename src/Models/{Companies.php => CompanyIndex.php} (93%) diff --git a/src/Client.php b/src/Client.php index 851c61a..1bc2f5b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -5,6 +5,7 @@ use TruckersMP\Collections\CompanyCollection; use TruckersMP\Requests\BanRequest; use TruckersMP\Requests\CompaniesRequest; +use TruckersMP\Requests\IndexRequest; use TruckersMP\Requests\CompanyRequest; use TruckersMP\Requests\GameTimeRequest; use TruckersMP\Requests\PlayerRequest; diff --git a/src/Collections/PostsCollection.php b/src/Collections/PostsCollection.php index a9a27dc..26c452f 100644 --- a/src/Collections/PostsCollection.php +++ b/src/Collections/PostsCollection.php @@ -15,9 +15,7 @@ public function __construct(array $response) { parent::__construct(); - // TODO: handle any errors or exceptions - - foreach ($response['response']['news'] as $key => $post) { + foreach ($response['news'] as $key => $post) { $this->items[$key] = new CompanyPost($post); } } diff --git a/src/Collections/RoleCollection.php b/src/Collections/RoleCollection.php index c78e45a..8ba99f2 100644 --- a/src/Collections/RoleCollection.php +++ b/src/Collections/RoleCollection.php @@ -15,9 +15,7 @@ public function __construct(array $response) { parent::__construct(); - // TODO: handle any errors or exceptions - - foreach ($response['response']['roles'] as $key => $role) { + foreach ($response['roles'] as $key => $role) { $this->items[$key] = new CompanyRole($role); } } diff --git a/src/Collections/ServerCollection.php b/src/Collections/ServerCollection.php index 4e71cf4..6d835ad 100644 --- a/src/Collections/ServerCollection.php +++ b/src/Collections/ServerCollection.php @@ -15,9 +15,7 @@ public function __construct(array $response) { parent::__construct(); - // TODO: handle any errors or exceptions - - foreach ($response['response'] as $key => $server) { + foreach ($response as $key => $server) { $this->items[$key] = new Server($server); } } diff --git a/src/Models/Ban.php b/src/Models/Ban.php index cafcb61..8d954fc 100644 --- a/src/Models/Ban.php +++ b/src/Models/Ban.php @@ -52,6 +52,8 @@ class Ban * Create a new Ban instance. * * @param array $ban + * + * @throws \Exception */ public function __construct(array $ban) { @@ -89,7 +91,7 @@ public function getExpirationDate(): ?Carbon /** * @return \Carbon\Carbon */ - public function getCreatedDate(): Carbon + public function getCreatedAt(): Carbon { return $this->timeAdded; } diff --git a/src/Models/Checksum.php b/src/Models/Checksum.php index 1c2d985..c71f10e 100644 --- a/src/Models/Checksum.php +++ b/src/Models/Checksum.php @@ -21,13 +21,12 @@ class Checksum /** * Create a new Checksum instance. * - * @param string $dll - * @param string $adb + * @param array $checksum */ - public function __construct(string $dll, string $adb) + public function __construct(array $checksum) { - $this->dll = $dll; - $this->adb = $adb; + $this->dll = $checksum['dll']; + $this->adb = $checksum['adb']; } /** diff --git a/src/Models/Company.php b/src/Models/Company.php index c4a1524..ac16d9e 100644 --- a/src/Models/Company.php +++ b/src/Models/Company.php @@ -143,6 +143,8 @@ class Company * Create a new Company instance. * * @param array $company + * + * @throws \Exception */ public function __construct(array $company) { @@ -176,11 +178,7 @@ public function __construct(array $company) $this->website = $company['website']; $this->social = new Social( - $company['socials']['twitter'], - $company['socials']['facebook'], - $company['socials']['playstv'], - $company['socials']['discord'], - $company['socials']['youtube'] + $company['socials'] ); $this->games = new Game( diff --git a/src/Models/Companies.php b/src/Models/CompanyIndex.php similarity index 93% rename from src/Models/Companies.php rename to src/Models/CompanyIndex.php index 1b554f9..3b3f0bc 100644 --- a/src/Models/Companies.php +++ b/src/Models/CompanyIndex.php @@ -4,7 +4,7 @@ use TruckersMP\Collections\CompanyCollection; -class Companies +class CompanyIndex { /** * The recently created companies. @@ -60,7 +60,7 @@ public function getFeatured(): CompanyCollection /** * @return \TruckersMP\Collections\CompanyCollection */ - public function getFeaturedCovered(): \TruckersMP\Collections\CompanyCollection + public function getFeaturedCovered(): CompanyCollection { return $this->featuredCovered; } diff --git a/src/Models/CompanyRole.php b/src/Models/CompanyRole.php index eb3540d..e8deae7 100644 --- a/src/Models/CompanyRole.php +++ b/src/Models/CompanyRole.php @@ -51,7 +51,9 @@ class CompanyRole /** * Create a new CompanyRole instance. * - * @param array $role + * @param array $role + * + * @throws \Exception */ public function __construct(array $role) { @@ -98,7 +100,7 @@ public function isOwner(): bool /** * @return \Carbon\Carbon */ - public function getCreatedAt(): \Carbon\Carbon + public function getCreatedAt(): Carbon { return $this->createdAt; } @@ -106,7 +108,7 @@ public function getCreatedAt(): \Carbon\Carbon /** * @return \Carbon\Carbon */ - public function getUpdatedAt(): \Carbon\Carbon + public function getUpdatedAt(): Carbon { return $this->updatedAt; } diff --git a/src/Models/Player.php b/src/Models/Player.php index b9e3bab..d7131d2 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -27,6 +27,13 @@ class Player */ protected $avatar; + /** + * URL to the small avatar on the website; + * + * @var string + */ + protected $smallAvatar; + /** * The date and time the user registered (UTC). * @@ -46,7 +53,7 @@ class Player * * @var int */ - protected $groupID; + protected $groupId; /** * The name of the group the user belongs to. @@ -87,15 +94,18 @@ class Player * Create a new Player instance. * * @param array $player + * + * @throws \Exception */ public function __construct(array $player) { $this->id = $player['id']; $this->name = $player['name']; $this->avatar = $player['avatar']; + $this->smallAvatar = $player['smallAvatar']; $this->joinDate = new Carbon($player['joinDate'], 'UTC'); $this->steamID64 = $player['steamID64']; - $this->groupID = $player['groupID']; + $this->groupId = $player['groupID']; $this->groupName = $player['groupName']; $this->isBanned = $player['banned']; $this->bannedUntil = new Carbon($player['bannedUntil'], 'UTC'); @@ -127,6 +137,14 @@ public function getAvatar(): string return $this->avatar; } + /** + * @return string + */ + public function getSmallAvatar(): string + { + return $this->smallAvatar; + } + /** * @return Carbon */ @@ -146,9 +164,9 @@ public function getSteamID64(): string /** * @return int */ - public function getGroupID(): int + public function getGroupId(): int { - return $this->groupID; + return $this->groupId; } /** diff --git a/src/Models/Social.php b/src/Models/Social.php index 52ad51d..afd2695 100644 --- a/src/Models/Social.php +++ b/src/Models/Social.php @@ -32,25 +32,15 @@ class Social /** * Create a new Social instance. * - * @param string|null $twitter - * @param string|null $facebook - * @param string|null $plays - * @param string|null $discord - * @param string|null $youtube + * @param array $social */ - public function __construct( - string $twitter = null, - string $facebook = null, - string $plays = null, - string $discord = null, - string $youtube = null - ) { - - $this->twitter = $twitter; - $this->facebook = $facebook; - $this->plays = $plays; - $this->discord = $discord; - $this->youtube = $youtube; + public function __construct(array $social) + { + $this->twitter = $social['twitter']; + $this->facebook = $social['facebook']; + $this->plays = $social['playstv']; + $this->discord = $social['discord']; + $this->youtube = $social['youtube']; } /** @@ -88,7 +78,7 @@ public function getDiscord(): ?string /** * @return string|null */ - public function getYoutube(): ?string + public function getYouTube(): ?string { return $this->youtube; } diff --git a/src/Models/Version.php b/src/Models/Version.php index 2399799..6b62f72 100644 --- a/src/Models/Version.php +++ b/src/Models/Version.php @@ -66,6 +66,8 @@ class Version * Create a new Version instance. * * @param array $version + * + * @throws \Exception */ public function __construct(array $version) { @@ -74,13 +76,11 @@ public function __construct(array $version) $this->stage = $version['stage']; $this->ets2mpChecksum = new Checksum( - $version['ets2mp_checksum']['dll'], - $version['ets2mp_checksum']['adb'] + $version['ets2mp_checksum'] ); $this->atsmpChecksum = new Checksum( - $version['atsmp_checksum']['dll'], - $version['atsmp_checksum']['adb'] + $version['atsmp_checksum'] ); $this->time = new Carbon($version['time'], 'UTC'); diff --git a/src/Requests/Companies/NewsRequest.php b/src/Requests/Companies/NewsRequest.php index bacb7c1..bdb6a37 100644 --- a/src/Requests/Companies/NewsRequest.php +++ b/src/Requests/Companies/NewsRequest.php @@ -48,7 +48,7 @@ public function getEndpoint(): string public function get(): PostsCollection { return new PostsCollection( - $this->send() + $this->send()['response'] ); } } diff --git a/src/Requests/Companies/RolesRequest.php b/src/Requests/Companies/RolesRequest.php index 9e16a3e..923541f 100644 --- a/src/Requests/Companies/RolesRequest.php +++ b/src/Requests/Companies/RolesRequest.php @@ -48,7 +48,7 @@ public function getEndpoint(): string public function get(): RoleCollection { return new RoleCollection( - $this->send() + $this->send()['response'] ); } } diff --git a/src/Requests/CompaniesRequest.php b/src/Requests/CompaniesRequest.php index 1718ea7..3e8cc4c 100644 --- a/src/Requests/CompaniesRequest.php +++ b/src/Requests/CompaniesRequest.php @@ -2,7 +2,7 @@ namespace TruckersMP\Requests; -use TruckersMP\Models\Companies; +use TruckersMP\Models\CompanyIndex; class CompaniesRequest extends Request { @@ -24,9 +24,9 @@ public function getEndpoint(): string * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException */ - public function get(): Companies + public function get(): CompanyIndex { - return new Companies( + return new CompanyIndex( $this->send()['response'] ); } diff --git a/src/Requests/ServerRequest.php b/src/Requests/ServerRequest.php index 86dd0e6..d093062 100644 --- a/src/Requests/ServerRequest.php +++ b/src/Requests/ServerRequest.php @@ -29,7 +29,7 @@ public function getEndpoint(): string public function get(): ServerCollection { return new ServerCollection( - $this->send() + $this->send()['response'] ); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 107bdf4..123ba3c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,19 +6,18 @@ use Phpfastcache\Config\ConfigurationOption; use PHPUnit\Framework\TestCase as BaseTestCase; use TruckersMP\Client; -use TruckersMP\Collections\CompanyCollection; use TruckersMP\Collections\PostsCollection; use TruckersMP\Collections\RoleCollection; use TruckersMP\Collections\ServerCollection; -use TruckersMP\Models\Companies; use TruckersMP\Models\Company; +use TruckersMP\Models\CompanyIndex; use TruckersMP\Models\CompanyPost; use TruckersMP\Models\CompanyRole; use TruckersMP\Models\GameTime; use TruckersMP\Models\Player; use TruckersMP\Models\Rule; use TruckersMP\Models\Version; -use TruckersMP\Requests\Companies\PostRequest; +use TruckersMP\Requests\CompaniesRequest; class TestCase extends BaseTestCase { @@ -151,13 +150,13 @@ public function gameTime(): GameTime /** * Get or cache the recent companies. * - * @return \TruckersMP\Models\Companies + * @return \TruckersMP\Models\CompanyIndex * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException */ - public function companies(): Companies + public function companies(): CompanyIndex { $cachedCompanies = $this->cache->getItem('recent_companies'); diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index 35c280b..2507d0c 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -5,7 +5,7 @@ use Carbon\Carbon; use Tests\TestCase; use TruckersMP\Collections\CompanyCollection; -use TruckersMP\Models\Companies; +use TruckersMP\Models\CompanyIndex; use TruckersMP\Models\Company; use TruckersMP\Models\Game; use TruckersMP\Models\Social; @@ -27,7 +27,7 @@ public function testWeCanGetTheCompanies() { $companies = $this->companies(); - $this->assertInstanceOf(Companies::class, $companies); + $this->assertInstanceOf(CompanyIndex::class, $companies); } /** diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index 9a95dad..a3f0538 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -16,6 +16,8 @@ class PlayerTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testWeCanGetThePlayer() { @@ -27,6 +29,8 @@ public function testWeCanGetThePlayer() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnId() { @@ -38,6 +42,8 @@ public function testItHasAnId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAName() { @@ -49,17 +55,25 @@ public function testItHasAName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnAvatar() { $player = $this->player(self::TEST_ACCOUNT); $this->assertIsString($player->getAvatar()); + + if ($player->getSmallAvatar() != null) { + $this->assertIsString($player->getSmallAvatar()); + } } /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAJoinDate() { @@ -71,6 +85,8 @@ public function testItHasAJoinDate() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasASteamId() { @@ -82,6 +98,8 @@ public function testItHasASteamId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAGroupName() { @@ -93,17 +111,21 @@ public function testItHasAGroupName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAGroupId() { $player = $this->player(self::TEST_ACCOUNT); - $this->assertIsInt($player->getGroupID()); + $this->assertIsInt($player->getGroupId()); } /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testIfItIsBanned() { @@ -115,6 +137,8 @@ public function testIfItIsBanned() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasABannedUntilDate() { @@ -126,6 +150,8 @@ public function testItHasABannedUntilDate() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testIfBansAreHidden() { @@ -137,6 +163,8 @@ public function testIfBansAreHidden() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasIfAdmin() { From 9449f0e42b4f081700c8570866c702aacd7f9092 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Mon, 25 Nov 2019 22:18:15 +0000 Subject: [PATCH 071/123] Updated PHPDoc comments and removed support for PHP 7.1 --- .travis.yml | 2 +- composer.json | 2 +- readme.md | 2 +- tests/Unit/BanTest.php | 26 +++++++++----- tests/Unit/ChecksumTest.php | 4 +++ tests/Unit/CompanyPostTest.php | 18 ++++++++++ tests/Unit/CompanyRoleTest.php | 16 +++++++++ tests/Unit/GameTimeTest.php | 2 ++ tests/Unit/RuleTest.php | 9 +++-- tests/Unit/ServerTest.php | 65 +++++++++++++++++++++++----------- 10 files changed, 110 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index 743e839..8f4f7ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,9 +7,9 @@ cache: - $HOME/.composer/cache php: - - 7.1 - 7.2 - 7.3 + - 7.4 before_install: - composer self-update diff --git a/composer.json b/composer.json index fbb86de..80586ec 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ } ], "require": { - "php": ">=7.1.0", + "php": ">=7.2.9", "nesbot/carbon": "^2.16", "ext-json": "*", "phpfastcache/phpfastcache": "^7.1", diff --git a/readme.md b/readme.md index c90bc6c..93d4b10 100644 --- a/readme.md +++ b/readme.md @@ -20,7 +20,7 @@ Please use our service responsibly. People who make lots of requests to our API ## Requirements -- PHP 7.1.0 or newer +- PHP 7.2.0 or newer - Composer ## Installation diff --git a/tests/Unit/BanTest.php b/tests/Unit/BanTest.php index 02ced29..a12fed5 100644 --- a/tests/Unit/BanTest.php +++ b/tests/Unit/BanTest.php @@ -16,6 +16,8 @@ class BanTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testWeCanGetAllBans() { @@ -30,8 +32,9 @@ public function testWeCanGetAllBans() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnExpiryDate() { @@ -52,8 +55,9 @@ public function testItHasAnExpiryDate() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasACreatedDate() { @@ -62,7 +66,7 @@ public function testItHasACreatedDate() if (count($bans) > 0) { $ban = $bans[0]; - $this->assertInstanceOf(Carbon::class, $ban->getCreatedDate()); + $this->assertInstanceOf(Carbon::class, $ban->getCreatedAt()); } else { $this->assertCount(0, $bans); } @@ -70,8 +74,9 @@ public function testItHasACreatedDate() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnActiveState() { @@ -88,8 +93,9 @@ public function testItHasAnActiveState() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAReason() { @@ -105,9 +111,10 @@ public function testItHasAReason() } /** - * @throws \TruckersMP\Exceptions\IndexNotFoundException - * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasTheNameOfTheAdmin() { @@ -123,9 +130,10 @@ public function testItHasTheNameOfTheAdmin() } /** - * @throws \TruckersMP\Exceptions\IndexNotFoundException - * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasTheIdOfTheAdmin() { diff --git a/tests/Unit/ChecksumTest.php b/tests/Unit/ChecksumTest.php index eece854..41e6c01 100644 --- a/tests/Unit/ChecksumTest.php +++ b/tests/Unit/ChecksumTest.php @@ -9,6 +9,8 @@ class ChecksumTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasADLL() { @@ -20,6 +22,8 @@ public function testItHasADLL() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnADB() { diff --git a/tests/Unit/CompanyPostTest.php b/tests/Unit/CompanyPostTest.php index 40f22f2..8f2311f 100644 --- a/tests/Unit/CompanyPostTest.php +++ b/tests/Unit/CompanyPostTest.php @@ -21,6 +21,8 @@ class CompanyPostTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testWeCanGetAllTheNewsPosts() { @@ -38,6 +40,8 @@ public function testWeCanGetAllTheNewsPosts() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testWeCanGetAPost() { @@ -49,6 +53,8 @@ public function testWeCanGetAPost() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnId() { @@ -60,6 +66,8 @@ public function testItHasAnId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasATitle() { @@ -71,6 +79,8 @@ public function testItHasATitle() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasASummary() { @@ -82,6 +92,8 @@ public function testItHasASummary() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasCotent() { @@ -93,6 +105,8 @@ public function testItHasCotent() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnAuthorId() { @@ -104,6 +118,8 @@ public function testItHasAnAuthorId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnAuthor() { @@ -115,6 +131,8 @@ public function testItHasAnAuthor() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testIfThePostIsPinned() { diff --git a/tests/Unit/CompanyRoleTest.php b/tests/Unit/CompanyRoleTest.php index 58258c8..c675f15 100644 --- a/tests/Unit/CompanyRoleTest.php +++ b/tests/Unit/CompanyRoleTest.php @@ -22,6 +22,8 @@ class CompanyRoleTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testWeCanGetAllTheRoles() { @@ -39,6 +41,8 @@ public function testWeCanGetAllTheRoles() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testWeCanGetARole() { @@ -50,6 +54,8 @@ public function testWeCanGetARole() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnId() { @@ -61,6 +67,8 @@ public function testItHasAnId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAName() { @@ -72,6 +80,8 @@ public function testItHasAName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnOrder() { @@ -83,6 +93,8 @@ public function testItHasAnOrder() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testIfItIsAnOwner() { @@ -94,6 +106,8 @@ public function testIfItIsAnOwner() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasACreatedAtDate() { @@ -105,6 +119,8 @@ public function testItHasACreatedAtDate() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnUpdatedAtDate() { diff --git a/tests/Unit/GameTimeTest.php b/tests/Unit/GameTimeTest.php index de0c1f1..4db7a1d 100644 --- a/tests/Unit/GameTimeTest.php +++ b/tests/Unit/GameTimeTest.php @@ -11,6 +11,8 @@ class GameTimeTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testWeCanGetTheGameTime() { diff --git a/tests/Unit/RuleTest.php b/tests/Unit/RuleTest.php index da86e30..849dea3 100644 --- a/tests/Unit/RuleTest.php +++ b/tests/Unit/RuleTest.php @@ -9,8 +9,9 @@ class RuleTest extends TestCase { /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\APIErrorException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testWeCanGetTheRules() { @@ -21,8 +22,9 @@ public function testWeCanGetTheRules() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\APIErrorException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasTheRules() { @@ -33,8 +35,9 @@ public function testItHasTheRules() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\APIErrorException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasTheRevision() { diff --git a/tests/Unit/ServerTest.php b/tests/Unit/ServerTest.php index 4fd55a1..9ab14d6 100644 --- a/tests/Unit/ServerTest.php +++ b/tests/Unit/ServerTest.php @@ -11,6 +11,8 @@ class ServerTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testWeCanGetAllTheServers() { @@ -25,8 +27,9 @@ public function testWeCanGetAllTheServers() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnId() { @@ -37,8 +40,9 @@ public function testItHasAnId() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAGame() { @@ -49,8 +53,9 @@ public function testItHasAGame() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnIp() { @@ -61,8 +66,9 @@ public function testItHasAnIp() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAPort() { @@ -73,8 +79,9 @@ public function testItHasAPort() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAName() { @@ -85,8 +92,9 @@ public function testItHasAName() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAShortName() { @@ -97,8 +105,9 @@ public function testItHasAShortName() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnIdPrefix() { @@ -113,8 +122,9 @@ public function testItHasAnIdPrefix() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnOnlineState() { @@ -125,8 +135,9 @@ public function testItHasAnOnlineState() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasPlayers() { @@ -137,8 +148,9 @@ public function testItHasPlayers() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAQueue() { @@ -149,8 +161,9 @@ public function testItHasAQueue() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasMaxPlayers() { @@ -161,8 +174,9 @@ public function testItHasMaxPlayers() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasADisplayOrder() { @@ -173,8 +187,9 @@ public function testItHasADisplayOrder() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasASpeedLimit() { @@ -185,8 +200,9 @@ public function testItHasASpeedLimit() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasCollisions() { @@ -197,8 +213,9 @@ public function testItHasCollisions() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasCarsForPlayers() { @@ -209,8 +226,9 @@ public function testItHasCarsForPlayers() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasPoliceCarsForPlayers() { @@ -221,8 +239,9 @@ public function testItHasPoliceCarsForPlayers() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAfkEnable() { @@ -233,8 +252,9 @@ public function testItHasAfkEnable() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasAnEvent() { @@ -245,8 +265,9 @@ public function testItHasAnEvent() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasASpecialEvent() { @@ -257,8 +278,9 @@ public function testItHasASpecialEvent() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasPromods() { @@ -269,8 +291,9 @@ public function testItHasPromods() /** * @throws \Http\Client\Exception - * @throws \TruckersMP\Exceptions\IndexNotFoundException * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function testItHasSyncDelay() { From 48703e592ed7642fdac6ca9ba4f5a1f93759320f Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Mon, 25 Nov 2019 22:23:14 +0000 Subject: [PATCH 072/123] Removed PHP 7.4 from Travis CI config --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8f4f7ff..0bcdbaf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ cache: php: - 7.2 - 7.3 - - 7.4 before_install: - composer self-update From 43e32e60c9bd8dbba4b1c1cb211908b103f03f2a Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 26 Nov 2019 15:37:43 +0000 Subject: [PATCH 073/123] Added the ability to get a company member --- src/Models/CompanyMember.php | 129 ++++++++++++++++++++++ src/Requests/Companies/MemberRequest.php | 63 +++++++++++ src/Requests/CompanyRequest.php | 17 +++ tests/TestCase.php | 38 ++++++- tests/Unit/CompanyMemberTest.php | 131 +++++++++++++++++++++++ 5 files changed, 373 insertions(+), 5 deletions(-) create mode 100644 src/Models/CompanyMember.php create mode 100644 src/Requests/Companies/MemberRequest.php create mode 100644 tests/Unit/CompanyMemberTest.php diff --git a/src/Models/CompanyMember.php b/src/Models/CompanyMember.php new file mode 100644 index 0000000..c42c415 --- /dev/null +++ b/src/Models/CompanyMember.php @@ -0,0 +1,129 @@ +id = $member['id']; + $this->userId = $member['user_id']; + $this->username = $member['username']; + $this->steamId = $member['steam_id']; + $this->roleId = $member['role_id']; + $this->role = $member['role']; + $this->joinDate = new Carbon($member['joinDate'], 'UTC'); + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return int + */ + public function getUserId(): int + { + return $this->userId; + } + + /** + * @return string + */ + public function getUsername(): string + { + return $this->username; + } + + /** + * @return string + */ + public function getSteamId(): string + { + return $this->steamId; + } + + /** + * @return int + */ + public function getRoleId(): int + { + return $this->roleId; + } + + /** + * @return string + */ + public function getRole(): string + { + return $this->role; + } + + /** + * @return \Carbon\Carbon + */ + public function getJoinDate(): Carbon + { + return $this->joinDate; + } +} diff --git a/src/Requests/Companies/MemberRequest.php b/src/Requests/Companies/MemberRequest.php new file mode 100644 index 0000000..5a8a135 --- /dev/null +++ b/src/Requests/Companies/MemberRequest.php @@ -0,0 +1,63 @@ +companyId = $companyId; + $this->memberId = $memberId; + } + + /** + * Get the endpoint of the request. + * + * @return string + */ + public function getEndpoint(): string + { + return 'vtc/' . $this->companyId . '/member/' . $this->memberId; + } + + /** + * Get the data for the request. + * + * @return mixed + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function get(): CompanyMember + { + return new CompanyMember( + $this->send()['response'] + ); + } +} diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index f4bacc3..f750a5c 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -3,6 +3,7 @@ namespace TruckersMP\Requests; use TruckersMP\Models\Company; +use TruckersMP\Requests\Companies\MemberRequest; use TruckersMP\Requests\Companies\NewsRequest; use TruckersMP\Requests\Companies\PostRequest; use TruckersMP\Requests\Companies\RoleRequest; @@ -119,4 +120,20 @@ public function role(int $id): RoleRequest $id ); } + + /** + * Get the requested company member. + * + * @param int $id + * + * @return \TruckersMP\Requests\Companies\MemberRequest + */ + public function member(int $id): MemberRequest + { + return new MemberRequest( + $this->config, + $this->id, + $id + ); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 123ba3c..732f95a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,6 +11,7 @@ use TruckersMP\Collections\ServerCollection; use TruckersMP\Models\Company; use TruckersMP\Models\CompanyIndex; +use TruckersMP\Models\CompanyMember; use TruckersMP\Models\CompanyPost; use TruckersMP\Models\CompanyRole; use TruckersMP\Models\GameTime; @@ -278,17 +279,44 @@ public function companyRoles(int $companyId): RoleCollection */ public function companyRole(int $companyId, int $roleId): CompanyRole { - $cachedRoles = $this->cache->getItem('company_' . $roleId . '_roles_' . $companyId); + $cachedRole = $this->cache->getItem('company_' . $companyId . '_roles_' . $roleId); - if (! $cachedRoles->isHit()) { - $cachedRoles->set( + if (! $cachedRole->isHit()) { + $cachedRole->set( $this->client->company($companyId)->role($roleId)->get() )->expiresAfter(self::CACHE_SECONDS); - $this->cache->save($cachedRoles); + $this->cache->save($cachedRole); } - return $cachedRoles->get(); + return $cachedRole->get(); + } + + /** + * Get or cache the company member. + * + * @param int $companyId + * @param int $memberId + * + * @return \TruckersMP\Models\CompanyMember + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function companyMember(int $companyId, int $memberId): CompanyMember + { + $cachedMember = $this->cache->getItem('company_member_' . $memberId); + + if (! $cachedMember->isHit()) { + $cachedMember->set( + $this->client->company($companyId)->member($memberId)->get() + )->expiresAfter(self::CACHE_SECONDS); + + $this->cache->save($cachedMember); + } + + return $cachedMember->get(); } /** diff --git a/tests/Unit/CompanyMemberTest.php b/tests/Unit/CompanyMemberTest.php new file mode 100644 index 0000000..eb9e914 --- /dev/null +++ b/tests/Unit/CompanyMemberTest.php @@ -0,0 +1,131 @@ +companyMember(self::TEST_COMPANY, self::TEST_MEMBER); + + $this->assertInstanceOf(CompanyMember::class, $member); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testTheMemberHasAnId() + { + $member = $this->companyMember(self::TEST_COMPANY, self::TEST_MEMBER); + + $this->assertNotEmpty($member->getId()); + $this->assertIsInt($member->getId()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testTheMemberHasAUserId() + { + $member = $this->companyMember(self::TEST_COMPANY, self::TEST_MEMBER); + + $this->assertNotEmpty($member->getUserId()); + $this->assertIsInt($member->getUserId()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testTheMemberHasAUsername() + { + $member = $this->companyMember(self::TEST_COMPANY, self::TEST_MEMBER); + + $this->assertNotEmpty($member->getUsername()); + $this->assertIsString($member->getUsername()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testTheMemberHasASteamId() + { + $member = $this->companyMember(self::TEST_COMPANY, self::TEST_MEMBER); + + $this->assertNotEmpty($member->getSteamId()); + $this->assertIsString($member->getSteamId()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testTheMemberHasARoleId() + { + $member = $this->companyMember(self::TEST_COMPANY, self::TEST_MEMBER); + + $this->assertNotEmpty($member->getRoleId()); + $this->assertIsInt($member->getRoleId()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testTheMemberHasARole() + { + $member = $this->companyMember(self::TEST_COMPANY, self::TEST_MEMBER); + + $this->assertNotEmpty($member->getRole()); + $this->assertIsString($member->getRole()); + } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testTheMemberHasAJoinDate() + { + $member = $this->companyMember(self::TEST_COMPANY, self::TEST_MEMBER); + + $this->assertNotEmpty($member->getJoinDate()); + $this->assertInstanceOf(Carbon::class, $member->getJoinDate()); + } +} From 41ce1ee8605aea6ae4ca6d74c1471b64ac92d187 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 26 Nov 2019 16:04:02 +0000 Subject: [PATCH 074/123] Added the ability to get all the members for a company --- src/Collections/MemberCollection.php | 22 +++++++++ src/Models/CompanyMemberIndex.php | 50 +++++++++++++++++++++ src/Requests/Companies/MembersRequest.php | 55 +++++++++++++++++++++++ src/Requests/CompanyRequest.php | 14 ++++++ tests/TestCase.php | 27 +++++++++++ tests/Unit/CompanyMemberTest.php | 19 ++++++++ 6 files changed, 187 insertions(+) create mode 100644 src/Collections/MemberCollection.php create mode 100644 src/Models/CompanyMemberIndex.php create mode 100644 src/Requests/Companies/MembersRequest.php diff --git a/src/Collections/MemberCollection.php b/src/Collections/MemberCollection.php new file mode 100644 index 0000000..ff327ed --- /dev/null +++ b/src/Collections/MemberCollection.php @@ -0,0 +1,22 @@ + $member) { + $this->items[$key] = new CompanyMember($member); + } + } +} diff --git a/src/Models/CompanyMemberIndex.php b/src/Models/CompanyMemberIndex.php new file mode 100644 index 0000000..52e4ea2 --- /dev/null +++ b/src/Models/CompanyMemberIndex.php @@ -0,0 +1,50 @@ +members = new MemberCollection($response['members']); + + $this->count = $response['members_count']; + } + + /** + * @return \TruckersMP\Collections\MemberCollection + */ + public function getMembers(): MemberCollection + { + return $this->members; + } + + /** + * @return int + */ + public function getCount(): int + { + return $this->count; + } +} diff --git a/src/Requests/Companies/MembersRequest.php b/src/Requests/Companies/MembersRequest.php new file mode 100644 index 0000000..96c75ff --- /dev/null +++ b/src/Requests/Companies/MembersRequest.php @@ -0,0 +1,55 @@ +companyId = $id; + } + + /** + * Get the endpoint of the request. + * + * @return string + */ + public function getEndpoint(): string + { + return 'vtc/' . $this->companyId . '/members'; + } + + /** + * Get the data for the request. + * + * @return CompanyMemberIndex + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function get(): CompanyMemberIndex + { + return new CompanyMemberIndex( + $this->send()['response'] + ); + } +} diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index f750a5c..47d57bf 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -4,6 +4,7 @@ use TruckersMP\Models\Company; use TruckersMP\Requests\Companies\MemberRequest; +use TruckersMP\Requests\Companies\MembersRequest; use TruckersMP\Requests\Companies\NewsRequest; use TruckersMP\Requests\Companies\PostRequest; use TruckersMP\Requests\Companies\RoleRequest; @@ -121,6 +122,19 @@ public function role(int $id): RoleRequest ); } + /** + * Get the members for the company. + * + * @return \TruckersMP\Requests\Companies\MembersRequest + */ + public function members(): MembersRequest + { + return new MembersRequest( + $this->config, + $this->id + ); + } + /** * Get the requested company member. * diff --git a/tests/TestCase.php b/tests/TestCase.php index 732f95a..9f15705 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -12,6 +12,7 @@ use TruckersMP\Models\Company; use TruckersMP\Models\CompanyIndex; use TruckersMP\Models\CompanyMember; +use TruckersMP\Models\CompanyMemberIndex; use TruckersMP\Models\CompanyPost; use TruckersMP\Models\CompanyRole; use TruckersMP\Models\GameTime; @@ -292,6 +293,32 @@ public function companyRole(int $companyId, int $roleId): CompanyRole return $cachedRole->get(); } + /** + * Get or cache the company members. + * + * @param int $companyId + * + * @return mixed + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function companyMembers(int $companyId): CompanyMemberIndex + { + $cachedMembers = $this->cache->getItem('company_members_' . $companyId); + + if (! $cachedMembers->isHit()) { + $cachedMembers->set( + $this->client->company($companyId)->members()->get() + ); + + $this->cache->save($cachedMembers); + } + + return $cachedMembers->get(); + } + /** * Get or cache the company member. * diff --git a/tests/Unit/CompanyMemberTest.php b/tests/Unit/CompanyMemberTest.php index eb9e914..7264ad0 100644 --- a/tests/Unit/CompanyMemberTest.php +++ b/tests/Unit/CompanyMemberTest.php @@ -4,7 +4,10 @@ use Carbon\Carbon; use Tests\TestCase; +use TruckersMP\Collections\CompanyCollection; +use TruckersMP\Collections\MemberCollection; use TruckersMP\Models\CompanyMember; +use TruckersMP\Models\CompanyMemberIndex; class CompanyMemberTest extends TestCase { @@ -18,6 +21,22 @@ class CompanyMemberTest extends TestCase */ private const TEST_MEMBER = 1579; + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testWeCanAllTheMembers() + { + $members = $this->companyMembers(self::TEST_COMPANY); + + $this->assertInstanceOf(CompanyMemberIndex::class, $members); + + $this->assertInstanceOf(MemberCollection::class, $members->getMembers()); + $this->assertIsInt($members->getCount()); + } + /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException From 2afb926f082bf96c6b29ff04feeefc515f88ae5e Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Wed, 27 Nov 2019 22:13:59 +0000 Subject: [PATCH 075/123] Removed types folder after pull request --- src/Types/Ban.php | 0 src/Types/Bans.php | 0 src/Types/GameTime.php | 0 src/Types/Player.php | 0 src/Types/Server.php | 0 src/Types/Servers.php | 0 src/Types/Version.php | 0 7 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/Types/Ban.php delete mode 100644 src/Types/Bans.php delete mode 100644 src/Types/GameTime.php delete mode 100644 src/Types/Player.php delete mode 100644 src/Types/Server.php delete mode 100644 src/Types/Servers.php delete mode 100644 src/Types/Version.php diff --git a/src/Types/Ban.php b/src/Types/Ban.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/Types/Bans.php b/src/Types/Bans.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/Types/GameTime.php b/src/Types/GameTime.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/Types/Player.php b/src/Types/Player.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/Types/Server.php b/src/Types/Server.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/Types/Servers.php b/src/Types/Servers.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/Types/Version.php b/src/Types/Version.php deleted file mode 100644 index e69de29..0000000 From 8fa5316d173c1d14911e7905ce25bb76babc3c19 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Wed, 27 Nov 2019 22:20:01 +0000 Subject: [PATCH 076/123] Apply fixes from StyleCI --- src/ApiErrorHandler.php | 7 ++-- src/Client.php | 5 +-- src/Collections/Collection.php | 16 +++++--- src/Collections/ServerCollection.php | 2 +- src/Models/Ban.php | 6 +-- src/Models/Checksum.php | 2 +- src/Models/Company.php | 2 +- src/Models/CompanyMember.php | 2 +- src/Models/CompanyMemberIndex.php | 2 +- src/Models/CompanyRole.php | 2 +- src/Models/Game.php | 4 +- src/Models/Player.php | 4 +- src/Models/Rule.php | 2 +- src/Models/Server.php | 4 +- src/Models/Social.php | 2 +- src/Models/Version.php | 2 +- src/Requests/BanRequest.php | 3 +- src/Requests/Companies/MemberRequest.php | 7 ++-- src/Requests/Companies/MembersRequest.php | 6 +-- src/Requests/Companies/NewsRequest.php | 3 +- src/Requests/Companies/PostRequest.php | 3 +- src/Requests/Companies/RoleRequest.php | 3 +- src/Requests/Companies/RolesRequest.php | 3 +- src/Requests/CompaniesRequest.php | 1 + src/Requests/CompanyRequest.php | 5 ++- src/Requests/GameTimeRequest.php | 2 +- src/Requests/PlayerRequest.php | 3 +- src/Requests/Request.php | 7 ++-- src/Requests/RuleRequest.php | 1 + src/Requests/ServerRequest.php | 2 +- src/Requests/VersionRequest.php | 1 + tests/TestCase.php | 49 ++++++++++++++--------- tests/Unit/BanTest.php | 2 +- tests/Unit/CompanyMemberTest.php | 1 - tests/Unit/CompanyTest.php | 12 +++--- tests/Unit/PlayerTest.php | 2 +- tests/Unit/ServerTest.php | 2 +- 37 files changed, 105 insertions(+), 77 deletions(-) diff --git a/src/ApiErrorHandler.php b/src/ApiErrorHandler.php index 9828d2d..6ced10f 100644 --- a/src/ApiErrorHandler.php +++ b/src/ApiErrorHandler.php @@ -13,9 +13,10 @@ class ApiErrorHandler * Check if the API returned an error. * * @param \Psr\Http\Message\StreamInterface $body - * @param int $statusCode + * @param int $statusCode * * @return \Exception + * * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException */ @@ -23,11 +24,11 @@ public static function check(StreamInterface $body, int $statusCode): ?Exception { $statusCodeType = (int) ($statusCode / 100); - if ($statusCodeType == 2) { + if ($statusCodeType === 2) { return null; } - $body = json_decode((string)$body, true, 512, JSON_BIGINT_AS_STRING); + $body = json_decode((string) $body, true, 512, JSON_BIGINT_AS_STRING); // If it's a page not found error, through a PageNotFoundException if (array_key_exists('descriptor', $body)) { diff --git a/src/Client.php b/src/Client.php index 1bc2f5b..9e202ed 100644 --- a/src/Client.php +++ b/src/Client.php @@ -2,10 +2,8 @@ namespace TruckersMP; -use TruckersMP\Collections\CompanyCollection; use TruckersMP\Requests\BanRequest; use TruckersMP\Requests\CompaniesRequest; -use TruckersMP\Requests\IndexRequest; use TruckersMP\Requests\CompanyRequest; use TruckersMP\Requests\GameTimeRequest; use TruckersMP\Requests\PlayerRequest; @@ -25,7 +23,7 @@ class Client /** * Create a new Client instance. * - * @param array $config + * @param array $config */ public function __construct(array $config = []) { @@ -38,6 +36,7 @@ public function __construct(array $config = []) * https://stats.truckersmp.com/api#players_lookup * * @param int $id + * * @return \TruckersMP\Requests\PlayerRequest */ public function player(int $id): PlayerRequest diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index 30c444b..2b3a5d2 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -33,7 +33,8 @@ public function __construct() /** * Determine if an item exists at an offset. * - * @param mixed $key + * @param mixed $key + * * @return bool */ public function offsetExists($key) @@ -44,7 +45,8 @@ public function offsetExists($key) /** * Get an item at a given offset. * - * @param mixed $key + * @param mixed $key + * * @return mixed */ public function offsetGet($key) @@ -55,8 +57,9 @@ public function offsetGet($key) /** * Set the item at a given offset. * - * @param mixed $key - * @param mixed $value + * @param mixed $key + * @param mixed $value + * * @return void */ public function offsetSet($key, $value) @@ -71,7 +74,8 @@ public function offsetSet($key, $value) /** * Unset the item at a given offset. * - * @param string $key + * @param string $key + * * @return void */ public function offsetUnset($key) @@ -96,7 +100,7 @@ public function current() */ public function next() { - ++$this->position; + $this->position++; } /** diff --git a/src/Collections/ServerCollection.php b/src/Collections/ServerCollection.php index 6d835ad..a68ddae 100644 --- a/src/Collections/ServerCollection.php +++ b/src/Collections/ServerCollection.php @@ -7,7 +7,7 @@ class ServerCollection extends Collection { /** - * Create a new Collection instance + * Create a new Collection instance. * * @param array $response */ diff --git a/src/Models/Ban.php b/src/Models/Ban.php index 8d954fc..83d6184 100644 --- a/src/Models/Ban.php +++ b/src/Models/Ban.php @@ -51,7 +51,7 @@ class Ban /** * Create a new Ban instance. * - * @param array $ban + * @param array $ban * * @throws \Exception */ @@ -69,8 +69,8 @@ public function __construct(array $ban) // Active $this->active = boolval($ban['active']); - if (! is_null($this->expiration) && $this->active) { - if (! $this->expiration->greaterThan(Carbon::now('UTC'))) { + if (!is_null($this->expiration) && $this->active) { + if (!$this->expiration->greaterThan(Carbon::now('UTC'))) { $this->active = false; } } diff --git a/src/Models/Checksum.php b/src/Models/Checksum.php index c71f10e..d4f51af 100644 --- a/src/Models/Checksum.php +++ b/src/Models/Checksum.php @@ -21,7 +21,7 @@ class Checksum /** * Create a new Checksum instance. * - * @param array $checksum + * @param array $checksum */ public function __construct(array $checksum) { diff --git a/src/Models/Company.php b/src/Models/Company.php index ac16d9e..5024e14 100644 --- a/src/Models/Company.php +++ b/src/Models/Company.php @@ -142,7 +142,7 @@ class Company /** * Create a new Company instance. * - * @param array $company + * @param array $company * * @throws \Exception */ diff --git a/src/Models/CompanyMember.php b/src/Models/CompanyMember.php index c42c415..f1d1342 100644 --- a/src/Models/CompanyMember.php +++ b/src/Models/CompanyMember.php @@ -58,7 +58,7 @@ class CompanyMember /** * Create a new CompanyMember instance. * - * @param array $member + * @param array $member */ public function __construct(array $member) { diff --git a/src/Models/CompanyMemberIndex.php b/src/Models/CompanyMemberIndex.php index 52e4ea2..396a12d 100644 --- a/src/Models/CompanyMemberIndex.php +++ b/src/Models/CompanyMemberIndex.php @@ -23,7 +23,7 @@ class CompanyMemberIndex /** * Create a new CompanyMemberIndex instance. * - * @param array $response + * @param array $response */ public function __construct(array $response) { diff --git a/src/Models/CompanyRole.php b/src/Models/CompanyRole.php index e8deae7..b346dc8 100644 --- a/src/Models/CompanyRole.php +++ b/src/Models/CompanyRole.php @@ -51,7 +51,7 @@ class CompanyRole /** * Create a new CompanyRole instance. * - * @param array $role + * @param array $role * * @throws \Exception */ diff --git a/src/Models/Game.php b/src/Models/Game.php index 5c66bb4..c82c8c2 100644 --- a/src/Models/Game.php +++ b/src/Models/Game.php @@ -17,8 +17,8 @@ class Game /** * Create a new Game instance. * - * @param bool $ats - * @param bool $ets + * @param bool $ats + * @param bool $ets */ public function __construct(bool $ats, bool $ets) { diff --git a/src/Models/Player.php b/src/Models/Player.php index d7131d2..383c165 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -28,7 +28,7 @@ class Player protected $avatar; /** - * URL to the small avatar on the website; + * URL to the small avatar on the website;. * * @var string */ @@ -93,7 +93,7 @@ class Player /** * Create a new Player instance. * - * @param array $player + * @param array $player * * @throws \Exception */ diff --git a/src/Models/Rule.php b/src/Models/Rule.php index 0fe44f8..ff25775 100644 --- a/src/Models/Rule.php +++ b/src/Models/Rule.php @@ -21,7 +21,7 @@ class Rule /** * Create a new Role instance. * - * @param array $rules + * @param array $rules */ public function __construct(array $rules) { diff --git a/src/Models/Server.php b/src/Models/Server.php index 3eb150f..30d4d74 100644 --- a/src/Models/Server.php +++ b/src/Models/Server.php @@ -96,7 +96,7 @@ class Server protected $speedLimiter; /** - * If server wide collisions is enabled + * If server wide collisions is enabled. * * @var bool */ @@ -131,7 +131,7 @@ class Server protected $event; /** - * Determine whether the server hosts special event file + * Determine whether the server hosts special event file. * * @var bool */ diff --git a/src/Models/Social.php b/src/Models/Social.php index afd2695..725c1e0 100644 --- a/src/Models/Social.php +++ b/src/Models/Social.php @@ -32,7 +32,7 @@ class Social /** * Create a new Social instance. * - * @param array $social + * @param array $social */ public function __construct(array $social) { diff --git a/src/Models/Version.php b/src/Models/Version.php index 6b62f72..c62fcdc 100644 --- a/src/Models/Version.php +++ b/src/Models/Version.php @@ -65,7 +65,7 @@ class Version /** * Create a new Version instance. * - * @param array $version + * @param array $version * * @throws \Exception */ diff --git a/src/Requests/BanRequest.php b/src/Requests/BanRequest.php index 96d81c6..395df35 100644 --- a/src/Requests/BanRequest.php +++ b/src/Requests/BanRequest.php @@ -17,7 +17,7 @@ class BanRequest extends Request * Create a new BanRequest instance. * * @param array $config - * @param int $id + * @param int $id */ public function __construct(array $config, int $id) { @@ -40,6 +40,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return \TruckersMP\Models\Ban[] + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException diff --git a/src/Requests/Companies/MemberRequest.php b/src/Requests/Companies/MemberRequest.php index 5a8a135..479e197 100644 --- a/src/Requests/Companies/MemberRequest.php +++ b/src/Requests/Companies/MemberRequest.php @@ -24,9 +24,9 @@ class MemberRequest extends Request /** * Create a new MemberRequest instance. * - * @param array $config - * @param int $companyId - * @param int $memberId + * @param array $config + * @param int $companyId + * @param int $memberId */ public function __construct(array $config, int $companyId, int $memberId) { @@ -50,6 +50,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return mixed + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException diff --git a/src/Requests/Companies/MembersRequest.php b/src/Requests/Companies/MembersRequest.php index 96c75ff..724ce41 100644 --- a/src/Requests/Companies/MembersRequest.php +++ b/src/Requests/Companies/MembersRequest.php @@ -2,7 +2,6 @@ namespace TruckersMP\Requests\Companies; -use TruckersMP\Collections\MemberCollection; use TruckersMP\Models\CompanyMemberIndex; use TruckersMP\Requests\Request; @@ -18,8 +17,8 @@ class MembersRequest extends Request /** * Create a new MembersRequest instance. * - * @param array $config - * @param int $id + * @param array $config + * @param int $id */ public function __construct(array $config, int $id) { @@ -42,6 +41,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return CompanyMemberIndex + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException diff --git a/src/Requests/Companies/NewsRequest.php b/src/Requests/Companies/NewsRequest.php index bdb6a37..4cbfa1c 100644 --- a/src/Requests/Companies/NewsRequest.php +++ b/src/Requests/Companies/NewsRequest.php @@ -18,7 +18,7 @@ class NewsRequest extends Request * Create a new NewsRequest instance. * * @param array $config - * @param int $companyId + * @param int $companyId */ public function __construct(array $config, int $companyId) { @@ -41,6 +41,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return PostsCollection|\TruckersMP\Models\CompanyPost[] + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException diff --git a/src/Requests/Companies/PostRequest.php b/src/Requests/Companies/PostRequest.php index a946d11..46f5672 100644 --- a/src/Requests/Companies/PostRequest.php +++ b/src/Requests/Companies/PostRequest.php @@ -25,7 +25,7 @@ class PostRequest extends Request * Create a new PostRequest instance. * * @param array $config - * @param int $companyId + * @param int $companyId * @param $postId */ public function __construct(array $config, int $companyId, $postId) @@ -50,6 +50,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return CompanyPost + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException diff --git a/src/Requests/Companies/RoleRequest.php b/src/Requests/Companies/RoleRequest.php index a491ad1..78930aa 100644 --- a/src/Requests/Companies/RoleRequest.php +++ b/src/Requests/Companies/RoleRequest.php @@ -25,7 +25,7 @@ class RoleRequest extends Request * Create a new RolesRequest instance. * * @param array $config - * @param int $companyId + * @param int $companyId */ public function __construct(array $config, int $companyId, int $roleId) { @@ -49,6 +49,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return CompanyRole + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException diff --git a/src/Requests/Companies/RolesRequest.php b/src/Requests/Companies/RolesRequest.php index 923541f..73e6d66 100644 --- a/src/Requests/Companies/RolesRequest.php +++ b/src/Requests/Companies/RolesRequest.php @@ -18,7 +18,7 @@ class RolesRequest extends Request * Create a new RolesRequest instance. * * @param array $config - * @param int $companyId + * @param int $companyId */ public function __construct(array $config, int $companyId) { @@ -41,6 +41,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return RoleCollection|\TruckersMP\Models\CompanyRole[] + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException diff --git a/src/Requests/CompaniesRequest.php b/src/Requests/CompaniesRequest.php index 3e8cc4c..6dd0e68 100644 --- a/src/Requests/CompaniesRequest.php +++ b/src/Requests/CompaniesRequest.php @@ -20,6 +20,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return mixed + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index 47d57bf..9b6dc73 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -30,7 +30,7 @@ class CompanyRequest extends Request * Create a new CompanyRequest instance. * * @param array $config - * @param int $id + * @param int $id */ public function __construct(array $config, int $id) { @@ -53,6 +53,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return Company + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException @@ -138,7 +139,7 @@ public function members(): MembersRequest /** * Get the requested company member. * - * @param int $id + * @param int $id * * @return \TruckersMP\Requests\Companies\MemberRequest */ diff --git a/src/Requests/GameTimeRequest.php b/src/Requests/GameTimeRequest.php index ebf4089..16d2d60 100644 --- a/src/Requests/GameTimeRequest.php +++ b/src/Requests/GameTimeRequest.php @@ -6,7 +6,6 @@ class GameTimeRequest extends Request { - /** * Get the endpoint of the request. * @@ -21,6 +20,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return GameTime + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException diff --git a/src/Requests/PlayerRequest.php b/src/Requests/PlayerRequest.php index 49c766d..cb0e3c7 100644 --- a/src/Requests/PlayerRequest.php +++ b/src/Requests/PlayerRequest.php @@ -17,7 +17,7 @@ class PlayerRequest extends Request * Create a new PlayerRequest instance. * * @param array $config - * @param int $id + * @param int $id */ public function __construct(array $config, int $id) { @@ -40,6 +40,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return Player + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException diff --git a/src/Requests/Request.php b/src/Requests/Request.php index 182d6c5..b763197 100644 --- a/src/Requests/Request.php +++ b/src/Requests/Request.php @@ -38,7 +38,7 @@ abstract class Request /** * Create a new Request instance. * - * @param array $config + * @param array $config */ public function __construct(array $config) { @@ -67,7 +67,8 @@ abstract public function get(); /** * Send the request to the API endpoint and get the result. * - * @return array + * @return array + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException @@ -83,6 +84,6 @@ public function send(): array ApiErrorHandler::check($exception->getResponse()->getBody(), $exception->getCode()); } - return json_decode((string)$result->getBody(), true, 512, JSON_BIGINT_AS_STRING); + return json_decode((string) $result->getBody(), true, 512, JSON_BIGINT_AS_STRING); } } diff --git a/src/Requests/RuleRequest.php b/src/Requests/RuleRequest.php index b50e0c8..6c0ca2a 100644 --- a/src/Requests/RuleRequest.php +++ b/src/Requests/RuleRequest.php @@ -20,6 +20,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return Rule + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException diff --git a/src/Requests/ServerRequest.php b/src/Requests/ServerRequest.php index d093062..6b40fc8 100644 --- a/src/Requests/ServerRequest.php +++ b/src/Requests/ServerRequest.php @@ -4,7 +4,6 @@ use TruckersMP\Collections\ServerCollection; use TruckersMP\Models\Server; -use function GuzzleHttp\Promise\all; class ServerRequest extends Request { @@ -22,6 +21,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return \TruckersMP\Collections\ServerCollection|Server[] + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException diff --git a/src/Requests/VersionRequest.php b/src/Requests/VersionRequest.php index 44b7eea..9f5da4f 100644 --- a/src/Requests/VersionRequest.php +++ b/src/Requests/VersionRequest.php @@ -20,6 +20,7 @@ public function getEndpoint(): string * Get the data for the request. * * @return Version + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException diff --git a/tests/TestCase.php b/tests/TestCase.php index 9f15705..bd9df53 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -19,7 +19,6 @@ use TruckersMP\Models\Player; use TruckersMP\Models\Rule; use TruckersMP\Models\Version; -use TruckersMP\Requests\CompaniesRequest; class TestCase extends BaseTestCase { @@ -67,6 +66,7 @@ public function __construct() * @param int $id * * @return \TruckersMP\Models\Player + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -76,7 +76,7 @@ public function player(int $id): Player { $cachedPlayer = $this->cache->getItem('player_' . $id); - if (! $cachedPlayer->isHit()) { + if (!$cachedPlayer->isHit()) { $cachedPlayer->set($this->client->player($id)->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedPlayer); } @@ -90,6 +90,7 @@ public function player(int $id): Player * @param int $id * * @return \TruckersMP\Models\Ban[] + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -99,7 +100,7 @@ public function bans(int $id): array { $cachedBans = $this->cache->getItem('bans_' . $id); - if (! $cachedBans->isHit()) { + if (!$cachedBans->isHit()) { $cachedBans->set($this->client->bans($id)->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedBans); } @@ -111,6 +112,7 @@ public function bans(int $id): array * Get or cache the server request. * * @return \TruckersMP\Collections\ServerCollection|\TruckersMP\Models\Server[] + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -120,7 +122,7 @@ public function servers(): ServerCollection { $cachedServers = $this->cache->getItem('servers'); - if (! $cachedServers->isHit()) { + if (!$cachedServers->isHit()) { $cachedServers->set($this->client->servers()->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedServers); } @@ -132,6 +134,7 @@ public function servers(): ServerCollection * Get or cache the game time. * * @return \TruckersMP\Models\GameTime + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -141,7 +144,7 @@ public function gameTime(): GameTime { $cachedGameTime = $this->cache->getItem('game_time'); - if (! $cachedGameTime->isHit()) { + if (!$cachedGameTime->isHit()) { $cachedGameTime->set($this->client->gameTime()->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedGameTime); } @@ -153,6 +156,7 @@ public function gameTime(): GameTime * Get or cache the recent companies. * * @return \TruckersMP\Models\CompanyIndex + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -162,7 +166,7 @@ public function companies(): CompanyIndex { $cachedCompanies = $this->cache->getItem('recent_companies'); - if (! $cachedCompanies->isHit()) { + if (!$cachedCompanies->isHit()) { $cachedCompanies->set($this->client->companies()->get()); $this->cache->save($cachedCompanies); } @@ -176,6 +180,7 @@ public function companies(): CompanyIndex * @param int $id * * @return \TruckersMP\Models\Company + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -185,7 +190,7 @@ public function company(int $id): Company { $cachedCompany = $this->cache->getItem('company_' . $id); - if (! $cachedCompany->isHit()) { + if (!$cachedCompany->isHit()) { $cachedCompany->set($this->client->company($id)->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedCompany); } @@ -199,6 +204,7 @@ public function company(int $id): Company * @param int $id * * @return PostsCollection|\TruckersMP\Models\CompanyPost[] + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -208,7 +214,7 @@ public function companyPosts(int $id): PostsCollection { $cachedNews = $this->cache->getItem('company_posts_' . $id); - if (! $cachedNews->isHit()) { + if (!$cachedNews->isHit()) { $cachedNews->set($this->client->company($id)->posts()->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedNews); } @@ -223,6 +229,7 @@ public function companyPosts(int $id): PostsCollection * @param int $postId * * @return CompanyPost + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -232,7 +239,7 @@ public function companyPost(int $companyId, int $postId): CompanyPost { $cachedPost = $this->cache->getItem('company_' . $companyId . '_post_' . $postId); - if (! $cachedPost->isHit()) { + if (!$cachedPost->isHit()) { $cachedPost->set( $this->client->company($companyId)->post($postId)->get() )->expiresAfter(self::CACHE_SECONDS); @@ -249,6 +256,7 @@ public function companyPost(int $companyId, int $postId): CompanyPost * @param int $companyId * * @return \TruckersMP\Collections\RoleCollection|\TruckersMP\Models\CompanyRole[] + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -258,7 +266,7 @@ public function companyRoles(int $companyId): RoleCollection { $cachedRoles = $this->cache->getItem('company_roles_' . $companyId); - if (! $cachedRoles->isHit()) { + if (!$cachedRoles->isHit()) { $cachedRoles->set($this->client->company($companyId)->roles()->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedRoles); } @@ -273,6 +281,7 @@ public function companyRoles(int $companyId): RoleCollection * @param int $roleId * * @return \TruckersMP\Models\CompanyRole + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -282,7 +291,7 @@ public function companyRole(int $companyId, int $roleId): CompanyRole { $cachedRole = $this->cache->getItem('company_' . $companyId . '_roles_' . $roleId); - if (! $cachedRole->isHit()) { + if (!$cachedRole->isHit()) { $cachedRole->set( $this->client->company($companyId)->role($roleId)->get() )->expiresAfter(self::CACHE_SECONDS); @@ -296,9 +305,10 @@ public function companyRole(int $companyId, int $roleId): CompanyRole /** * Get or cache the company members. * - * @param int $companyId + * @param int $companyId * * @return mixed + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -308,7 +318,7 @@ public function companyMembers(int $companyId): CompanyMemberIndex { $cachedMembers = $this->cache->getItem('company_members_' . $companyId); - if (! $cachedMembers->isHit()) { + if (!$cachedMembers->isHit()) { $cachedMembers->set( $this->client->company($companyId)->members()->get() ); @@ -322,10 +332,11 @@ public function companyMembers(int $companyId): CompanyMemberIndex /** * Get or cache the company member. * - * @param int $companyId - * @param int $memberId + * @param int $companyId + * @param int $memberId * * @return \TruckersMP\Models\CompanyMember + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -335,7 +346,7 @@ public function companyMember(int $companyId, int $memberId): CompanyMember { $cachedMember = $this->cache->getItem('company_member_' . $memberId); - if (! $cachedMember->isHit()) { + if (!$cachedMember->isHit()) { $cachedMember->set( $this->client->company($companyId)->member($memberId)->get() )->expiresAfter(self::CACHE_SECONDS); @@ -350,6 +361,7 @@ public function companyMember(int $companyId, int $memberId): CompanyMember * Get or cache the TruckersMP version. * * @return \TruckersMP\Models\Version + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -359,7 +371,7 @@ public function version(): Version { $cachedVersion = $this->cache->getItem('version'); - if (! $cachedVersion->isHit()) { + if (!$cachedVersion->isHit()) { $cachedVersion->set($this->client->version()->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedVersion); } @@ -371,6 +383,7 @@ public function version(): Version * Get or cache the rules. * * @return \TruckersMP\Models\Rule + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException @@ -380,7 +393,7 @@ public function rules(): Rule { $cachedRules = $this->cache->getItem('rules'); - if (! $cachedRules->isHit()) { + if (!$cachedRules->isHit()) { $cachedRules->set($this->client->rules()->get())->expiresAfter(self::CACHE_SECONDS); $this->cache->save($cachedRules); } diff --git a/tests/Unit/BanTest.php b/tests/Unit/BanTest.php index a12fed5..edb4ac6 100644 --- a/tests/Unit/BanTest.php +++ b/tests/Unit/BanTest.php @@ -43,7 +43,7 @@ public function testItHasAnExpiryDate() if (count($bans) > 0) { $ban = $bans[0]; - if ($ban->getExpirationDate() != null) { + if ($ban->getExpirationDate() !== null) { $this->assertInstanceOf(Carbon::class, $ban->getExpirationDate()); } else { $this->assertNull($ban->getExpirationDate()); diff --git a/tests/Unit/CompanyMemberTest.php b/tests/Unit/CompanyMemberTest.php index 7264ad0..551c0d3 100644 --- a/tests/Unit/CompanyMemberTest.php +++ b/tests/Unit/CompanyMemberTest.php @@ -4,7 +4,6 @@ use Carbon\Carbon; use Tests\TestCase; -use TruckersMP\Collections\CompanyCollection; use TruckersMP\Collections\MemberCollection; use TruckersMP\Models\CompanyMember; use TruckersMP\Models\CompanyMemberIndex; diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index 2507d0c..d80bc15 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -5,8 +5,8 @@ use Carbon\Carbon; use Tests\TestCase; use TruckersMP\Collections\CompanyCollection; -use TruckersMP\Models\CompanyIndex; use TruckersMP\Models\Company; +use TruckersMP\Models\CompanyIndex; use TruckersMP\Models\Game; use TruckersMP\Models\Social; @@ -257,35 +257,35 @@ public function testItHasSocialInformation() $this->assertInstanceOf(Social::class, $company->getSocial()); // Twitter - if ($company->getSocial()->getTwitter() != null) { + if ($company->getSocial()->getTwitter() !== null) { $this->assertIsString($company->getSocial()->getTwitter()); } else { $this->assertNull($company->getSocial()->getTwitter()); } // Facebook - if ($company->getSocial()->getFacebook() != null) { + if ($company->getSocial()->getFacebook() !== null) { $this->assertIsString($company->getSocial()->getFacebook()); } else { $this->assertNull($company->getSocial()->getFacebook()); } // PlaysTV - if ($company->getSocial()->getPlays() != null) { + if ($company->getSocial()->getPlays() !== null) { $this->assertIsString($company->getSocial()->getPlays()); } else { $this->assertNull($company->getSocial()->getPlays()); } // Discord - if ($company->getSocial()->getDiscord() != null) { + if ($company->getSocial()->getDiscord() !== null) { $this->assertIsString($company->getSocial()->getDiscord()); } else { $this->assertNull($company->getSocial()->getDiscord()); } // YouTube - if ($company->getSocial()->getYouTube() != null) { + if ($company->getSocial()->getYouTube() !== null) { $this->assertIsString($company->getSocial()->getYouTube()); } else { $this->assertNull($company->getSocial()->getYouTube()); diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index a3f0538..d4073f1 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -64,7 +64,7 @@ public function testItHasAnAvatar() $this->assertIsString($player->getAvatar()); - if ($player->getSmallAvatar() != null) { + if ($player->getSmallAvatar() !== null) { $this->assertIsString($player->getSmallAvatar()); } } diff --git a/tests/Unit/ServerTest.php b/tests/Unit/ServerTest.php index 9ab14d6..c28f699 100644 --- a/tests/Unit/ServerTest.php +++ b/tests/Unit/ServerTest.php @@ -113,7 +113,7 @@ public function testItHasAnIdPrefix() { $server = $this->servers()[0]; - if ($server->getIdPrefix() != null) { + if ($server->getIdPrefix() !== null) { $this->assertIsString($server->getIdPrefix()); } else { $this->assertNull($server->getIdPrefix()); From 4e983df53765d3abccc18c5f534884e71b2e4333 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Wed, 27 Nov 2019 22:28:05 +0000 Subject: [PATCH 077/123] Removed old API client and request file --- Tests/ClientTest.php | 0 src/API/APIClient.php | 0 src/API/Request.php | 0 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Tests/ClientTest.php delete mode 100644 src/API/APIClient.php delete mode 100644 src/API/Request.php diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/API/APIClient.php b/src/API/APIClient.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/API/Request.php b/src/API/Request.php deleted file mode 100644 index e69de29..0000000 From a0c0befc1e97c0bbc304d213267ebba193e5ee7e Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Wed, 27 Nov 2019 22:31:57 +0000 Subject: [PATCH 078/123] Updated required PHP version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 80586ec..818176c 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ } ], "require": { - "php": ">=7.2.9", + "php": "^7.2", "nesbot/carbon": "^2.16", "ext-json": "*", "phpfastcache/phpfastcache": "^7.1", From 0d3967f16e30ad6b6bfbce8779818d08ccdb343d Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 15:38:21 +0000 Subject: [PATCH 079/123] Simplified the README file --- readme.md | 167 ++++++------------------------------------------------ 1 file changed, 18 insertions(+), 149 deletions(-) diff --git a/readme.md b/readme.md index eaa2045..9a1862e 100644 --- a/readme.md +++ b/readme.md @@ -1,159 +1,28 @@ -# TruckersMP REST API Library +

-[![Build Status](https://travis-ci.org/TruckersMP/API-Client.svg?branch=master)](https://travis-ci.org/TruckersMP/API-Client) -[![StyleCI Status](https://github.styleci.io/repos/57324164/shield?branch=master)](https://github.styleci.io/repos/57324164) -[![Latest Stable Version](https://poser.pugx.org/truckersmp/api-client/v/stable)](https://packagist.org/packages/truckersmp/api-client) -[![Latest Unstable Version](https://poser.pugx.org/truckersmp/api-client/v/unstable)](https://packagist.org/packages/truckersmp/api-client) -[![License](https://poser.pugx.org/truckersmp/api-client/license)](https://packagist.org/packages/truckersmp/api-client) -[![Monthly Downloads](https://poser.pugx.org/truckersmp/api-client/d/monthly)](https://packagist.org/packages/truckersmp/api-client) -[![Total Downloads](https://poser.pugx.org/truckersmp/api-client/downloads)](https://packagist.org/packages/truckersmp/api-client) +

+Build Status +StyleCI Status +Total Downloads +Latest Stable Version +License +

+## Introduction -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. +The TruckersMP PHP library provides convenient access to the TruckersMP API for applications written in the PHP +language. It includes a pre-defined set of classes for API each endpoint to get the data as a collection or model. -> 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). +If you want to use the API without the library, check out the [API Documentation](https://stats.truckersmp.com/api). -## Warning! +## Official Documentation -Please use our service responsibly. People who make lots of requests to our API should contact TruckersMP Staff with a rationale and contact email. +Documentation for API client can be found on the [Wiki](https://github.com/TruckersMP/API-Client/wiki). +## Support -## Requirements +If you have any questions about the library, you can create a topic on our [forum](https://forum.truckersmp.com/index.php?/forum/198-developer-portal/). -- PHP 7.2.0 or newer -- Composer +## License -## Installation - -This library can be installed using [Composer](http://getcomposer.org/). - -Two ways: -1. Execute command `composer require truckersmp/api-client` -2. Add `truckersmp/api-client` manually to the composer requirements list. - -After doing either of the above, execute the command `composer install`. - -## Usage - -> **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); - -// Get player data for player with SteamID 76561197965863564 -$player = $client->player(76561197965863564); - -// output the user's name -echo $player->getName(); - -// output the user's group -echo $player->getGroupName(); - -``` - -## Methods - -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 -- `getExpirationDate(): ?Carbon` -- `getCreatedDate(): 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` -- `isBanned(): bool` -- `getBannedUntil(): bool` -- `hasBansHidden(): bool` -- `getGroupName(): string` -- `isAdmin(): bool` - -### RulesModel Methods -- `getRules(): string` -- `getRevision(): int` - -### ServerModel Methods -- `getId(): int` -- `getGame(): string` -- `getIp(): string` -- `getPort(): int` -- `getName(): string` -- `getShortName(): string` -- `getIdPrefix(): string` -- `isOnline(): bool` -- `getPlayers(): int` -- `getQueue(): int` -- `getMaxPlayers(): int` -- `getDisplayOrder(): int` -- `hasSpeedLimit(): bool` -- `hasCollisions(): bool` -- `canPlayersHaveCars(): bool` -- `canPlayersHavePoliceCars(): bool` -- `isAfkEnabled(): bool` -- `isEvent(): bool` -- `isSpecialEvent(): bool` -- `isPromods(): 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) 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 - Date: Fri, 29 Nov 2019 16:11:49 +0000 Subject: [PATCH 080/123] Added requirements and how to install to README --- readme.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/readme.md b/readme.md index 9a1862e..80ed5ca 100644 --- a/readme.md +++ b/readme.md @@ -5,6 +5,7 @@ StyleCI Status Total Downloads Latest Stable Version +Latest Unstable Version License

@@ -15,6 +16,24 @@ language. It includes a pre-defined set of classes for API each endpoint to get If you want to use the API without the library, check out the [API Documentation](https://stats.truckersmp.com/api). +## Requirements + +PHP 7.2 or later + +## Composer + +You can install the package via [Composer](https://getcomposer.org). Run the following command: + +```bash +composer require truckersmp/api-client +``` + +To use the package, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading): + +```php +require_once('vendor/autoload.php'); +``` + ## Official Documentation Documentation for API client can be found on the [Wiki](https://github.com/TruckersMP/API-Client/wiki). From a4f84a8598f808312fa17820b1eb26dc33cc1e40 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 16:15:19 +0000 Subject: [PATCH 081/123] Added composer to the list of requirements --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 80ed5ca..f5a341a 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,8 @@ If you want to use the API without the library, check out the [API Documentation ## Requirements -PHP 7.2 or later +- PHP 7.2 or later +- Composer ## Composer From b599b8f94901964356f0a184b286b7125175ebca Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 16:17:27 +0000 Subject: [PATCH 082/123] Added PHP 7.4 to travis config --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index d957e0c..8905453 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ cache: php: - 7.2 - 7.3 + - 7.4 before_install: - composer self-update From 6d010c6a9c40573e24d8a327d5783bfe76d9b4ec Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 16:27:18 +0000 Subject: [PATCH 083/123] Removed PHP 7.4 from TravisCI config --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8905453..d957e0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ cache: php: - 7.2 - 7.3 - - 7.4 before_install: - composer self-update From 5212a16ba72aa58f18f006be53ce97b272490aed Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 17:31:21 +0000 Subject: [PATCH 084/123] Removed the examples from the codebase --- examples/cache/Laravel.php | 33 ------------------------------ examples/cache/phpFastCache.php | 36 --------------------------------- 2 files changed, 69 deletions(-) delete mode 100644 examples/cache/Laravel.php delete mode 100644 examples/cache/phpFastCache.php diff --git a/examples/cache/Laravel.php b/examples/cache/Laravel.php deleted file mode 100644 index 3c0f289..0000000 --- a/examples/cache/Laravel.php +++ /dev/null @@ -1,33 +0,0 @@ -input('needle'); - - /** - * Caching search for that needle for 10 minutes - */ - $tmp = Cache::remember('users.player.' . (string)$needle, 10, function () use ($needle, $client) { - return $client->player($needle); - }); - - return view('search', compact($tmp)); - } -} diff --git a/examples/cache/phpFastCache.php b/examples/cache/phpFastCache.php deleted file mode 100644 index a84ae75..0000000 --- a/examples/cache/phpFastCache.php +++ /dev/null @@ -1,36 +0,0 @@ - '/path/to/your/cache/folder', -]); - -// In your class, function, you can call the Cache -$InstanceCache = CacheManager::getInstance('files'); - -$client = new Client(); - -/** - * Try to get $products from Caching First - * product_page is "identity keyword"; - */ -$key = "player_" . $player_id; -$CachedRequest = $InstanceCache->getItem($key); - -if (is_null($CachedRequest->get())) { - $request = $client->player($player_id); - - $CachedRequest->set($request)->expiresAfter(5);//in seconds, also accepts Datetime - $InstanceCache->save($CachedRequest); // Save the cache item just like you do with doctrine and entities -} - -var_dump($CachedRequest->get()); From ccbb674ed7699249ff11fbb51f3bba00fbcbf065 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 20:40:43 +0000 Subject: [PATCH 085/123] We now return the bans as a collection --- src/Collections/BanCollection.php | 25 +++++++++++++++++++++++++ src/Collections/CompanyCollection.php | 4 +++- src/Requests/BanRequest.php | 19 +++++++------------ tests/TestCase.php | 3 ++- tests/Unit/BanTest.php | 3 ++- 5 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 src/Collections/BanCollection.php diff --git a/src/Collections/BanCollection.php b/src/Collections/BanCollection.php new file mode 100644 index 0000000..d031fcc --- /dev/null +++ b/src/Collections/BanCollection.php @@ -0,0 +1,25 @@ + $ban) { + $this->items[$key] = new Ban($ban); + } + } +} diff --git a/src/Collections/CompanyCollection.php b/src/Collections/CompanyCollection.php index 2dada44..5c24f5f 100644 --- a/src/Collections/CompanyCollection.php +++ b/src/Collections/CompanyCollection.php @@ -9,7 +9,9 @@ class CompanyCollection extends Collection /** * Create a new Collection instance. * - * @param array $companies + * @param array $companies + * + * @throws \Exception */ public function __construct(array $companies) { diff --git a/src/Requests/BanRequest.php b/src/Requests/BanRequest.php index 395df35..10c4226 100644 --- a/src/Requests/BanRequest.php +++ b/src/Requests/BanRequest.php @@ -2,6 +2,7 @@ namespace TruckersMP\Requests; +use TruckersMP\Collections\BanCollection; use TruckersMP\Models\Ban; class BanRequest extends Request @@ -39,23 +40,17 @@ public function getEndpoint(): string /** * Get the data for the request. * - * @return \TruckersMP\Models\Ban[] + * @return \TruckersMP\Collections\BanCollection * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException + * @throws \Exception */ - public function get(): array + public function get(): BanCollection { - $bans = []; - $results = $this->send(); - - // TODO: handle any errors / exceptions - - foreach ($results['response'] as $key => $ban) { - $bans[$key] = new Ban($ban); - } - - return $bans; + return new BanCollection( + $this->send()['response'] + ); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index bd9df53..2f001e2 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,6 +6,7 @@ use Phpfastcache\Config\ConfigurationOption; use PHPUnit\Framework\TestCase as BaseTestCase; use TruckersMP\Client; +use TruckersMP\Collections\BanCollection; use TruckersMP\Collections\PostsCollection; use TruckersMP\Collections\RoleCollection; use TruckersMP\Collections\ServerCollection; @@ -96,7 +97,7 @@ public function player(int $id): Player * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException */ - public function bans(int $id): array + public function bans(int $id): BanCollection { $cachedBans = $this->cache->getItem('bans_' . $id); diff --git a/tests/Unit/BanTest.php b/tests/Unit/BanTest.php index edb4ac6..3e1ed2f 100644 --- a/tests/Unit/BanTest.php +++ b/tests/Unit/BanTest.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use Tests\TestCase; +use TruckersMP\Collections\BanCollection; use TruckersMP\Models\Ban; class BanTest extends TestCase @@ -23,7 +24,7 @@ public function testWeCanGetAllBans() { $bans = $this->bans(self::TEST_ACCOUNT); - $this->assertIsArray($bans); + $this->assertInstanceOf(BanCollection::class, $bans); if (count($bans) > 0) { $this->assertInstanceOf(Ban::class, $bans[0]); From 1567caf54ef2418efb0b1ed39b200bfa046f6ba3 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 20:57:09 +0000 Subject: [PATCH 086/123] Added the ability to get the players VTC information --- src/Models/Player.php | 80 +++++++++++++++++++++++++++++++++++++++ tests/Unit/PlayerTest.php | 35 +++++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/src/Models/Player.php b/src/Models/Player.php index 383c165..022fe6f 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -90,6 +90,41 @@ class Player */ protected $inGameAdmin; + /** + * The players company ID. + * + * @var int + */ + protected $companyId; + + /** + * The players company name. + * + * @var string + */ + protected $companyName; + + /** + * The players company tag. + * + * @var string + */ + protected $companyTag; + + /** + * If the player is in a company. + * + * @var bool + */ + protected $isInCompany; + + /** + * The players company member id. + * + * @var int + */ + protected $companyMemberId; + /** * Create a new Player instance. * @@ -111,6 +146,11 @@ public function __construct(array $player) $this->bannedUntil = new Carbon($player['bannedUntil'], 'UTC'); $this->displayBans = $player['displayBans']; $this->inGameAdmin = $player['permissions']['isGameAdmin']; + $this->companyId = $player['vtc']['id']; + $this->companyName = $player['vtc']['name']; + $this->companyTag = $player['vtc']['tag']; + $this->isInCompany = $player['vtc']['inVTC']; + $this->companyMemberId = $player['vtc']['memberID']; } /** @@ -208,4 +248,44 @@ public function isAdmin(): bool { return $this->inGameAdmin; } + + /** + * @return int + */ + public function getCompanyId(): int + { + return $this->companyId; + } + + /** + * @return string + */ + public function getCompanyName(): string + { + return $this->companyName; + } + + /** + * @return string + */ + public function getCompanyTag(): string + { + return $this->companyTag; + } + + /** + * @return bool + */ + public function isInCompany(): bool + { + return $this->isInCompany; + } + + /** + * @return int + */ + public function getCompanyMemberId(): int + { + return $this->companyMemberId; + } } diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index d4073f1..498ad85 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -172,4 +172,39 @@ public function testItHasIfAdmin() $this->assertIsBool($player->isAdmin()); } + + public function testItHasACompanyId() + { + $player = $this->player(self::TEST_ACCOUNT); + + $this->assertIsInt($player->getCompanyId()); + } + + public function testItHasACompanyName() + { + $player = $this->player(self::TEST_ACCOUNT); + + $this->assertIsString($player->getCompanyName()); + } + + public function testItHasACompanyTag() + { + $player = $this->player(self::TEST_ACCOUNT); + + $this->assertIsString($player->getCompanyTag()); + } + + public function testIfInACompany() + { + $player = $this->player(self::TEST_ACCOUNT); + + $this->assertIsBool($player->isInCompany()); + } + + public function testItHasAMemberId() + { + $player = $this->player(self::TEST_ACCOUNT); + + $this->assertIsInt($player->getCompanyMemberId()); + } } From cd135c3c774b16574c2a8ee01740d9f9bc6ec563 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 21:07:32 +0000 Subject: [PATCH 087/123] Updated comments in PlayerTest --- tests/Unit/PlayerTest.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index 498ad85..d89135c 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use Tests\TestCase; +use TruckersMP\Models\Company; use TruckersMP\Models\Player; class PlayerTest extends TestCase @@ -11,7 +12,7 @@ class PlayerTest extends TestCase /** * The ID of the player to use in the tests. */ - private const TEST_ACCOUNT = 28159; + private const TEST_ACCOUNT = 6818; /** * @throws \Http\Client\Exception @@ -173,6 +174,12 @@ public function testItHasIfAdmin() $this->assertIsBool($player->isAdmin()); } + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ public function testItHasACompanyId() { $player = $this->player(self::TEST_ACCOUNT); @@ -180,6 +187,12 @@ public function testItHasACompanyId() $this->assertIsInt($player->getCompanyId()); } + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ public function testItHasACompanyName() { $player = $this->player(self::TEST_ACCOUNT); @@ -187,6 +200,12 @@ public function testItHasACompanyName() $this->assertIsString($player->getCompanyName()); } + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ public function testItHasACompanyTag() { $player = $this->player(self::TEST_ACCOUNT); @@ -201,6 +220,12 @@ public function testIfInACompany() $this->assertIsBool($player->isInCompany()); } + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ public function testItHasAMemberId() { $player = $this->player(self::TEST_ACCOUNT); From 5da8ff9757192c84e6f252c577eb3689418c5a19 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 21:22:58 +0000 Subject: [PATCH 088/123] Changed the way we get the guzzle config --- src/Client.php | 30 +++++++++++++++-------- src/Requests/BanRequest.php | 7 +++--- src/Requests/Companies/MemberRequest.php | 9 +++---- src/Requests/Companies/MembersRequest.php | 7 +++--- src/Requests/Companies/NewsRequest.php | 7 +++--- src/Requests/Companies/PostRequest.php | 7 +++--- src/Requests/Companies/RoleRequest.php | 8 +++--- src/Requests/Companies/RolesRequest.php | 7 +++--- src/Requests/CompanyRequest.php | 13 +++------- src/Requests/PlayerRequest.php | 7 +++--- src/Requests/Request.php | 7 +++--- src/Requests/VersionRequest.php | 1 + 12 files changed, 53 insertions(+), 57 deletions(-) diff --git a/src/Client.php b/src/Client.php index 9e202ed..894b007 100644 --- a/src/Client.php +++ b/src/Client.php @@ -18,7 +18,7 @@ class Client * * @var array */ - protected $config = []; + protected static $config = []; /** * Create a new Client instance. @@ -27,7 +27,7 @@ class Client */ public function __construct(array $config = []) { - $this->config = $config; + self::$config = $config; } /** @@ -41,7 +41,7 @@ public function __construct(array $config = []) */ public function player(int $id): PlayerRequest { - return new PlayerRequest($this->config, $id); + return new PlayerRequest($id); } /** @@ -55,7 +55,7 @@ public function player(int $id): PlayerRequest */ public function bans(int $id): BanRequest { - return new BanRequest($this->config, $id); + return new BanRequest($id); } /** @@ -67,7 +67,7 @@ public function bans(int $id): BanRequest */ public function servers(): ServerRequest { - return new ServerRequest($this->config); + return new ServerRequest(); } /** @@ -79,7 +79,7 @@ public function servers(): ServerRequest */ public function gameTime(): GameTimeRequest { - return new GameTimeRequest($this->config); + return new GameTimeRequest(); } /** @@ -91,7 +91,7 @@ public function gameTime(): GameTimeRequest */ public function companies(): CompaniesRequest { - return new CompaniesRequest($this->config); + return new CompaniesRequest(); } /** @@ -105,7 +105,7 @@ public function companies(): CompaniesRequest */ public function company(int $id): CompanyRequest { - return new CompanyRequest($this->config, $id); + return new CompanyRequest($id); } /** @@ -117,7 +117,7 @@ public function company(int $id): CompanyRequest */ public function version(): VersionRequest { - return new VersionRequest($this->config); + return new VersionRequest(); } /** @@ -129,6 +129,16 @@ public function version(): VersionRequest */ public function rules(): RuleRequest { - return new RuleRequest($this->config); + return new RuleRequest(); + } + + /** + * Get the configuration to use for Guzzle. + * + * @return array + */ + public static function config() + { + return self::$config; } } diff --git a/src/Requests/BanRequest.php b/src/Requests/BanRequest.php index 10c4226..e2a7384 100644 --- a/src/Requests/BanRequest.php +++ b/src/Requests/BanRequest.php @@ -17,12 +17,11 @@ class BanRequest extends Request /** * Create a new BanRequest instance. * - * @param array $config - * @param int $id + * @param int $id */ - public function __construct(array $config, int $id) + public function __construct(int $id) { - parent::__construct($config); + parent::__construct(); $this->id = $id; } diff --git a/src/Requests/Companies/MemberRequest.php b/src/Requests/Companies/MemberRequest.php index 479e197..ddcda75 100644 --- a/src/Requests/Companies/MemberRequest.php +++ b/src/Requests/Companies/MemberRequest.php @@ -24,13 +24,12 @@ class MemberRequest extends Request /** * Create a new MemberRequest instance. * - * @param array $config - * @param int $companyId - * @param int $memberId + * @param int $companyId + * @param int $memberId */ - public function __construct(array $config, int $companyId, int $memberId) + public function __construct(int $companyId, int $memberId) { - parent::__construct($config); + parent::__construct(); $this->companyId = $companyId; $this->memberId = $memberId; diff --git a/src/Requests/Companies/MembersRequest.php b/src/Requests/Companies/MembersRequest.php index 724ce41..7b2c8d1 100644 --- a/src/Requests/Companies/MembersRequest.php +++ b/src/Requests/Companies/MembersRequest.php @@ -17,12 +17,11 @@ class MembersRequest extends Request /** * Create a new MembersRequest instance. * - * @param array $config - * @param int $id + * @param int $id */ - public function __construct(array $config, int $id) + public function __construct(int $id) { - parent::__construct($config); + parent::__construct(); $this->companyId = $id; } diff --git a/src/Requests/Companies/NewsRequest.php b/src/Requests/Companies/NewsRequest.php index 4cbfa1c..274ee81 100644 --- a/src/Requests/Companies/NewsRequest.php +++ b/src/Requests/Companies/NewsRequest.php @@ -17,12 +17,11 @@ class NewsRequest extends Request /** * Create a new NewsRequest instance. * - * @param array $config - * @param int $companyId + * @param int $companyId */ - public function __construct(array $config, int $companyId) + public function __construct(int $companyId) { - parent::__construct($config); + parent::__construct(); $this->companyId = $companyId; } diff --git a/src/Requests/Companies/PostRequest.php b/src/Requests/Companies/PostRequest.php index 46f5672..d6131cb 100644 --- a/src/Requests/Companies/PostRequest.php +++ b/src/Requests/Companies/PostRequest.php @@ -24,13 +24,12 @@ class PostRequest extends Request /** * Create a new PostRequest instance. * - * @param array $config - * @param int $companyId + * @param int $companyId * @param $postId */ - public function __construct(array $config, int $companyId, $postId) + public function __construct(int $companyId, $postId) { - parent::__construct($config); + parent::__construct(); $this->companyId = $companyId; $this->postId = $postId; diff --git a/src/Requests/Companies/RoleRequest.php b/src/Requests/Companies/RoleRequest.php index 78930aa..21d03a4 100644 --- a/src/Requests/Companies/RoleRequest.php +++ b/src/Requests/Companies/RoleRequest.php @@ -24,12 +24,12 @@ class RoleRequest extends Request /** * Create a new RolesRequest instance. * - * @param array $config - * @param int $companyId + * @param int $companyId + * @param int $roleId */ - public function __construct(array $config, int $companyId, int $roleId) + public function __construct(int $companyId, int $roleId) { - parent::__construct($config); + parent::__construct(); $this->companyId = $companyId; $this->roleId = $roleId; diff --git a/src/Requests/Companies/RolesRequest.php b/src/Requests/Companies/RolesRequest.php index 73e6d66..f2c9aff 100644 --- a/src/Requests/Companies/RolesRequest.php +++ b/src/Requests/Companies/RolesRequest.php @@ -17,12 +17,11 @@ class RolesRequest extends Request /** * Create a new RolesRequest instance. * - * @param array $config - * @param int $companyId + * @param int $companyId */ - public function __construct(array $config, int $companyId) + public function __construct(int $companyId) { - parent::__construct($config); + parent::__construct(); $this->companyId = $companyId; } diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index 9b6dc73..5b53ec6 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -29,12 +29,11 @@ class CompanyRequest extends Request /** * Create a new CompanyRequest instance. * - * @param array $config - * @param int $id + * @param int $id */ - public function __construct(array $config, int $id) + public function __construct(int $id) { - parent::__construct($config); + parent::__construct(); $this->id = $id; } @@ -73,7 +72,6 @@ public function get(): Company public function posts(): NewsRequest { return new NewsRequest( - $this->config, $this->id ); } @@ -88,7 +86,6 @@ public function posts(): NewsRequest public function post(int $id): PostRequest { return new PostRequest( - $this->config, $this->id, $id ); @@ -102,7 +99,6 @@ public function post(int $id): PostRequest public function roles(): RolesRequest { return new RolesRequest( - $this->config, $this->id ); } @@ -117,7 +113,6 @@ public function roles(): RolesRequest public function role(int $id): RoleRequest { return new RoleRequest( - $this->config, $this->id, $id ); @@ -131,7 +126,6 @@ public function role(int $id): RoleRequest public function members(): MembersRequest { return new MembersRequest( - $this->config, $this->id ); } @@ -146,7 +140,6 @@ public function members(): MembersRequest public function member(int $id): MemberRequest { return new MemberRequest( - $this->config, $this->id, $id ); diff --git a/src/Requests/PlayerRequest.php b/src/Requests/PlayerRequest.php index cb0e3c7..0c25181 100644 --- a/src/Requests/PlayerRequest.php +++ b/src/Requests/PlayerRequest.php @@ -16,12 +16,11 @@ class PlayerRequest extends Request /** * Create a new PlayerRequest instance. * - * @param array $config - * @param int $id + * @param int $id */ - public function __construct(array $config, int $id) + public function __construct(int $id) { - parent::__construct($config); + parent::__construct(); $this->id = $id; } diff --git a/src/Requests/Request.php b/src/Requests/Request.php index b763197..9d13a90 100644 --- a/src/Requests/Request.php +++ b/src/Requests/Request.php @@ -7,6 +7,7 @@ use Http\Client\Exception\HttpException; use Http\Message\MessageFactory\GuzzleMessageFactory; use TruckersMP\ApiErrorHandler; +use TruckersMP\Client; abstract class Request { @@ -37,14 +38,12 @@ abstract class Request /** * Create a new Request instance. - * - * @param array $config */ - public function __construct(array $config) + public function __construct() { $this->message = new GuzzleMessageFactory(); $this->adapter = new GuzzleAdapter( - new GuzzleClient($config) + new GuzzleClient(Client::config()) ); $this->url = 'https://' . self::API_ENDPOINT . '/' . self::API_VERSION . '/'; diff --git a/src/Requests/VersionRequest.php b/src/Requests/VersionRequest.php index 9f5da4f..9784744 100644 --- a/src/Requests/VersionRequest.php +++ b/src/Requests/VersionRequest.php @@ -24,6 +24,7 @@ public function getEndpoint(): string * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException + * @throws \Exception */ public function get(): Version { From 04467023a99fff80035f7c7eef07aa2a829797d9 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 21:26:06 +0000 Subject: [PATCH 089/123] Apply fixes from StyleCI --- src/Collections/BanCollection.php | 3 ++- src/Collections/CompanyCollection.php | 2 +- src/Requests/BanRequest.php | 3 +-- src/Requests/Companies/MemberRequest.php | 4 ++-- src/Requests/Companies/MembersRequest.php | 2 +- src/Requests/Companies/NewsRequest.php | 2 +- src/Requests/Companies/PostRequest.php | 2 +- src/Requests/Companies/RoleRequest.php | 4 ++-- src/Requests/Companies/RolesRequest.php | 2 +- src/Requests/CompanyRequest.php | 2 +- src/Requests/PlayerRequest.php | 2 +- tests/Unit/PlayerTest.php | 1 - 12 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Collections/BanCollection.php b/src/Collections/BanCollection.php index d031fcc..bf7c8d3 100644 --- a/src/Collections/BanCollection.php +++ b/src/Collections/BanCollection.php @@ -9,9 +9,10 @@ class BanCollection extends Collection /** * Create a new BanCollection instance. * - * @param array $bans + * @param array $bans * * @return void + * * @throws \Exception */ public function __construct(array $bans) diff --git a/src/Collections/CompanyCollection.php b/src/Collections/CompanyCollection.php index 5c24f5f..9d709d2 100644 --- a/src/Collections/CompanyCollection.php +++ b/src/Collections/CompanyCollection.php @@ -9,7 +9,7 @@ class CompanyCollection extends Collection /** * Create a new Collection instance. * - * @param array $companies + * @param array $companies * * @throws \Exception */ diff --git a/src/Requests/BanRequest.php b/src/Requests/BanRequest.php index e2a7384..fcd1b1b 100644 --- a/src/Requests/BanRequest.php +++ b/src/Requests/BanRequest.php @@ -3,7 +3,6 @@ namespace TruckersMP\Requests; use TruckersMP\Collections\BanCollection; -use TruckersMP\Models\Ban; class BanRequest extends Request { @@ -17,7 +16,7 @@ class BanRequest extends Request /** * Create a new BanRequest instance. * - * @param int $id + * @param int $id */ public function __construct(int $id) { diff --git a/src/Requests/Companies/MemberRequest.php b/src/Requests/Companies/MemberRequest.php index ddcda75..4d38ee9 100644 --- a/src/Requests/Companies/MemberRequest.php +++ b/src/Requests/Companies/MemberRequest.php @@ -24,8 +24,8 @@ class MemberRequest extends Request /** * Create a new MemberRequest instance. * - * @param int $companyId - * @param int $memberId + * @param int $companyId + * @param int $memberId */ public function __construct(int $companyId, int $memberId) { diff --git a/src/Requests/Companies/MembersRequest.php b/src/Requests/Companies/MembersRequest.php index 7b2c8d1..05e2c8f 100644 --- a/src/Requests/Companies/MembersRequest.php +++ b/src/Requests/Companies/MembersRequest.php @@ -17,7 +17,7 @@ class MembersRequest extends Request /** * Create a new MembersRequest instance. * - * @param int $id + * @param int $id */ public function __construct(int $id) { diff --git a/src/Requests/Companies/NewsRequest.php b/src/Requests/Companies/NewsRequest.php index 274ee81..3014dad 100644 --- a/src/Requests/Companies/NewsRequest.php +++ b/src/Requests/Companies/NewsRequest.php @@ -17,7 +17,7 @@ class NewsRequest extends Request /** * Create a new NewsRequest instance. * - * @param int $companyId + * @param int $companyId */ public function __construct(int $companyId) { diff --git a/src/Requests/Companies/PostRequest.php b/src/Requests/Companies/PostRequest.php index d6131cb..e1c9cd9 100644 --- a/src/Requests/Companies/PostRequest.php +++ b/src/Requests/Companies/PostRequest.php @@ -24,7 +24,7 @@ class PostRequest extends Request /** * Create a new PostRequest instance. * - * @param int $companyId + * @param int $companyId * @param $postId */ public function __construct(int $companyId, $postId) diff --git a/src/Requests/Companies/RoleRequest.php b/src/Requests/Companies/RoleRequest.php index 21d03a4..58e01d8 100644 --- a/src/Requests/Companies/RoleRequest.php +++ b/src/Requests/Companies/RoleRequest.php @@ -24,8 +24,8 @@ class RoleRequest extends Request /** * Create a new RolesRequest instance. * - * @param int $companyId - * @param int $roleId + * @param int $companyId + * @param int $roleId */ public function __construct(int $companyId, int $roleId) { diff --git a/src/Requests/Companies/RolesRequest.php b/src/Requests/Companies/RolesRequest.php index f2c9aff..e6aa2d5 100644 --- a/src/Requests/Companies/RolesRequest.php +++ b/src/Requests/Companies/RolesRequest.php @@ -17,7 +17,7 @@ class RolesRequest extends Request /** * Create a new RolesRequest instance. * - * @param int $companyId + * @param int $companyId */ public function __construct(int $companyId) { diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index 5b53ec6..c4b7e97 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -29,7 +29,7 @@ class CompanyRequest extends Request /** * Create a new CompanyRequest instance. * - * @param int $id + * @param int $id */ public function __construct(int $id) { diff --git a/src/Requests/PlayerRequest.php b/src/Requests/PlayerRequest.php index 0c25181..4b3539a 100644 --- a/src/Requests/PlayerRequest.php +++ b/src/Requests/PlayerRequest.php @@ -16,7 +16,7 @@ class PlayerRequest extends Request /** * Create a new PlayerRequest instance. * - * @param int $id + * @param int $id */ public function __construct(int $id) { diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index d89135c..ea23b49 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -4,7 +4,6 @@ use Carbon\Carbon; use Tests\TestCase; -use TruckersMP\Models\Company; use TruckersMP\Models\Player; class PlayerTest extends TestCase From 748c275b82bc13689aabc32ee3524ee01e5af3e9 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 23:13:10 +0000 Subject: [PATCH 090/123] Added the ability to get the players bans via the player request --- src/Models/Player.php | 21 +++++++++++++++++++++ src/Requests/PlayerRequest.php | 12 ++++++++++++ tests/TestCase.php | 23 +++++++++++++++++++++++ tests/Unit/PlayerTest.php | 20 +++++++++++++++++++- 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/Models/Player.php b/src/Models/Player.php index 022fe6f..66c46b1 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -3,6 +3,8 @@ namespace TruckersMP\Models; use Carbon\Carbon; +use TruckersMP\Collections\BanCollection; +use TruckersMP\Requests\BanRequest; class Player { @@ -125,12 +127,20 @@ class Player */ protected $companyMemberId; + /** + * The players bans. + * + * @var \TruckersMP\Collections\BanCollection + */ + protected $bans; + /** * Create a new Player instance. * * @param array $player * * @throws \Exception + * @throws \Http\Client\Exception */ public function __construct(array $player) { @@ -151,6 +161,9 @@ public function __construct(array $player) $this->companyTag = $player['vtc']['tag']; $this->isInCompany = $player['vtc']['inVTC']; $this->companyMemberId = $player['vtc']['memberID']; + + // Get the player bans + $this->bans = (new BanRequest($this->id))->get(); } /** @@ -288,4 +301,12 @@ public function getCompanyMemberId(): int { return $this->companyMemberId; } + + /** + * @return \TruckersMP\Collections\BanCollection + */ + public function getBans(): ?BanCollection + { + return $this->bans; + } } diff --git a/src/Requests/PlayerRequest.php b/src/Requests/PlayerRequest.php index 0c25181..a5cdfd8 100644 --- a/src/Requests/PlayerRequest.php +++ b/src/Requests/PlayerRequest.php @@ -50,4 +50,16 @@ public function get(): Player $this->send()['response'] ); } + + /** + * Get the players bans. + * + * @return \TruckersMP\Requests\BanRequest + */ + public function bans(): BanRequest + { + return new BanRequest( + $this->id + ); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 2f001e2..358f424 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -85,6 +85,29 @@ public function player(int $id): Player return $cachedPlayer->get(); } + /** + * Get or cache the players bans. + * + * @param int $id + * + * @return \TruckersMP\Collections\BanCollection + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function playerBans(int $id): BanCollection + { + $cachedBans = $this->cache->getItem('player_bans_' . $id); + + if (!$cachedBans->isHit()) { + $cachedBans->set($this->client->player($id)->bans()->get())->expiresAfter(self::CACHE_SECONDS); + $this->cache->save($cachedBans); + } + + return $cachedBans->get(); + } + /** * Get or cache the bans for the player. * diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index d89135c..67ce792 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use Tests\TestCase; +use TruckersMP\Collections\BanCollection; use TruckersMP\Models\Company; use TruckersMP\Models\Player; @@ -12,7 +13,7 @@ class PlayerTest extends TestCase /** * The ID of the player to use in the tests. */ - private const TEST_ACCOUNT = 6818; + private const TEST_ACCOUNT = 28159; /** * @throws \Http\Client\Exception @@ -232,4 +233,21 @@ public function testItHasAMemberId() $this->assertIsInt($player->getCompanyMemberId()); } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testWeCanGeThePlayersBans() + { + $bans = $this->playerBans(self::TEST_ACCOUNT); + + $this->assertInstanceOf(BanCollection::class, $bans); + + $player = $this->player(self::TEST_ACCOUNT); + + $this->assertInstanceOf(BanCollection::class, $player->getBans()); + } } From 2b7bbea031d7f08f5b752ed22818098a3f631788 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 23:29:05 +0000 Subject: [PATCH 091/123] Added the ability to get the players company via the model --- src/Models/Player.php | 23 ++++++++++++++++++++++- tests/TestCase.php | 2 +- tests/Unit/PlayerTest.php | 21 ++++++++++++++++++++- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/Models/Player.php b/src/Models/Player.php index 66c46b1..de332be 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -5,6 +5,7 @@ use Carbon\Carbon; use TruckersMP\Collections\BanCollection; use TruckersMP\Requests\BanRequest; +use TruckersMP\Requests\CompanyRequest; class Player { @@ -134,6 +135,13 @@ class Player */ protected $bans; + /** + * The players company. + * + * @var \TruckersMP\Models\Company|null + */ + protected $company; + /** * Create a new Player instance. * @@ -164,6 +172,11 @@ public function __construct(array $player) // Get the player bans $this->bans = (new BanRequest($this->id))->get(); + + // Get the players company + if ($this->isInCompany) { + $this->company = (new CompanyRequest($this->companyId))->get(); + } } /** @@ -305,8 +318,16 @@ public function getCompanyMemberId(): int /** * @return \TruckersMP\Collections\BanCollection */ - public function getBans(): ?BanCollection + public function getBans(): BanCollection { return $this->bans; } + + /** + * @return \TruckersMP\Models\Company|null + */ + public function getCompany(): ?Company + { + return $this->company; + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 358f424..5325d34 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -26,7 +26,7 @@ class TestCase extends BaseTestCase /** * The number of seconds we should cache the data for. */ - private const CACHE_SECONDS = 3600; + private const CACHE_SECONDS = 600; /** * @var \TruckersMP\Client diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index 67ce792..9e3d31c 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -240,7 +240,7 @@ public function testItHasAMemberId() * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException */ - public function testWeCanGeThePlayersBans() + public function testWeCanGetThePlayersBans() { $bans = $this->playerBans(self::TEST_ACCOUNT); @@ -250,4 +250,23 @@ public function testWeCanGeThePlayersBans() $this->assertInstanceOf(BanCollection::class, $player->getBans()); } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testWeCanGetThePlayersCompany() + { + $player = $this->player(self::TEST_ACCOUNT); + + $company = $player->getCompany(); + + if ($player->isInCompany()) { + $this->assertInstanceOf(Company::class, $company); + } else { + $this->assertNull($company); + } + } } From 012288edb233c421aa1bba47258fdb420a5fc8b7 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 23:36:04 +0000 Subject: [PATCH 092/123] Added the ability to get the players company member model via the player model --- src/Models/Player.php | 21 +++++++++++++++++++++ tests/Unit/PlayerTest.php | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/Models/Player.php b/src/Models/Player.php index de332be..72b768e 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -5,6 +5,7 @@ use Carbon\Carbon; use TruckersMP\Collections\BanCollection; use TruckersMP\Requests\BanRequest; +use TruckersMP\Requests\Companies\MemberRequest; use TruckersMP\Requests\CompanyRequest; class Player @@ -142,6 +143,13 @@ class Player */ protected $company; + /** + * The player a company member. + * + * @var \TruckersMP\Models\CompanyMember|null + */ + protected $companyMember; + /** * Create a new Player instance. * @@ -177,6 +185,11 @@ public function __construct(array $player) if ($this->isInCompany) { $this->company = (new CompanyRequest($this->companyId))->get(); } + + // Get the players company member + if ($this->isInCompany) { + $this->companyMember = (new MemberRequest($this->companyId, $this->companyMemberId))->get(); + } } /** @@ -330,4 +343,12 @@ public function getCompany(): ?Company { return $this->company; } + + /** + * @return \TruckersMP\Models\CompanyMember|null + */ + public function getCompanyMember(): ?CompanyMember + { + return $this->companyMember; + } } diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index 9e3d31c..15a1522 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -6,6 +6,7 @@ use Tests\TestCase; use TruckersMP\Collections\BanCollection; use TruckersMP\Models\Company; +use TruckersMP\Models\CompanyMember; use TruckersMP\Models\Player; class PlayerTest extends TestCase @@ -269,4 +270,23 @@ public function testWeCanGetThePlayersCompany() $this->assertNull($company); } } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testWeCanGetThePlayersCompanyMember() + { + $player = $this->player(self::TEST_ACCOUNT); + + $member = $player->getCompanyMember(); + + if ($player->isInCompany()) { + $this->assertInstanceOf(CompanyMember::class, $member); + } else { + $this->assertNull($member); + } + } } From 8c3f8818f4f1bec7f6ea940562a2e3d3b1f1fa1e Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 23:41:05 +0000 Subject: [PATCH 093/123] We can now get the players company role via the player model --- src/Models/Player.php | 21 +++++++++++++++++++++ tests/Unit/PlayerTest.php | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/Models/Player.php b/src/Models/Player.php index 72b768e..9f1801c 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -6,6 +6,7 @@ use TruckersMP\Collections\BanCollection; use TruckersMP\Requests\BanRequest; use TruckersMP\Requests\Companies\MemberRequest; +use TruckersMP\Requests\Companies\RoleRequest; use TruckersMP\Requests\CompanyRequest; class Player @@ -150,6 +151,13 @@ class Player */ protected $companyMember; + /** + * The players company role. + * + * @var \TruckersMP\Models\CompanyRole|null + */ + protected $companyRole; + /** * Create a new Player instance. * @@ -190,6 +198,11 @@ public function __construct(array $player) if ($this->isInCompany) { $this->companyMember = (new MemberRequest($this->companyId, $this->companyMemberId))->get(); } + + // Get the players company role + if ($this->isInCompany) { + $this->companyRole = (new RoleRequest($this->companyId, $this->companyMember->getRoleId()))->get(); + } } /** @@ -351,4 +364,12 @@ public function getCompanyMember(): ?CompanyMember { return $this->companyMember; } + + /** + * @return \TruckersMP\Models\CompanyRole|null + */ + public function getCompanyRole(): ?CompanyRole + { + return $this->companyRole; + } } diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index 15a1522..b99b7c8 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -7,6 +7,7 @@ use TruckersMP\Collections\BanCollection; use TruckersMP\Models\Company; use TruckersMP\Models\CompanyMember; +use TruckersMP\Models\CompanyRole; use TruckersMP\Models\Player; class PlayerTest extends TestCase @@ -289,4 +290,23 @@ public function testWeCanGetThePlayersCompanyMember() $this->assertNull($member); } } + + /** + * @throws \Http\Client\Exception + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException + */ + public function testWeCanGetThePlayersCompanyRole() + { + $player = $this->player(self::TEST_ACCOUNT); + + $role = $player->getCompanyRole(); + + if ($player->isInCompany()) { + $this->assertInstanceOf(CompanyRole::class, $role); + } else { + $this->assertNull($role); + } + } } From c14dc045ccbd1abbbc0e0c7d522718a17ca0438b Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 23:45:04 +0000 Subject: [PATCH 094/123] Optimized how we get the players company details --- src/Models/Player.php | 69 +++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/src/Models/Player.php b/src/Models/Player.php index 9f1801c..c4dd3a0 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -137,27 +137,6 @@ class Player */ protected $bans; - /** - * The players company. - * - * @var \TruckersMP\Models\Company|null - */ - protected $company; - - /** - * The player a company member. - * - * @var \TruckersMP\Models\CompanyMember|null - */ - protected $companyMember; - - /** - * The players company role. - * - * @var \TruckersMP\Models\CompanyRole|null - */ - protected $companyRole; - /** * Create a new Player instance. * @@ -188,21 +167,6 @@ public function __construct(array $player) // Get the player bans $this->bans = (new BanRequest($this->id))->get(); - - // Get the players company - if ($this->isInCompany) { - $this->company = (new CompanyRequest($this->companyId))->get(); - } - - // Get the players company member - if ($this->isInCompany) { - $this->companyMember = (new MemberRequest($this->companyId, $this->companyMemberId))->get(); - } - - // Get the players company role - if ($this->isInCompany) { - $this->companyRole = (new RoleRequest($this->companyId, $this->companyMember->getRoleId()))->get(); - } } /** @@ -351,25 +315,52 @@ public function getBans(): BanCollection /** * @return \TruckersMP\Models\Company|null + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function getCompany(): ?Company { - return $this->company; + $company = null; + + if ($this->isInCompany) { + $company = (new CompanyRequest($this->companyId))->get(); + } + + return $company; } /** * @return \TruckersMP\Models\CompanyMember|null + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function getCompanyMember(): ?CompanyMember { - return $this->companyMember; + $member = null; + + if ($this->isInCompany) { + $member = (new MemberRequest($this->companyId, $this->companyMemberId))->get(); + } + + return $member; } /** * @return \TruckersMP\Models\CompanyRole|null + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function getCompanyRole(): ?CompanyRole { - return $this->companyRole; + $role = null; + + if ($this->isInCompany) { + $role = (new RoleRequest($this->companyId, $this->getCompanyMember()->getRoleId()))->get(); + } + + return $role; } } From 0ab8b08cae94a13c9aeff8bfea9df13ddf67ec83 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Fri, 29 Nov 2019 23:45:56 +0000 Subject: [PATCH 095/123] Apply fixes from StyleCI --- src/Models/Player.php | 5 ++++- tests/TestCase.php | 1 + tests/Unit/PlayerTest.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Models/Player.php b/src/Models/Player.php index c4dd3a0..9c08f5e 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -315,6 +315,7 @@ public function getBans(): BanCollection /** * @return \TruckersMP\Models\Company|null + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException @@ -332,6 +333,7 @@ public function getCompany(): ?Company /** * @return \TruckersMP\Models\CompanyMember|null + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException @@ -349,6 +351,7 @@ public function getCompanyMember(): ?CompanyMember /** * @return \TruckersMP\Models\CompanyRole|null + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException @@ -358,7 +361,7 @@ public function getCompanyRole(): ?CompanyRole $role = null; if ($this->isInCompany) { - $role = (new RoleRequest($this->companyId, $this->getCompanyMember()->getRoleId()))->get(); + $role = (new RoleRequest($this->companyId, $this->getCompanyMember()->getRoleId()))->get(); } return $role; diff --git a/tests/TestCase.php b/tests/TestCase.php index 5325d34..1712a86 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -91,6 +91,7 @@ public function player(int $id): Player * @param int $id * * @return \TruckersMP\Collections\BanCollection + * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException * @throws \TruckersMP\Exceptions\PageNotFoundException diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index b99b7c8..2170da9 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -263,7 +263,7 @@ public function testWeCanGetThePlayersCompany() { $player = $this->player(self::TEST_ACCOUNT); - $company = $player->getCompany(); + $company = $player->getCompany(); if ($player->isInCompany()) { $this->assertInstanceOf(Company::class, $company); From b92240b47fe19941b78b102a34c20ef3da904348 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 1 Dec 2019 20:30:26 +0000 Subject: [PATCH 096/123] Corrected a comment spelling mistake in the PostRequest class Co-Authored-By: ShawnCZek --- src/Requests/Companies/PostRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Requests/Companies/PostRequest.php b/src/Requests/Companies/PostRequest.php index e1c9cd9..967f224 100644 --- a/src/Requests/Companies/PostRequest.php +++ b/src/Requests/Companies/PostRequest.php @@ -15,7 +15,7 @@ class PostRequest extends Request protected $companyId; /** - * The DID of the requested post. + * The ID of the requested post. * * @var int */ From b0aabbdc5b08156532788b5d044b85bb4762edad Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 1 Dec 2019 20:30:51 +0000 Subject: [PATCH 097/123] Corrected a comment spelling mistake in the MemberRequest class Co-Authored-By: ShawnCZek --- src/Requests/Companies/MemberRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Requests/Companies/MemberRequest.php b/src/Requests/Companies/MemberRequest.php index 4d38ee9..cb9c01a 100644 --- a/src/Requests/Companies/MemberRequest.php +++ b/src/Requests/Companies/MemberRequest.php @@ -15,7 +15,7 @@ class MemberRequest extends Request protected $companyId; /** - * The DID of the requested member. + * The ID of the requested member. * * @var int */ From d87a143ce562bdd47f3c4744857c0cf8105bf84b Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 1 Dec 2019 20:36:10 +0000 Subject: [PATCH 098/123] Updated collection construct comments to be accurate --- src/Collections/CompanyCollection.php | 2 +- src/Collections/PostsCollection.php | 2 +- src/Collections/RoleCollection.php | 4 +++- src/Collections/ServerCollection.php | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Collections/CompanyCollection.php b/src/Collections/CompanyCollection.php index 9d709d2..0aebf2a 100644 --- a/src/Collections/CompanyCollection.php +++ b/src/Collections/CompanyCollection.php @@ -7,7 +7,7 @@ class CompanyCollection extends Collection { /** - * Create a new Collection instance. + * Create a new CompanyCollection instance. * * @param array $companies * diff --git a/src/Collections/PostsCollection.php b/src/Collections/PostsCollection.php index 26c452f..50812f4 100644 --- a/src/Collections/PostsCollection.php +++ b/src/Collections/PostsCollection.php @@ -7,7 +7,7 @@ class PostsCollection extends Collection { /** - * Create a new Collection instance. + * Create a new PostsCollection instance. * * @param array $response */ diff --git a/src/Collections/RoleCollection.php b/src/Collections/RoleCollection.php index 8ba99f2..d98b8ba 100644 --- a/src/Collections/RoleCollection.php +++ b/src/Collections/RoleCollection.php @@ -7,9 +7,11 @@ class RoleCollection extends Collection { /** - * Create a new Collection instance. + * Create a new RoleCollection instance. * * @param array $response + * + * @throws \Exception */ public function __construct(array $response) { diff --git a/src/Collections/ServerCollection.php b/src/Collections/ServerCollection.php index a68ddae..ea9b920 100644 --- a/src/Collections/ServerCollection.php +++ b/src/Collections/ServerCollection.php @@ -7,7 +7,7 @@ class ServerCollection extends Collection { /** - * Create a new Collection instance. + * Create a new ServerCollection instance. * * @param array $response */ From 8ed40597051a94d2c3e5ad8a04a72e98ced48acc Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 1 Dec 2019 21:09:27 +0000 Subject: [PATCH 099/123] Updated CompanyIndex construct description --- src/Models/CompanyIndex.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Models/CompanyIndex.php b/src/Models/CompanyIndex.php index 3b3f0bc..98f75ae 100644 --- a/src/Models/CompanyIndex.php +++ b/src/Models/CompanyIndex.php @@ -28,9 +28,11 @@ class CompanyIndex protected $featuredCovered; /** - * Create a new Companies instance. + * Create a new CompanyIndex instance. * * @param array $response + * + * @throws \Exception */ public function __construct(array $response) { From 7bd2c7dcfbee1bb364fc9b6113712297ac3160f4 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 1 Dec 2019 21:11:20 +0000 Subject: [PATCH 100/123] We now use the getter to determine if the user is in a company --- src/Models/Player.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Models/Player.php b/src/Models/Player.php index 9c08f5e..969cda6 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -324,7 +324,7 @@ public function getCompany(): ?Company { $company = null; - if ($this->isInCompany) { + if ($this->isInCompany()) { $company = (new CompanyRequest($this->companyId))->get(); } @@ -342,7 +342,7 @@ public function getCompanyMember(): ?CompanyMember { $member = null; - if ($this->isInCompany) { + if ($this->isInCompany()) { $member = (new MemberRequest($this->companyId, $this->companyMemberId))->get(); } @@ -360,7 +360,7 @@ public function getCompanyRole(): ?CompanyRole { $role = null; - if ($this->isInCompany) { + if ($this->isInCompany()) { $role = (new RoleRequest($this->companyId, $this->getCompanyMember()->getRoleId()))->get(); } From b53847e2bacecff03f55cfd7db6294f0804bc287 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 1 Dec 2019 21:13:40 +0000 Subject: [PATCH 101/123] Update description of owner property in CompanyRole model Co-Authored-By: ShawnCZek <15310717+ShawnCZek@users.noreply.github.com> --- src/Models/CompanyRole.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/CompanyRole.php b/src/Models/CompanyRole.php index b346dc8..183bb82 100644 --- a/src/Models/CompanyRole.php +++ b/src/Models/CompanyRole.php @@ -28,7 +28,7 @@ class CompanyRole protected $order; /** - * The owner of the role. + * The owner of the company. * * @var bool */ From efc3f08ea0141b87a38b3a39cd03ab11961ad226 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 1 Dec 2019 21:15:55 +0000 Subject: [PATCH 102/123] We now only fetch the player bans when the getter is called --- src/Models/Player.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/Models/Player.php b/src/Models/Player.php index 969cda6..3289c0e 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -130,20 +130,12 @@ class Player */ protected $companyMemberId; - /** - * The players bans. - * - * @var \TruckersMP\Collections\BanCollection - */ - protected $bans; - /** * Create a new Player instance. * * @param array $player * * @throws \Exception - * @throws \Http\Client\Exception */ public function __construct(array $player) { @@ -164,9 +156,6 @@ public function __construct(array $player) $this->companyTag = $player['vtc']['tag']; $this->isInCompany = $player['vtc']['inVTC']; $this->companyMemberId = $player['vtc']['memberID']; - - // Get the player bans - $this->bans = (new BanRequest($this->id))->get(); } /** @@ -307,10 +296,13 @@ public function getCompanyMemberId(): int /** * @return \TruckersMP\Collections\BanCollection + * @throws \Http\Client\Exception + * @throws \TruckersMP\Exceptions\PageNotFoundException + * @throws \TruckersMP\Exceptions\RequestException */ public function getBans(): BanCollection { - return $this->bans; + return (new BanRequest($this->id))->get(); } /** From e213826ecc1ab0e63f0f5c1d345bd06b8d90a106 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 1 Dec 2019 21:16:57 +0000 Subject: [PATCH 103/123] Removed used property from CompanyRequest class --- src/Requests/CompanyRequest.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index c4b7e97..4df50e4 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -18,14 +18,7 @@ class CompanyRequest extends Request * @var int */ protected $id; - - /** - * The configuration to use for Guzzle. - * - * @var array - */ - protected $config = []; - + /** * Create a new CompanyRequest instance. * @@ -56,6 +49,7 @@ public function getEndpoint(): string * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException + * @throws \Exception */ public function get(): Company { From fa7e75d3bc84d42cfd4f28cb155cca30cc044dd8 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 1 Dec 2019 21:18:27 +0000 Subject: [PATCH 104/123] Aded .phpunit.result.cache to gitignore file --- .gitignore | 4 +++- src/Requests/CompanyRequest.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 4907691..4af8a0e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,7 @@ composer.phar # Unit Tests /tests/cache/ +.phpunit.result.cache - +# Mac OS +.DS_Store diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index 4df50e4..5e91a70 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -18,7 +18,7 @@ class CompanyRequest extends Request * @var int */ protected $id; - + /** * Create a new CompanyRequest instance. * From ce3aff289b2ccd05ce44c91f27ff74408ce4fc04 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 1 Dec 2019 21:20:32 +0000 Subject: [PATCH 105/123] Fixed styling in Player model --- src/Models/Player.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Models/Player.php b/src/Models/Player.php index 3289c0e..16681ed 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -296,6 +296,7 @@ public function getCompanyMemberId(): int /** * @return \TruckersMP\Collections\BanCollection + * * @throws \Http\Client\Exception * @throws \TruckersMP\Exceptions\PageNotFoundException * @throws \TruckersMP\Exceptions\RequestException From 9b099cb6f010b487bb1daff4fa948682927ae0bb Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sun, 1 Dec 2019 21:22:27 +0000 Subject: [PATCH 106/123] Updated composer.lock file --- composer.lock | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/composer.lock b/composer.lock index a21ac0d..b32d893 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": "ba66ac65346ff31be0772b912a130196", + "content-hash": "562b22b6456a4c6eb412a36ca893f778", "packages": [ { "name": "clue/stream-filter", @@ -607,16 +607,16 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.12.0", + "version": "v1.13.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17" + "reference": "7b4aab9743c30be783b73de055d24a39cf4b954f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b42a2f66e8f1b15ccf25652c3424265923eb4f17", - "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7b4aab9743c30be783b73de055d24a39cf4b954f", + "reference": "7b4aab9743c30be783b73de055d24a39cf4b954f", "shasum": "" }, "require": { @@ -628,7 +628,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.12-dev" + "dev-master": "1.13-dev" } }, "autoload": { @@ -662,11 +662,11 @@ "portable", "shim" ], - "time": "2019-08-06T08:03:45+00:00" + "time": "2019-11-27T14:18:11+00:00" }, { "name": "symfony/translation", - "version": "v5.0.0", + "version": "v5.0.1", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", @@ -743,20 +743,20 @@ }, { "name": "symfony/translation-contracts", - "version": "v2.0.0", + "version": "v2.0.1", "source": { "type": "git", "url": "https://github.com/symfony/translation-contracts.git", - "reference": "8feb81e6bb1a42d6a3b1429c751d291eb6d05297" + "reference": "8cc682ac458d75557203b2f2f14b0b92e1c744ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/8feb81e6bb1a42d6a3b1429c751d291eb6d05297", - "reference": "8feb81e6bb1a42d6a3b1429c751d291eb6d05297", + "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/8cc682ac458d75557203b2f2f14b0b92e1c744ed", + "reference": "8cc682ac458d75557203b2f2f14b0b92e1c744ed", "shasum": "" }, "require": { - "php": "^7.2.9" + "php": "^7.2.5" }, "suggest": { "symfony/translation-implementation": "" @@ -796,7 +796,7 @@ "interoperability", "standards" ], - "time": "2019-11-09T09:18:34+00:00" + "time": "2019-11-18T17:27:11+00:00" } ], "packages-dev": [ @@ -2484,16 +2484,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.12.0", + "version": "v1.13.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "550ebaac289296ce228a706d0867afc34687e3f4" + "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", - "reference": "550ebaac289296ce228a706d0867afc34687e3f4", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", + "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", "shasum": "" }, "require": { @@ -2505,7 +2505,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.12-dev" + "dev-master": "1.13-dev" } }, "autoload": { @@ -2538,7 +2538,7 @@ "polyfill", "portable" ], - "time": "2019-08-06T08:03:45+00:00" + "time": "2019-11-27T13:56:44+00:00" }, { "name": "theseer/tokenizer", @@ -2635,7 +2635,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.1.0", + "php": "^7.2", "ext-json": "*" }, "platform-dev": [] From b7740c855d5d3824fe2094941870d4faee3ae4cf Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 3 Dec 2019 16:07:30 +0000 Subject: [PATCH 107/123] Renamed NewsRequest to PostsRequest --- src/Requests/Companies/PostRequest.php | 2 +- .../Companies/{NewsRequest.php => PostsRequest.php} | 2 +- src/Requests/CompanyRequest.php | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) rename src/Requests/Companies/{NewsRequest.php => PostsRequest.php} (96%) diff --git a/src/Requests/Companies/PostRequest.php b/src/Requests/Companies/PostRequest.php index 967f224..11ad36b 100644 --- a/src/Requests/Companies/PostRequest.php +++ b/src/Requests/Companies/PostRequest.php @@ -27,7 +27,7 @@ class PostRequest extends Request * @param int $companyId * @param $postId */ - public function __construct(int $companyId, $postId) + public function __construct(int $companyId, int $postId) { parent::__construct(); diff --git a/src/Requests/Companies/NewsRequest.php b/src/Requests/Companies/PostsRequest.php similarity index 96% rename from src/Requests/Companies/NewsRequest.php rename to src/Requests/Companies/PostsRequest.php index 3014dad..184a0f8 100644 --- a/src/Requests/Companies/NewsRequest.php +++ b/src/Requests/Companies/PostsRequest.php @@ -5,7 +5,7 @@ use TruckersMP\Collections\PostsCollection; use TruckersMP\Requests\Request; -class NewsRequest extends Request +class PostsRequest extends Request { /** * The ID of the requested company. diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index 5e91a70..63cf355 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -5,7 +5,7 @@ use TruckersMP\Models\Company; use TruckersMP\Requests\Companies\MemberRequest; use TruckersMP\Requests\Companies\MembersRequest; -use TruckersMP\Requests\Companies\NewsRequest; +use TruckersMP\Requests\Companies\PostsRequest; use TruckersMP\Requests\Companies\PostRequest; use TruckersMP\Requests\Companies\RoleRequest; use TruckersMP\Requests\Companies\RolesRequest; @@ -61,11 +61,11 @@ public function get(): Company /** * Get the news posts for the company. * - * @return \TruckersMP\Requests\Companies\NewsRequest + * @return \TruckersMP\Requests\Companies\PostsRequest */ - public function posts(): NewsRequest + public function posts(): PostsRequest { - return new NewsRequest( + return new PostsRequest( $this->id ); } From 53459ec13fd5b975e38ac65248e311b952655607 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 3 Dec 2019 16:10:11 +0000 Subject: [PATCH 108/123] Fixed issue with styling --- src/Requests/CompanyRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index 63cf355..e0c5d89 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -5,8 +5,8 @@ use TruckersMP\Models\Company; use TruckersMP\Requests\Companies\MemberRequest; use TruckersMP\Requests\Companies\MembersRequest; -use TruckersMP\Requests\Companies\PostsRequest; use TruckersMP\Requests\Companies\PostRequest; +use TruckersMP\Requests\Companies\PostsRequest; use TruckersMP\Requests\Companies\RoleRequest; use TruckersMP\Requests\Companies\RolesRequest; From 652ccf404cacd1e52b06992c4c31f99257210716 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 3 Dec 2019 16:43:51 +0000 Subject: [PATCH 109/123] Renamed some classes and updated some as per pr #12 changes --- src/Client.php | 8 ++-- src/Models/Checksum.php | 9 ++-- src/Models/Company.php | 7 +++- src/Models/CompanyMemberIndex.php | 2 +- src/Models/Player.php | 4 +- src/Models/Social.php | 42 +++++++++++++++---- src/Models/Version.php | 6 ++- .../MemberIndexRequest.php} | 4 +- .../{Companies => Company}/MemberRequest.php | 2 +- .../PostIndexRequest.php} | 4 +- .../{Companies => Company}/PostRequest.php | 2 +- .../RoleIndexRequest.php} | 4 +- .../{Companies => Company}/RoleRequest.php | 2 +- ...iesRequest.php => CompanyIndexRequest.php} | 2 +- src/Requests/CompanyRequest.php | 36 ++++++++-------- tests/Unit/CompanyTest.php | 7 ++++ 16 files changed, 91 insertions(+), 50 deletions(-) rename src/Requests/{Companies/MembersRequest.php => Company/MemberIndexRequest.php} (92%) rename src/Requests/{Companies => Company}/MemberRequest.php (96%) rename src/Requests/{Companies/PostsRequest.php => Company/PostIndexRequest.php} (93%) rename src/Requests/{Companies => Company}/PostRequest.php (96%) rename src/Requests/{Companies/RolesRequest.php => Company/RoleIndexRequest.php} (92%) rename src/Requests/{Companies => Company}/RoleRequest.php (96%) rename src/Requests/{CompaniesRequest.php => CompanyIndexRequest.php} (93%) diff --git a/src/Client.php b/src/Client.php index 894b007..35d1f12 100644 --- a/src/Client.php +++ b/src/Client.php @@ -3,7 +3,7 @@ namespace TruckersMP; use TruckersMP\Requests\BanRequest; -use TruckersMP\Requests\CompaniesRequest; +use TruckersMP\Requests\CompanyIndexRequest; use TruckersMP\Requests\CompanyRequest; use TruckersMP\Requests\GameTimeRequest; use TruckersMP\Requests\PlayerRequest; @@ -87,11 +87,11 @@ public function gameTime(): GameTimeRequest * * https://stats.truckersmp.com/api#vtc_index * - * @return \TruckersMP\Requests\CompaniesRequest + * @return \TruckersMP\Requests\CompanyIndexRequest */ - public function companies(): CompaniesRequest + public function companies(): CompanyIndexRequest { - return new CompaniesRequest(); + return new CompanyIndexRequest(); } /** diff --git a/src/Models/Checksum.php b/src/Models/Checksum.php index d4f51af..4f5ffde 100644 --- a/src/Models/Checksum.php +++ b/src/Models/Checksum.php @@ -21,12 +21,13 @@ class Checksum /** * Create a new Checksum instance. * - * @param array $checksum + * @param string $dll + * @param string $adb */ - public function __construct(array $checksum) + public function __construct(string $dll, string $adb) { - $this->dll = $checksum['dll']; - $this->adb = $checksum['adb']; + $this->dll = $dll; + $this->adb = $adb; } /** diff --git a/src/Models/Company.php b/src/Models/Company.php index 5024e14..910ea69 100644 --- a/src/Models/Company.php +++ b/src/Models/Company.php @@ -178,7 +178,12 @@ public function __construct(array $company) $this->website = $company['website']; $this->social = new Social( - $company['socials'] + $company['socials']['twitter'], + $company['socials']['facebook'], + $company['socials']['twitch'], + $company['socials']['playstv'], + $company['socials']['discord'], + $company['socials']['youtube'] ); $this->games = new Game( diff --git a/src/Models/CompanyMemberIndex.php b/src/Models/CompanyMemberIndex.php index 396a12d..5663a23 100644 --- a/src/Models/CompanyMemberIndex.php +++ b/src/Models/CompanyMemberIndex.php @@ -14,7 +14,7 @@ class CompanyMemberIndex protected $members; /** - * The number of memebers in the company. + * The number of members in the company. * * @var int */ diff --git a/src/Models/Player.php b/src/Models/Player.php index 16681ed..3f9c74e 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -5,8 +5,8 @@ use Carbon\Carbon; use TruckersMP\Collections\BanCollection; use TruckersMP\Requests\BanRequest; -use TruckersMP\Requests\Companies\MemberRequest; -use TruckersMP\Requests\Companies\RoleRequest; +use TruckersMP\Requests\Company\MemberRequest; +use TruckersMP\Requests\Company\RoleRequest; use TruckersMP\Requests\CompanyRequest; class Player diff --git a/src/Models/Social.php b/src/Models/Social.php index 725c1e0..61ee051 100644 --- a/src/Models/Social.php +++ b/src/Models/Social.php @@ -14,6 +14,11 @@ class Social */ protected $facebook; + /** + * @var string|null + */ + protected $twitch; + /** * @var string|null */ @@ -32,15 +37,28 @@ class Social /** * Create a new Social instance. * - * @param array $social + * @param string|null $twitter + * @param string|null $facebook + * @param string|null $twitch + * @param string|null $plays + * @param string|null $discord + * @param string|null $youtube */ - public function __construct(array $social) - { - $this->twitter = $social['twitter']; - $this->facebook = $social['facebook']; - $this->plays = $social['playstv']; - $this->discord = $social['discord']; - $this->youtube = $social['youtube']; + public function __construct( + string $twitter = null, + string $facebook = null, + string $twitch = null, + string $plays = null, + string $discord = null, + string $youtube = null + ) { + + $this->twitter = $twitter; + $this->facebook = $facebook; + $this->twitch = $twitch; + $this->plays = $plays; + $this->discord = $discord; + $this->youtube = $youtube; } /** @@ -59,6 +77,14 @@ public function getFacebook(): ?string return $this->facebook; } + /** + * @return string|null + */ + public function getTwitch(): ?string + { + return $this->twitch; + } + /** * @return string|null */ diff --git a/src/Models/Version.php b/src/Models/Version.php index c62fcdc..3951b8e 100644 --- a/src/Models/Version.php +++ b/src/Models/Version.php @@ -76,11 +76,13 @@ public function __construct(array $version) $this->stage = $version['stage']; $this->ets2mpChecksum = new Checksum( - $version['ets2mp_checksum'] + $version['ets2mp_checksum']['dll'], + $version['ets2mp_checksum']['adb'] ); $this->atsmpChecksum = new Checksum( - $version['atsmp_checksum'] + $version['atsmp_checksum']['dll'], + $version['atsmp_checksum']['adb'] ); $this->time = new Carbon($version['time'], 'UTC'); diff --git a/src/Requests/Companies/MembersRequest.php b/src/Requests/Company/MemberIndexRequest.php similarity index 92% rename from src/Requests/Companies/MembersRequest.php rename to src/Requests/Company/MemberIndexRequest.php index 05e2c8f..f6213cd 100644 --- a/src/Requests/Companies/MembersRequest.php +++ b/src/Requests/Company/MemberIndexRequest.php @@ -1,11 +1,11 @@ id ); } @@ -75,7 +75,7 @@ public function posts(): PostsRequest * * @param int $id * - * @return \TruckersMP\Requests\Companies\PostRequest + * @return \TruckersMP\Requests\Company\PostRequest */ public function post(int $id): PostRequest { @@ -88,11 +88,11 @@ public function post(int $id): PostRequest /** * Get the roles for the company. * - * @return \TruckersMP\Requests\Companies\RolesRequest + * @return \TruckersMP\Requests\Company\RoleIndexRequest */ - public function roles(): RolesRequest + public function roles(): RoleIndexRequest { - return new RolesRequest( + return new RoleIndexRequest( $this->id ); } @@ -102,7 +102,7 @@ public function roles(): RolesRequest * * @param int $id * - * @return \TruckersMP\Requests\Companies\RoleRequest + * @return \TruckersMP\Requests\Company\RoleRequest */ public function role(int $id): RoleRequest { @@ -115,11 +115,11 @@ public function role(int $id): RoleRequest /** * Get the members for the company. * - * @return \TruckersMP\Requests\Companies\MembersRequest + * @return \TruckersMP\Requests\Company\MemberIndexRequest */ - public function members(): MembersRequest + public function members(): MemberIndexRequest { - return new MembersRequest( + return new MemberIndexRequest( $this->id ); } @@ -129,7 +129,7 @@ public function members(): MembersRequest * * @param int $id * - * @return \TruckersMP\Requests\Companies\MemberRequest + * @return \TruckersMP\Requests\Company\MemberRequest */ public function member(int $id): MemberRequest { diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index d80bc15..dbc63c9 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -270,6 +270,13 @@ public function testItHasSocialInformation() $this->assertNull($company->getSocial()->getFacebook()); } + // Twitch + if ($company->getSocial()->getTwitch() !== null) { + $this->assertIsString($company->getSocial()->getTwitch()); + } else { + $this->assertNull($company->getSocial()->getTwitch()); + } + // PlaysTV if ($company->getSocial()->getPlays() !== null) { $this->assertIsString($company->getSocial()->getPlays()); From 9f7c8c6f55a5d4ca9c2213982cb48953e07b4ad7 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 3 Dec 2019 16:47:16 +0000 Subject: [PATCH 110/123] Fixed styling issues --- src/Models/Social.php | 12 ++++++------ src/Requests/CompanyRequest.php | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Models/Social.php b/src/Models/Social.php index 61ee051..b485d7c 100644 --- a/src/Models/Social.php +++ b/src/Models/Social.php @@ -45,12 +45,12 @@ class Social * @param string|null $youtube */ public function __construct( - string $twitter = null, - string $facebook = null, - string $twitch = null, - string $plays = null, - string $discord = null, - string $youtube = null + ?string $twitter = null, + ?string $facebook = null, + ?string $twitch = null, + ?string $plays = null, + ?string $discord = null, + ?string $youtube = null ) { $this->twitter = $twitter; diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index b2bda83..40481ba 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -3,12 +3,12 @@ namespace TruckersMP\Requests; use TruckersMP\Models\Company; -use TruckersMP\Requests\Company\MemberRequest; use TruckersMP\Requests\Company\MemberIndexRequest; -use TruckersMP\Requests\Company\PostRequest; +use TruckersMP\Requests\Company\MemberRequest; use TruckersMP\Requests\Company\PostIndexRequest; -use TruckersMP\Requests\Company\RoleRequest; +use TruckersMP\Requests\Company\PostRequest; use TruckersMP\Requests\Company\RoleIndexRequest; +use TruckersMP\Requests\Company\RoleRequest; class CompanyRequest extends Request { From 930644f092bc322e4506f83ff91be3331afc644b Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 3 Dec 2019 16:48:02 +0000 Subject: [PATCH 111/123] Fixed further styling issues --- src/Models/Social.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Models/Social.php b/src/Models/Social.php index b485d7c..2a88a6e 100644 --- a/src/Models/Social.php +++ b/src/Models/Social.php @@ -52,7 +52,6 @@ public function __construct( ?string $discord = null, ?string $youtube = null ) { - $this->twitter = $twitter; $this->facebook = $facebook; $this->twitch = $twitch; From 5a0f71c9524f27ea028c4cb66158045cd1f7b552 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 3 Dec 2019 19:03:59 +0000 Subject: [PATCH 112/123] Apply suggestions from code review Co-Authored-By: ShawnCZek --- src/Models/Player.php | 4 ++-- src/Requests/Company/MemberIndexRequest.php | 2 +- src/Requests/Company/PostRequest.php | 2 +- src/Requests/Company/RoleIndexRequest.php | 2 +- src/Requests/Company/RoleRequest.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Models/Player.php b/src/Models/Player.php index 3f9c74e..a858cb7 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -33,7 +33,7 @@ class Player protected $avatar; /** - * URL to the small avatar on the website;. + * URL to the small avatar on the website. * * @var string */ @@ -77,7 +77,7 @@ class Player /** * The date and time the ban will expire (UTC) or null if not banned or ban is permanent. * - * @var \Carbon\Carbon + * @var \Carbon\Carbon|null */ protected $bannedUntil; diff --git a/src/Requests/Company/MemberIndexRequest.php b/src/Requests/Company/MemberIndexRequest.php index f6213cd..3bc261e 100644 --- a/src/Requests/Company/MemberIndexRequest.php +++ b/src/Requests/Company/MemberIndexRequest.php @@ -15,7 +15,7 @@ class MemberIndexRequest extends Request protected $companyId; /** - * Create a new MembersRequest instance. + * Create a new MemberIndexRequest instance. * * @param int $id */ diff --git a/src/Requests/Company/PostRequest.php b/src/Requests/Company/PostRequest.php index 9106784..8dbd3ef 100644 --- a/src/Requests/Company/PostRequest.php +++ b/src/Requests/Company/PostRequest.php @@ -25,7 +25,7 @@ class PostRequest extends Request * Create a new PostRequest instance. * * @param int $companyId - * @param $postId + * @param int $postId */ public function __construct(int $companyId, int $postId) { diff --git a/src/Requests/Company/RoleIndexRequest.php b/src/Requests/Company/RoleIndexRequest.php index a03639a..1ba9b4a 100644 --- a/src/Requests/Company/RoleIndexRequest.php +++ b/src/Requests/Company/RoleIndexRequest.php @@ -15,7 +15,7 @@ class RoleIndexRequest extends Request protected $companyId; /** - * Create a new RolesRequest instance. + * Create a new RoleIndexRequest instance. * * @param int $companyId */ diff --git a/src/Requests/Company/RoleRequest.php b/src/Requests/Company/RoleRequest.php index 5c9e4c3..bf9d202 100644 --- a/src/Requests/Company/RoleRequest.php +++ b/src/Requests/Company/RoleRequest.php @@ -22,7 +22,7 @@ class RoleRequest extends Request protected $roleId; /** - * Create a new RolesRequest instance. + * Create a new RoleRequest instance. * * @param int $companyId * @param int $roleId From 423fc395575a04d1f51a9e0c52d44c4809801f05 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 3 Dec 2019 19:05:58 +0000 Subject: [PATCH 113/123] Updated documentation for PostIndexRequest Co-Authored-By: ShawnCZek --- src/Requests/Company/PostIndexRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Requests/Company/PostIndexRequest.php b/src/Requests/Company/PostIndexRequest.php index 6ba6d9f..3776f6c 100644 --- a/src/Requests/Company/PostIndexRequest.php +++ b/src/Requests/Company/PostIndexRequest.php @@ -15,7 +15,7 @@ class PostIndexRequest extends Request protected $companyId; /** - * Create a new NewsRequest instance. + * Create a new PostIndexRequest instance. * * @param int $companyId */ From 796b97988a0dc73de81e87b27ab0b54d5a3e6b96 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 3 Dec 2019 19:29:15 +0000 Subject: [PATCH 114/123] Removed assert for social info being null --- tests/Unit/CompanyTest.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index dbc63c9..2db185f 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -259,44 +259,34 @@ public function testItHasSocialInformation() // Twitter if ($company->getSocial()->getTwitter() !== null) { $this->assertIsString($company->getSocial()->getTwitter()); - } else { - $this->assertNull($company->getSocial()->getTwitter()); } // Facebook if ($company->getSocial()->getFacebook() !== null) { $this->assertIsString($company->getSocial()->getFacebook()); - } else { - $this->assertNull($company->getSocial()->getFacebook()); } // Twitch if ($company->getSocial()->getTwitch() !== null) { $this->assertIsString($company->getSocial()->getTwitch()); - } else { - $this->assertNull($company->getSocial()->getTwitch()); } // PlaysTV if ($company->getSocial()->getPlays() !== null) { $this->assertIsString($company->getSocial()->getPlays()); - } else { - $this->assertNull($company->getSocial()->getPlays()); } // Discord if ($company->getSocial()->getDiscord() !== null) { $this->assertIsString($company->getSocial()->getDiscord()); - } else { - $this->assertNull($company->getSocial()->getDiscord()); } // YouTube if ($company->getSocial()->getYouTube() !== null) { $this->assertIsString($company->getSocial()->getYouTube()); - } else { - $this->assertNull($company->getSocial()->getYouTube()); } + + $this->assertInstanceOf(Social::class, $company->getSocial()); } /** From 573bb7c9b439201376fca0beee922d068d00e387 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 3 Dec 2019 19:37:03 +0000 Subject: [PATCH 115/123] Added the ability to tell if a companies recruitment is open or not --- src/Models/Company.php | 26 ++++++++++++++++++++++++++ tests/Unit/CompanyTest.php | 3 +++ 2 files changed, 29 insertions(+) diff --git a/src/Models/Company.php b/src/Models/Company.php index 910ea69..97acdfa 100644 --- a/src/Models/Company.php +++ b/src/Models/Company.php @@ -6,6 +6,16 @@ class Company { + /** + * The value used if recruitment is closed. + */ + public const RECRUITMENT_CLOSED = 'Close'; + + /** + * The value used if recruitment is open. + */ + public const RECRUITMENT_OPEN = 'Open'; + /** * The ID of the company requested. * @@ -349,4 +359,20 @@ public function getCreatedDate(): Carbon { return $this->createdAt; } + + /** + * @return bool + */ + public function isRecruitmentClosed(): bool + { + return $this->recruitment === self::RECRUITMENT_CLOSED; + } + + /** + * @return bool + */ + public function isRecruitmentOpen(): bool + { + return $this->recruitment === self::RECRUITMENT_OPEN; + } } diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index 2db185f..f7ef8cf 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -329,6 +329,9 @@ public function testItHasARecruitmentState() $company = $this->company(self::TEST_COMPANY); $this->assertIsString($company->getRecruitment()); + + $this->assertIsBool($company->isRecruitmentClosed()); + $this->assertIsBool($company->isRecruitmentOpen()); } /** From 2c74c48a82971d18c0202cd4d0a78417df82019c Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 3 Dec 2019 19:51:05 +0000 Subject: [PATCH 116/123] Updated the way we check if a company is open --- src/Models/Company.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Models/Company.php b/src/Models/Company.php index 97acdfa..750761f 100644 --- a/src/Models/Company.php +++ b/src/Models/Company.php @@ -9,12 +9,7 @@ class Company /** * The value used if recruitment is closed. */ - public const RECRUITMENT_CLOSED = 'Close'; - - /** - * The value used if recruitment is open. - */ - public const RECRUITMENT_OPEN = 'Open'; + protected const RECRUITMENT_CLOSED = 'Close'; /** * The ID of the company requested. @@ -373,6 +368,6 @@ public function isRecruitmentClosed(): bool */ public function isRecruitmentOpen(): bool { - return $this->recruitment === self::RECRUITMENT_OPEN; + return !$this->isRecruitmentClosed(); } } From fadc03cc233061967627a33b6c9c66f40485fe76 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 3 Dec 2019 19:51:50 +0000 Subject: [PATCH 117/123] Removed duplicate assertion when checking company social info --- tests/Unit/CompanyTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index f7ef8cf..609bc59 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -285,8 +285,6 @@ public function testItHasSocialInformation() if ($company->getSocial()->getYouTube() !== null) { $this->assertIsString($company->getSocial()->getYouTube()); } - - $this->assertInstanceOf(Social::class, $company->getSocial()); } /** From 2ee6e9c7555b55fa2c5fe13fd3259ada8dcfdf79 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 3 Dec 2019 21:41:30 +0000 Subject: [PATCH 118/123] Update all namespaces to be TruckersMP\APIClient --- composer.json | 2 +- src/ApiErrorHandler.php | 12 +- src/Client.php | 34 ++--- src/Collections/BanCollection.php | 4 +- src/Collections/Collection.php | 2 +- .../{ => Company}/MemberCollection.php | 5 +- .../PostCollection.php} | 7 +- .../{ => Company}/RoleCollection.php | 5 +- src/Collections/CompanyCollection.php | 4 +- src/Collections/ServerCollection.php | 4 +- src/Exceptions/PageNotFoundException.php | 2 +- src/Exceptions/RequestException.php | 2 +- src/Models/Ban.php | 2 +- src/Models/Checksum.php | 2 +- src/Models/Company.php | 2 +- src/Models/CompanyIndex.php | 4 +- src/Models/CompanyMember.php | 2 +- src/Models/CompanyMemberIndex.php | 8 +- src/Models/CompanyPost.php | 2 +- src/Models/CompanyRole.php | 2 +- src/Models/Game.php | 2 +- src/Models/GameTime.php | 2 +- src/Models/Player.php | 12 +- src/Models/Rule.php | 2 +- src/Models/Server.php | 2 +- src/Models/Social.php | 2 +- src/Models/Version.php | 2 +- src/Requests/BanRequest.php | 10 +- src/Requests/Company/MemberIndexRequest.php | 10 +- src/Requests/Company/MemberRequest.php | 10 +- src/Requests/Company/PostIndexRequest.php | 16 +-- src/Requests/Company/PostRequest.php | 10 +- src/Requests/Company/RoleIndexRequest.php | 13 +- src/Requests/Company/RoleRequest.php | 10 +- src/Requests/CompanyIndexRequest.php | 8 +- src/Requests/CompanyRequest.php | 32 ++--- src/Requests/GameTimeRequest.php | 8 +- src/Requests/PlayerRequest.php | 10 +- src/Requests/Request.php | 10 +- src/Requests/RuleRequest.php | 8 +- src/Requests/ServerRequest.php | 12 +- src/Requests/VersionRequest.php | 8 +- tests/TestCase.php | 121 +++++++++--------- tests/Unit/BanTest.php | 32 ++--- tests/Unit/ChecksumTest.php | 8 +- tests/Unit/CompanyMemberTest.php | 42 +++--- tests/Unit/CompanyPostTest.php | 42 +++--- tests/Unit/CompanyRoleTest.php | 36 +++--- tests/Unit/CompanyTest.php | 106 +++++++-------- tests/Unit/GameTimeTest.php | 6 +- tests/Unit/PlayerTest.php | 90 ++++++------- tests/Unit/RuleTest.php | 14 +- tests/Unit/ServerTest.php | 92 ++++++------- tests/Unit/VersionTest.php | 22 +++- 54 files changed, 470 insertions(+), 447 deletions(-) rename src/Collections/{ => Company}/MemberCollection.php (70%) rename src/Collections/{PostsCollection.php => Company/PostCollection.php} (63%) rename src/Collections/{ => Company}/RoleCollection.php (73%) diff --git a/composer.json b/composer.json index 818176c..26d50b3 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ }, "autoload": { "psr-4": { - "TruckersMP\\": "src/" + "TruckersMP\\APIClient\\": "src/" }, "classmap": [ "src/" diff --git a/src/ApiErrorHandler.php b/src/ApiErrorHandler.php index 6ced10f..c264f22 100644 --- a/src/ApiErrorHandler.php +++ b/src/ApiErrorHandler.php @@ -1,11 +1,11 @@ send()['response'] ); } diff --git a/src/Requests/Company/PostRequest.php b/src/Requests/Company/PostRequest.php index 8dbd3ef..77dee44 100644 --- a/src/Requests/Company/PostRequest.php +++ b/src/Requests/Company/PostRequest.php @@ -1,9 +1,9 @@ cache->getItem('company_posts_' . $id); @@ -257,8 +258,8 @@ public function companyPosts(int $id): PostsCollection * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function companyPost(int $companyId, int $postId): CompanyPost { @@ -280,12 +281,12 @@ public function companyPost(int $companyId, int $postId): CompanyPost * * @param int $companyId * - * @return \TruckersMP\Collections\RoleCollection|\TruckersMP\Models\CompanyRole[] + * @return \TruckersMP\APIClient\Collections\Company\RoleCollection|CompanyRole[] * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function companyRoles(int $companyId): RoleCollection { @@ -305,12 +306,12 @@ public function companyRoles(int $companyId): RoleCollection * @param int $companyId * @param int $roleId * - * @return \TruckersMP\Models\CompanyRole + * @return \TruckersMP\APIClient\Models\CompanyRole * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function companyRole(int $companyId, int $roleId): CompanyRole { @@ -336,8 +337,8 @@ public function companyRole(int $companyId, int $roleId): CompanyRole * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function companyMembers(int $companyId): CompanyMemberIndex { @@ -360,12 +361,12 @@ public function companyMembers(int $companyId): CompanyMemberIndex * @param int $companyId * @param int $memberId * - * @return \TruckersMP\Models\CompanyMember + * @return \TruckersMP\APIClient\Models\CompanyMember * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function companyMember(int $companyId, int $memberId): CompanyMember { @@ -385,12 +386,12 @@ public function companyMember(int $companyId, int $memberId): CompanyMember /** * Get or cache the TruckersMP version. * - * @return \TruckersMP\Models\Version + * @return \TruckersMP\APIClient\Models\Version * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function version(): Version { @@ -407,12 +408,12 @@ public function version(): Version /** * Get or cache the rules. * - * @return \TruckersMP\Models\Rule + * @return \TruckersMP\APIClient\Models\Rule * * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function rules(): Rule { diff --git a/tests/Unit/BanTest.php b/tests/Unit/BanTest.php index 3e1ed2f..5151d24 100644 --- a/tests/Unit/BanTest.php +++ b/tests/Unit/BanTest.php @@ -4,8 +4,8 @@ use Carbon\Carbon; use Tests\TestCase; -use TruckersMP\Collections\BanCollection; -use TruckersMP\Models\Ban; +use TruckersMP\APIClient\Collections\BanCollection; +use TruckersMP\APIClient\Models\Ban; class BanTest extends TestCase { @@ -17,8 +17,8 @@ class BanTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetAllBans() { @@ -34,8 +34,8 @@ public function testWeCanGetAllBans() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnExpiryDate() { @@ -57,8 +57,8 @@ public function testItHasAnExpiryDate() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasACreatedDate() { @@ -76,8 +76,8 @@ public function testItHasACreatedDate() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnActiveState() { @@ -95,8 +95,8 @@ public function testItHasAnActiveState() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAReason() { @@ -114,8 +114,8 @@ public function testItHasAReason() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasTheNameOfTheAdmin() { @@ -133,8 +133,8 @@ public function testItHasTheNameOfTheAdmin() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasTheIdOfTheAdmin() { diff --git a/tests/Unit/ChecksumTest.php b/tests/Unit/ChecksumTest.php index 41e6c01..5e7907e 100644 --- a/tests/Unit/ChecksumTest.php +++ b/tests/Unit/ChecksumTest.php @@ -9,8 +9,8 @@ class ChecksumTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasADLL() { @@ -22,8 +22,8 @@ public function testItHasADLL() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnADB() { diff --git a/tests/Unit/CompanyMemberTest.php b/tests/Unit/CompanyMemberTest.php index 551c0d3..14730c7 100644 --- a/tests/Unit/CompanyMemberTest.php +++ b/tests/Unit/CompanyMemberTest.php @@ -4,9 +4,9 @@ use Carbon\Carbon; use Tests\TestCase; -use TruckersMP\Collections\MemberCollection; -use TruckersMP\Models\CompanyMember; -use TruckersMP\Models\CompanyMemberIndex; +use TruckersMP\APIClient\Collections\Company\MemberCollection; +use TruckersMP\APIClient\Models\CompanyMember; +use TruckersMP\APIClient\Models\CompanyMemberIndex; class CompanyMemberTest extends TestCase { @@ -23,8 +23,8 @@ class CompanyMemberTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanAllTheMembers() { @@ -39,8 +39,8 @@ public function testWeCanAllTheMembers() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetAMember() { @@ -52,8 +52,8 @@ public function testWeCanGetAMember() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testTheMemberHasAnId() { @@ -66,8 +66,8 @@ public function testTheMemberHasAnId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testTheMemberHasAUserId() { @@ -80,8 +80,8 @@ public function testTheMemberHasAUserId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testTheMemberHasAUsername() { @@ -94,8 +94,8 @@ public function testTheMemberHasAUsername() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testTheMemberHasASteamId() { @@ -108,8 +108,8 @@ public function testTheMemberHasASteamId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testTheMemberHasARoleId() { @@ -122,8 +122,8 @@ public function testTheMemberHasARoleId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testTheMemberHasARole() { @@ -136,8 +136,8 @@ public function testTheMemberHasARole() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testTheMemberHasAJoinDate() { diff --git a/tests/Unit/CompanyPostTest.php b/tests/Unit/CompanyPostTest.php index 8f2311f..ac305e7 100644 --- a/tests/Unit/CompanyPostTest.php +++ b/tests/Unit/CompanyPostTest.php @@ -3,8 +3,8 @@ namespace Tests\Unit; use Tests\TestCase; -use TruckersMP\Collections\PostsCollection; -use TruckersMP\Models\CompanyPost; +use TruckersMP\APIClient\Collections\Company\PostCollection; +use TruckersMP\APIClient\Models\CompanyPost; class CompanyPostTest extends TestCase { @@ -21,14 +21,14 @@ class CompanyPostTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetAllTheNewsPosts() { $posts = $this->companyPosts(self::TEST_COMPANY); - $this->assertInstanceOf(PostsCollection::class, $posts); + $this->assertInstanceOf(PostCollection::class, $posts); if ($posts->count() > 0) { $post = $posts[0]; @@ -40,8 +40,8 @@ public function testWeCanGetAllTheNewsPosts() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetAPost() { @@ -53,8 +53,8 @@ public function testWeCanGetAPost() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnId() { @@ -66,8 +66,8 @@ public function testItHasAnId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasATitle() { @@ -79,8 +79,8 @@ public function testItHasATitle() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasASummary() { @@ -92,8 +92,8 @@ public function testItHasASummary() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasCotent() { @@ -105,8 +105,8 @@ public function testItHasCotent() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnAuthorId() { @@ -118,8 +118,8 @@ public function testItHasAnAuthorId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnAuthor() { @@ -131,8 +131,8 @@ public function testItHasAnAuthor() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testIfThePostIsPinned() { diff --git a/tests/Unit/CompanyRoleTest.php b/tests/Unit/CompanyRoleTest.php index c675f15..df32cf0 100644 --- a/tests/Unit/CompanyRoleTest.php +++ b/tests/Unit/CompanyRoleTest.php @@ -4,8 +4,8 @@ use Carbon\Carbon; use Tests\TestCase; -use TruckersMP\Collections\RoleCollection; -use TruckersMP\Models\CompanyRole; +use TruckersMP\APIClient\Collections\Company\RoleCollection; +use TruckersMP\APIClient\Models\CompanyRole; class CompanyRoleTest extends TestCase { @@ -22,8 +22,8 @@ class CompanyRoleTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetAllTheRoles() { @@ -41,8 +41,8 @@ public function testWeCanGetAllTheRoles() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetARole() { @@ -54,8 +54,8 @@ public function testWeCanGetARole() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnId() { @@ -67,8 +67,8 @@ public function testItHasAnId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAName() { @@ -80,8 +80,8 @@ public function testItHasAName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnOrder() { @@ -93,8 +93,8 @@ public function testItHasAnOrder() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testIfItIsAnOwner() { @@ -106,8 +106,8 @@ public function testIfItIsAnOwner() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasACreatedAtDate() { @@ -119,8 +119,8 @@ public function testItHasACreatedAtDate() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnUpdatedAtDate() { diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index 609bc59..afa3f3d 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -4,11 +4,11 @@ use Carbon\Carbon; use Tests\TestCase; -use TruckersMP\Collections\CompanyCollection; -use TruckersMP\Models\Company; -use TruckersMP\Models\CompanyIndex; -use TruckersMP\Models\Game; -use TruckersMP\Models\Social; +use TruckersMP\APIClient\Collections\CompanyCollection; +use TruckersMP\APIClient\Models\Company; +use TruckersMP\APIClient\Models\CompanyIndex; +use TruckersMP\APIClient\Models\Game; +use TruckersMP\APIClient\Models\Social; class CompanyTest extends TestCase { @@ -20,8 +20,8 @@ class CompanyTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetTheCompanies() { @@ -33,8 +33,8 @@ public function testWeCanGetTheCompanies() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetTheRecentCompanies() { @@ -48,8 +48,8 @@ public function testWeCanGetTheRecentCompanies() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetTheFeaturedCompanies() { @@ -63,8 +63,8 @@ public function testWeCanGetTheFeaturedCompanies() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetTheFeaturedCoverCompanies() { @@ -78,8 +78,8 @@ public function testWeCanGetTheFeaturedCoverCompanies() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetACompany() { @@ -91,8 +91,8 @@ public function testWeCanGetACompany() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnId() { @@ -104,8 +104,8 @@ public function testItHasAnId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAName() { @@ -117,8 +117,8 @@ public function testItHasAName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnOwnerId() { @@ -130,8 +130,8 @@ public function testItHasAnOwnerId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnOwnerName() { @@ -143,8 +143,8 @@ public function testItHasAnOwnerName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasASlogan() { @@ -156,8 +156,8 @@ public function testItHasASlogan() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasATag() { @@ -169,8 +169,8 @@ public function testItHasATag() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasALogo() { @@ -182,8 +182,8 @@ public function testItHasALogo() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasACover() { @@ -195,8 +195,8 @@ public function testItHasACover() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasInformation() { @@ -208,8 +208,8 @@ public function testItHasInformation() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasRules() { @@ -221,8 +221,8 @@ public function testItHasRules() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasRequirements() { @@ -234,8 +234,8 @@ public function testItHasRequirements() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAWebsite() { @@ -247,8 +247,8 @@ public function testItHasAWebsite() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasSocialInformation() { @@ -290,8 +290,8 @@ public function testItHasSocialInformation() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasSupportedGames() { @@ -306,8 +306,8 @@ public function testItHasSupportedGames() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasMemberCount() { @@ -319,8 +319,8 @@ public function testItHasMemberCount() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasARecruitmentState() { @@ -335,8 +335,8 @@ public function testItHasARecruitmentState() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasALanguage() { @@ -348,8 +348,8 @@ public function testItHasALanguage() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testIfItsVerified() { @@ -361,8 +361,8 @@ public function testIfItsVerified() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasACreatedDate() { diff --git a/tests/Unit/GameTimeTest.php b/tests/Unit/GameTimeTest.php index 4db7a1d..68c7170 100644 --- a/tests/Unit/GameTimeTest.php +++ b/tests/Unit/GameTimeTest.php @@ -4,15 +4,15 @@ use Carbon\Carbon; use Tests\TestCase; -use TruckersMP\Models\GameTime; +use TruckersMP\APIClient\Models\GameTime; class GameTimeTest extends TestCase { /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetTheGameTime() { diff --git a/tests/Unit/PlayerTest.php b/tests/Unit/PlayerTest.php index 2170da9..b8a56e2 100644 --- a/tests/Unit/PlayerTest.php +++ b/tests/Unit/PlayerTest.php @@ -4,11 +4,11 @@ use Carbon\Carbon; use Tests\TestCase; -use TruckersMP\Collections\BanCollection; -use TruckersMP\Models\Company; -use TruckersMP\Models\CompanyMember; -use TruckersMP\Models\CompanyRole; -use TruckersMP\Models\Player; +use TruckersMP\APIClient\Collections\BanCollection; +use TruckersMP\APIClient\Models\Company; +use TruckersMP\APIClient\Models\CompanyMember; +use TruckersMP\APIClient\Models\CompanyRole; +use TruckersMP\APIClient\Models\Player; class PlayerTest extends TestCase { @@ -20,8 +20,8 @@ class PlayerTest extends TestCase /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetThePlayer() { @@ -33,8 +33,8 @@ public function testWeCanGetThePlayer() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnId() { @@ -46,8 +46,8 @@ public function testItHasAnId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAName() { @@ -59,8 +59,8 @@ public function testItHasAName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnAvatar() { @@ -76,8 +76,8 @@ public function testItHasAnAvatar() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAJoinDate() { @@ -89,8 +89,8 @@ public function testItHasAJoinDate() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasASteamId() { @@ -102,8 +102,8 @@ public function testItHasASteamId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAGroupName() { @@ -115,8 +115,8 @@ public function testItHasAGroupName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAGroupId() { @@ -128,8 +128,8 @@ public function testItHasAGroupId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testIfItIsBanned() { @@ -141,8 +141,8 @@ public function testIfItIsBanned() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasABannedUntilDate() { @@ -154,8 +154,8 @@ public function testItHasABannedUntilDate() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testIfBansAreHidden() { @@ -167,8 +167,8 @@ public function testIfBansAreHidden() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasIfAdmin() { @@ -180,8 +180,8 @@ public function testItHasIfAdmin() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasACompanyId() { @@ -193,8 +193,8 @@ public function testItHasACompanyId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasACompanyName() { @@ -206,8 +206,8 @@ public function testItHasACompanyName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasACompanyTag() { @@ -226,8 +226,8 @@ public function testIfInACompany() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAMemberId() { @@ -239,8 +239,8 @@ public function testItHasAMemberId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetThePlayersBans() { @@ -256,8 +256,8 @@ public function testWeCanGetThePlayersBans() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetThePlayersCompany() { @@ -275,8 +275,8 @@ public function testWeCanGetThePlayersCompany() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetThePlayersCompanyMember() { @@ -294,8 +294,8 @@ public function testWeCanGetThePlayersCompanyMember() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetThePlayersCompanyRole() { diff --git a/tests/Unit/RuleTest.php b/tests/Unit/RuleTest.php index 849dea3..2e5f6c2 100644 --- a/tests/Unit/RuleTest.php +++ b/tests/Unit/RuleTest.php @@ -3,15 +3,15 @@ namespace Tests\Unit; use Tests\TestCase; -use TruckersMP\Models\Rule; +use TruckersMP\APIClient\Models\Rule; class RuleTest extends TestCase { /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetTheRules() { @@ -23,8 +23,8 @@ public function testWeCanGetTheRules() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasTheRules() { @@ -36,8 +36,8 @@ public function testItHasTheRules() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasTheRevision() { diff --git a/tests/Unit/ServerTest.php b/tests/Unit/ServerTest.php index c28f699..c6152f2 100644 --- a/tests/Unit/ServerTest.php +++ b/tests/Unit/ServerTest.php @@ -3,16 +3,16 @@ namespace Tests\Unit; use Tests\TestCase; -use TruckersMP\Collections\ServerCollection; -use TruckersMP\Models\Server; +use TruckersMP\APIClient\Collections\ServerCollection; +use TruckersMP\APIClient\Models\Server; class ServerTest extends TestCase { /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetAllTheServers() { @@ -28,8 +28,8 @@ public function testWeCanGetAllTheServers() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnId() { @@ -41,8 +41,8 @@ public function testItHasAnId() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAGame() { @@ -54,8 +54,8 @@ public function testItHasAGame() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnIp() { @@ -67,8 +67,8 @@ public function testItHasAnIp() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAPort() { @@ -80,8 +80,8 @@ public function testItHasAPort() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAName() { @@ -93,8 +93,8 @@ public function testItHasAName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAShortName() { @@ -106,8 +106,8 @@ public function testItHasAShortName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnIdPrefix() { @@ -123,8 +123,8 @@ public function testItHasAnIdPrefix() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnOnlineState() { @@ -136,8 +136,8 @@ public function testItHasAnOnlineState() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasPlayers() { @@ -149,8 +149,8 @@ public function testItHasPlayers() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAQueue() { @@ -162,8 +162,8 @@ public function testItHasAQueue() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasMaxPlayers() { @@ -175,8 +175,8 @@ public function testItHasMaxPlayers() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasADisplayOrder() { @@ -188,8 +188,8 @@ public function testItHasADisplayOrder() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasASpeedLimit() { @@ -201,8 +201,8 @@ public function testItHasASpeedLimit() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasCollisions() { @@ -214,8 +214,8 @@ public function testItHasCollisions() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasCarsForPlayers() { @@ -227,8 +227,8 @@ public function testItHasCarsForPlayers() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasPoliceCarsForPlayers() { @@ -240,8 +240,8 @@ public function testItHasPoliceCarsForPlayers() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAfkEnable() { @@ -253,8 +253,8 @@ public function testItHasAfkEnable() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnEvent() { @@ -266,8 +266,8 @@ public function testItHasAnEvent() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasASpecialEvent() { @@ -279,8 +279,8 @@ public function testItHasASpecialEvent() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasPromods() { @@ -292,8 +292,8 @@ public function testItHasPromods() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException - * @throws \TruckersMP\Exceptions\PageNotFoundException - * @throws \TruckersMP\Exceptions\RequestException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasSyncDelay() { diff --git a/tests/Unit/VersionTest.php b/tests/Unit/VersionTest.php index 40feae9..e8c3e5f 100644 --- a/tests/Unit/VersionTest.php +++ b/tests/Unit/VersionTest.php @@ -4,14 +4,16 @@ use Carbon\Carbon; use Tests\TestCase; -use TruckersMP\Models\Checksum; -use TruckersMP\Models\Version; +use TruckersMP\APIClient\Models\Checksum; +use TruckersMP\APIClient\Models\Version; class VersionTest extends TestCase { /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testWeCanGetTheVersion() { @@ -23,6 +25,8 @@ public function testWeCanGetTheVersion() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAName() { @@ -34,6 +38,8 @@ public function testItHasAName() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasANumeric() { @@ -45,6 +51,8 @@ public function testItHasANumeric() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAStage() { @@ -56,6 +64,8 @@ public function testItHasAStage() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnETS2MPChecksum() { @@ -67,6 +77,8 @@ public function testItHasAnETS2MPChecksum() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasAnATSMPChecksum() { @@ -78,6 +90,8 @@ public function testItHasAnATSMPChecksum() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasATime() { @@ -89,6 +103,8 @@ public function testItHasATime() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasASupportedGameVersion() { @@ -100,6 +116,8 @@ public function testItHasASupportedGameVersion() /** * @throws \Http\Client\Exception * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \TruckersMP\APIClient\Exceptions\PageNotFoundException + * @throws \TruckersMP\APIClient\Exceptions\RequestException */ public function testItHasASupportedATSGameVersion() { From 3a2de4815485f0290c00f9ff44a02a7a4b82682c Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Tue, 3 Dec 2019 21:43:37 +0000 Subject: [PATCH 119/123] Apply fixes from StyleCI --- src/ApiErrorHandler.php | 2 +- src/Requests/ServerRequest.php | 1 - tests/TestCase.php | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ApiErrorHandler.php b/src/ApiErrorHandler.php index c264f22..9d76fb3 100644 --- a/src/ApiErrorHandler.php +++ b/src/ApiErrorHandler.php @@ -13,7 +13,7 @@ class ApiErrorHandler * Check if the API returned an error. * * @param \Psr\Http\Message\StreamInterface $body - * @param int $statusCode + * @param int $statusCode * * @return \Exception * diff --git a/src/Requests/ServerRequest.php b/src/Requests/ServerRequest.php index cb71961..845c1a0 100644 --- a/src/Requests/ServerRequest.php +++ b/src/Requests/ServerRequest.php @@ -3,7 +3,6 @@ namespace TruckersMP\APIClient\Requests; use TruckersMP\APIClient\Collections\ServerCollection; -use TruckersMP\APIClient\Models\Server; class ServerRequest extends Request { diff --git a/tests/TestCase.php b/tests/TestCase.php index 6c5ac14..bae51dc 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,7 +9,6 @@ use TruckersMP\APIClient\Collections\BanCollection; use TruckersMP\APIClient\Collections\Company\PostCollection; use TruckersMP\APIClient\Collections\Company\RoleCollection; -use TruckersMP\APIClient\Collections\PostsCollection; use TruckersMP\APIClient\Collections\ServerCollection; use TruckersMP\APIClient\Models\Company; use TruckersMP\APIClient\Models\CompanyIndex; From 56a269a3402a22b185416edf6daacab3535d3dfa Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Wed, 4 Dec 2019 22:28:43 +0000 Subject: [PATCH 120/123] Updated the type of sync delay --- src/Models/Server.php | 6 +++--- tests/Unit/ServerTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Models/Server.php b/src/Models/Server.php index 8cc7c27..39cf81c 100644 --- a/src/Models/Server.php +++ b/src/Models/Server.php @@ -147,7 +147,7 @@ class Server /** * The server tick rate. * - * @var bool + * @var int */ protected $syncDelay; @@ -342,9 +342,9 @@ public function hasPromods(): bool } /** - * @return bool + * @return int */ - public function hasSyncDelay(): bool + public function getSyncDelay(): int { return $this->syncDelay; } diff --git a/tests/Unit/ServerTest.php b/tests/Unit/ServerTest.php index c6152f2..0bd6154 100644 --- a/tests/Unit/ServerTest.php +++ b/tests/Unit/ServerTest.php @@ -299,6 +299,6 @@ public function testItHasSyncDelay() { $server = $this->servers()[0]; - $this->assertIsBool($server->hasSyncDelay()); + $this->assertIsInt($server->getSyncDelay()); } } From 783fa94b3553c2ed29ac1bf143c9fd3296cd9dbd Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Thu, 5 Dec 2019 16:51:52 +0000 Subject: [PATCH 121/123] Updated getter name on Version model --- src/Models/Version.php | 6 +++--- tests/Unit/VersionTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Models/Version.php b/src/Models/Version.php index 659c575..7a0aebc 100644 --- a/src/Models/Version.php +++ b/src/Models/Version.php @@ -53,7 +53,7 @@ class Version * * @var string */ - protected $supportedGameVersion; + protected $supportedETS2GameVersion; /** * The ATS version that is supported. @@ -86,7 +86,7 @@ public function __construct(array $version) ); $this->time = new Carbon($version['time'], 'UTC'); - $this->supportedGameVersion = $version['supported_game_version']; + $this->supportedETS2GameVersion = $version['supported_game_version']; $this->supportedATSGameVersion = $version['supported_ats_game_version']; } @@ -141,7 +141,7 @@ public function getTime(): Carbon /** * @return string */ - public function getSupportedGameVersion(): string + public function getSupportedETS2GameVersion(): string { return $this->supportedGameVersion; } diff --git a/tests/Unit/VersionTest.php b/tests/Unit/VersionTest.php index e8c3e5f..e80a254 100644 --- a/tests/Unit/VersionTest.php +++ b/tests/Unit/VersionTest.php @@ -110,7 +110,7 @@ public function testItHasASupportedGameVersion() { $version = $this->version(); - $this->assertIsString($version->getSupportedGameVersion()); + $this->assertIsString($version->getSupportedETS2GameVersion()); } /** From a28981cb0dc72317c6bff5503ed6dbe589827f8a Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Thu, 5 Dec 2019 16:55:26 +0000 Subject: [PATCH 122/123] Fixed an issue with an undefined property --- src/Models/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/Version.php b/src/Models/Version.php index 7a0aebc..a07dfb2 100644 --- a/src/Models/Version.php +++ b/src/Models/Version.php @@ -143,7 +143,7 @@ public function getTime(): Carbon */ public function getSupportedETS2GameVersion(): string { - return $this->supportedGameVersion; + return $this->supportedETS2GameVersion; } /** From 1ad2d811df252ae4820da1df5104c9d7255db04b Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 14 Dec 2019 23:09:14 +0000 Subject: [PATCH 123/123] Added PHP 7.4 to Travis CI config --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index d957e0c..8905453 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ cache: php: - 7.2 - 7.3 + - 7.4 before_install: - composer self-update