Skip to content

Commit

Permalink
Added new player methods (#20)
Browse files Browse the repository at this point in the history
* Improved the readability of test names

* We can now check if a player is a staff member or an upper staff member

* We can now get the users patreon information

* Updated composer dependencies

* Made the player patreon tests more future proof
  • Loading branch information
bensherred authored Jul 18, 2020
1 parent 12bc0e7 commit 33eb977
Show file tree
Hide file tree
Showing 15 changed files with 896 additions and 1,108 deletions.
523 changes: 287 additions & 236 deletions composer.lock

Large diffs are not rendered by default.

174 changes: 174 additions & 0 deletions src/Models/Patreon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?php

namespace TruckersMP\APIClient\Models;

class Patreon
{
/**
* If the current player is a patron.
*
* @var bool
*/
protected $isPatron;

/**
* If the players patron subscription is active.
*
* @var bool
*/
protected $active;

/**
* The HEX code for subscribed tier.
*
* @var string|null
*/
protected $color;

/**
* The players tier ID.
*
* @var int|null
*/
protected $tierId;

/**
* The players current pledge.
*
* @var int|null
*/
protected $currentPledge;

/**
* The players lifetime pledge.
*
* @var int|null
*/
protected $lifetimePledge;

/**
* The players next pledge.
*
* @var int|null
*/
protected $nextPledge;

/**
* If the user has their patreon information hidden.
*
* @var bool
*/
protected $hidden;

/**
* Create a new Patreon instance.
*
* @param bool $isPatron
* @param bool $active
* @param string|null $color
* @param int|null $tierId
* @param int|null $currentPledge
* @param int|null $lifetimePledge
* @param int|null $nextPledge
* @param bool|null $hidden
*/
public function __construct(
bool $isPatron,
bool $active,
?string $color,
?int $tierId,
?int $currentPledge,
?int $lifetimePledge,
?int $nextPledge,
?bool $hidden
) {
$this->isPatron = $isPatron;
$this->active = $active;
$this->color = $color;
$this->tierId = $tierId;
$this->currentPledge = $currentPledge;
$this->lifetimePledge = $lifetimePledge;
$this->nextPledge = $nextPledge;
$this->hidden = $hidden;
}

/**
* Get if the current player is a patron.
*
* @return bool
*/
public function isPatron(): bool
{
return $this->isPatron;
}

/**
* Get if the players patron subscription is active.
*
* @return mixed
*/
public function isActive(): bool
{
return $this->active;
}

/**
* Get the HEX code for subscribed tier.
*
* @return string|null
*/
public function getColor(): ?string
{
return $this->color;
}

/**
* Get the players tier ID.
*
* @return int|null
*/
public function getTierId(): ?int
{
return $this->tierId;
}

/**
* Get the players current pledge.
*
* @return int|null
*/
public function getCurrentPledge(): ?int
{
return $this->currentPledge;
}

/**
* Get the players lifetime pledge.
*
* @return int|null
*/
public function getLifetimePledge(): ?int
{
return $this->lifetimePledge;
}

/**
* Get the players next pledge.
*
* @return int|null
*/
public function getNextPledge(): ?int
{
return $this->nextPledge;
}

/**
* Get if the user has their patreon information hidden.
*
* @return bool|null
*/
public function isHidden(): ?bool
{
return $this->hidden;
}
}
65 changes: 65 additions & 0 deletions src/Models/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ class Player
*/
protected $displayBans;

/**
* Get the players patreon information.
*
* @var Patreon
*/
protected $patreon;

/**
* If the user is a staff member.
*
* @var bool
*/
protected $isStaff;

/**
* If the user is an upper staff member.
*
* @var bool
*/
protected $isUpperStaff;

/**
* If user is an in-game admin.
*
Expand Down Expand Up @@ -170,6 +191,20 @@ public function __construct(array $player)
$this->isBanned = $player['banned'];
$this->bannedUntil = new Carbon($player['bannedUntil'], 'UTC');
$this->displayBans = $player['displayBans'];

$this->patreon = new Patreon(
$player['patreon']['isPatron'],
$player['patreon']['active'],
$player['patreon']['color'],
$player['patreon']['tierId'],
$player['patreon']['currentPledge'],
$player['patreon']['lifetimePledge'],
$player['patreon']['nextPledge'],
$player['patreon']['hidden']
);

$this->isStaff = $player['permissions']['isStaff'];
$this->isUpperStaff = $player['permissions']['isUpperStaff'];
$this->inGameAdmin = $player['permissions']['isGameAdmin'];
$this->companyId = $player['vtc']['id'];
$this->companyName = $player['vtc']['name'];
Expand Down Expand Up @@ -299,6 +334,36 @@ public function hasBansHidden(): bool
return !$this->displayBans;
}

/**
* Get the players patreon information.
*
* @return Patreon
*/
public function patreon(): Patreon
{
return $this->patreon;
}

/**
* Check if the player is a staff member.
*
* @return bool
*/
public function isStaff(): bool
{
return $this->isStaff;
}

/**
* Check if the player is an upper staff member.
*
* @return bool
*/
public function isUpperStaff(): bool
{
return $this->isUpperStaff;
}

/**
* Check if the player is an in-game admin.
*
Expand Down
67 changes: 14 additions & 53 deletions tests/Unit/BanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
namespace Tests\Unit;

use Carbon\Carbon;
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
use Psr\Http\Client\ClientExceptionInterface;
use Tests\TestCase;
use TruckersMP\APIClient\Collections\BanCollection;
use TruckersMP\APIClient\Exceptions\PageNotFoundException;
use TruckersMP\APIClient\Exceptions\RequestException;
use TruckersMP\APIClient\Models\Ban;

class BanTest extends TestCase
Expand All @@ -18,13 +14,8 @@ class BanTest extends TestCase
*/
private const TEST_ACCOUNT = 28159;

/**
* @throws PhpfastcacheInvalidArgumentException
* @throws PageNotFoundException
* @throws RequestException
* @throws ClientExceptionInterface
*/
public function testWeCanGetAllBans()
/** @test */
public function it_can_get_all_bans()
{
$bans = $this->bans(self::TEST_ACCOUNT);

Expand All @@ -35,13 +26,8 @@ public function testWeCanGetAllBans()
}
}

