Skip to content

Commit 8048a3e

Browse files
committed
nullable session
1 parent e052e64 commit 8048a3e

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

src/Api/AbstractCore.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Http\Client\Common\Plugin\QueryDefaultsPlugin;
1313
use Psr\Http\Message\ResponseInterface;
1414
use Psr\Http\Message\UriInterface;
15+
use RuntimeException;
1516
use Shapecode\FUT\Client\Authentication\AccountInterface;
1617
use Shapecode\FUT\Client\Authentication\Session;
1718
use Shapecode\FUT\Client\Config\Config;
@@ -694,9 +695,14 @@ public function clubConsumables()
694695
*/
695696
public function squad(int $squadId = 0)
696697
{
698+
$session = $this->getAccount()->getSession();
699+
if ($session === null) {
700+
throw new RuntimeException('session has to be set');
701+
}
702+
697703
$this->pin->sendEvent('page_view', 'Hub - Squads');
698704

699-
$personaId = $this->getAccount()->getSession()->getPersona();
705+
$personaId = $session->getPersona();
700706
$response = $this->request('GET', '/squad/' . $squadId . '/user/' . $personaId);
701707

702708
$this->pin->sendEvent('page_view', 'Squads - Squad Overview');
@@ -1122,6 +1128,10 @@ protected function request(
11221128
$account = $this->getAccount();
11231129
$session = $account->getSession();
11241130

1131+
if ($session === null) {
1132+
throw new RuntimeException('session has to be set');
1133+
}
1134+
11251135
if ($method === 'GET') {
11261136
$params['_'] = time();
11271137
}

src/Api/Pin.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Shapecode\FUT\Client\Api;
66

77
use Carbon\Carbon;
8+
use RuntimeException;
89
use Shapecode\FUT\Client\Authentication\AccountInterface;
910
use Shapecode\FUT\Client\Exception\PinErrorException;
1011
use Shapecode\FUT\Client\Http\ClientFactoryInterface;
@@ -58,6 +59,10 @@ public function event(
5859
$account = $this->account;
5960
$session = $account->getSession();
6061

62+
if ($session === null) {
63+
throw new RuntimeException('session has to be set');
64+
}
65+
6166
$data = [
6267
'core' => [
6368
'dob' => $session->getDob(),
@@ -121,6 +126,10 @@ public function send(array $events) : bool
121126
$session = $account->getSession();
122127
$platform = $account->getCredentials()->getPlatform();
123128

129+
if ($session === null) {
130+
throw new RuntimeException('session has to be set');
131+
}
132+
124133
$body = json_encode([
125134
'custom' => [
126135
'networkAccess' => 'G',

src/Authentication/Account.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Shapecode\FUT\Client\Authentication;
66

77
use GuzzleHttp\ClientInterface;
8-
use RuntimeException;
98
use Shapecode\FUT\Client\Model\ProxyInterface;
109

1110
class Account implements AccountInterface
@@ -37,12 +36,8 @@ public function getCredentials() : CredentialsInterface
3736
return $this->credentials;
3837
}
3938

40-
public function getSession() : SessionInterface
39+
public function getSession() : ?SessionInterface
4140
{
42-
if ($this->session === null) {
43-
throw new RuntimeException('session has to be set');
44-
}
45-
4641
return $this->session;
4742
}
4843

src/Authentication/AccountInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface AccountInterface
1010
{
1111
public function getCredentials() : CredentialsInterface;
1212

13-
public function getSession() : SessionInterface;
13+
public function getSession() : ?SessionInterface;
1414

1515
public function setSession(SessionInterface $session) : void;
1616

0 commit comments

Comments
 (0)