Skip to content

Commit

Permalink
Merge pull request #248 from P3D-Legacy/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dsbilling authored Jan 31, 2023
2 parents e4ef9f0 + 377d739 commit 929049e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
14 changes: 5 additions & 9 deletions app/Helpers/StatsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ class StatsHelper

const METHOD_POST = 'post';

public static function countForumMembers()
public static function countForumMembers(): int
{
try {
$count = XenForoHelper::getUserCount();

return $count;
return XenForoHelper::getUserCount();
} catch (\Exception $exception) {
return 0;
}
}

public static function countPlayers()
public static function countPlayers(): int
{
try {
$data = self::sendRequest('/server/status');
Expand All @@ -35,11 +33,10 @@ public static function countPlayers()
}
}

public static function getInGameSeason()
public static function getInGameSeason(): string
{
$season = date('W') % 4;
$seasonName = 'spring';
//echo "Season (WOY % 4): " . $season;
if ($season == 0) {
$seasonName = __('fall');
} elseif ($season == 1) {
Expand All @@ -65,8 +62,7 @@ public static function sendRequest($endpoint, $data = [], $method = self::METHOD

$url = config('gameserver.base_url').$endpoint;
$response = Http::withHeaders([])->$method($url, $data);
$decodedResponse = json_decode($response, true);

return $decodedResponse;
return json_decode($response, true);
}
}
17 changes: 11 additions & 6 deletions app/Helpers/XenForoHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Http;

class XenForoHelper
Expand All @@ -12,9 +13,9 @@ class XenForoHelper

const METHOD_POST = 'post';

public static function sendRequest($endpoint, $data = [], $method = self::METHOD_GET)
public static function sendRequest($endpoint, $data = [], $method = self::METHOD_GET): array
{
if (! config('services.xenforo.api_key') or ! config('services.xenforo.api_url')) {
if (! config('services.xenforo.api_key') or ! config('services.xenforo.api_url') or ! config('services.xenforo.base_url')) {
return ['errors' => []];
}
if (is_string($data)) {
Expand All @@ -25,12 +26,11 @@ public static function sendRequest($endpoint, $data = [], $method = self::METHOD
$response = Http::withHeaders([
'XF-Api-Key' => config('services.xenforo.api_key'),
])->$method($url, $data);
$decodedResponse = json_decode($response, true);

return $decodedResponse;
return json_decode($response, true);
}

public static function getUserCount()
public static function getUserCount(): int
{
$data = self::sendRequest('/users');
if ($data) {
Expand All @@ -44,7 +44,7 @@ public static function getUserCount()
return 0;
}

public static function postAuth($login, $password)
public static function postAuth($login, $password): array
{
$credentials = [
'login' => $login,
Expand Down Expand Up @@ -76,6 +76,11 @@ public static function postAuth($login, $password)
'error' => true,
'message' => $data['errors'][0]['message'] ?? 'Could not find error message.',
];
} catch (GuzzleException $e) {
return [
'error' => true,
'message' => $e->getMessage() ?? 'Could not find error message.',
];
}

$data = $response->getBody();
Expand Down
2 changes: 1 addition & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class User extends Authenticatable implements MustVerifyEmail
'gender',
'location',
'about',
'birtdate',
'birthdate',
'last_active_at',
'timezone',
'created_at',
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/NovaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function boot()

// TIMEZONE
Nova::userTimezone(function ($request) {
return $request->user()->timezone;
return $request->user() ? $request->user()->timezone : null;
});

// FOOTER
Expand Down

0 comments on commit 929049e

Please sign in to comment.