/**
* @throws PhpfastcacheInvalidArgumentException
* @throws PageNotFoundException
* @throws RequestException
* @throws ClientExceptionInterface
*/
public function testItHasAnExpiryDate()
/** @test */
public function it_has_an_expiry_date()
{
$bans = $this->bans(self::TEST_ACCOUNT);

Expand All @@ -58,13 +44,8 @@ public function testItHasAnExpiryDate()
}
}

/**
* @throws PhpfastcacheInvalidArgumentException
* @throws PageNotFoundException
* @throws RequestException
* @throws ClientExceptionInterface
*/
public function testItHasACreatedDate()
/** @test */
public function it_has_created_at_date()
{
$bans = $this->bans(self::TEST_ACCOUNT);

Expand All @@ -77,13 +58,8 @@ public function testItHasACreatedDate()
}
}

/**
* @throws PhpfastcacheInvalidArgumentException
* @throws PageNotFoundException
* @throws RequestException
* @throws ClientExceptionInterface
*/
public function testItHasAnActiveState()
/** @test */
public function it_has_active_state()
{
$bans = $this->bans(self::TEST_ACCOUNT);

Expand All @@ -96,13 +72,8 @@ public function testItHasAnActiveState()
}
}

/**
* @throws PhpfastcacheInvalidArgumentException
* @throws PageNotFoundException
* @throws RequestException
* @throws ClientExceptionInterface
*/
public function testItHasAReason()
/** @test */
public function it_has_a_reason()
{
$bans = $this->bans(self::TEST_ACCOUNT);

Expand All @@ -115,13 +86,8 @@ public function testItHasAReason()
}
}

/**
* @throws PhpfastcacheInvalidArgumentException
* @throws PageNotFoundException
* @throws RequestException
* @throws ClientExceptionInterface
*/
public function testItHasTheNameOfTheAdmin()
/** @test */
public function it_has_the_name_of_the_admin()
{
$bans = $this->bans(self::TEST_ACCOUNT);

Expand All @@ -134,13 +100,8 @@ public function testItHasTheNameOfTheAdmin()
}
}

/**
* @throws PhpfastcacheInvalidArgumentException
* @throws PageNotFoundException
* @throws RequestException
* @throws ClientExceptionInterface
*/
public function testItHasTheIdOfTheAdmin()
/** @test */
public function it_has_the_id_of_the_admin()
{
$bans = $this->bans(self::TEST_ACCOUNT);

Expand Down
Loading

0 comments on commit 33eb977

Please sign in to comment.