Skip to content

Commit

Permalink
Update toArray function to be cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
wisoot committed May 4, 2016
1 parent b64521d commit 947dc58
Showing 1 changed file with 9 additions and 31 deletions.
40 changes: 9 additions & 31 deletions src/Claim.php
Expand Up @@ -179,37 +179,15 @@ public function validateAccessible()
public function toArray()
{
$data = [];

if (!empty($this->sub)) {
$data['sub'] = $this->sub;
}

if (!empty($this->iss)) {
$data['iss'] = $this->iss;
}

if (!empty($this->aud)) {
$data['aud'] = $this->aud;
}

if (!empty($this->iat)) {
$data['iat'] = $this->iat;
}

if (!empty($this->exp)) {
$data['exp'] = $this->exp;
}

if (!empty($this->nbf)) {
$data['nbf'] = $this->nbf;
}

if (!empty($this->nat)) {
$data['nat'] = $this->nat;
}

if (!empty($this->jti)) {
$data['jti'] = $this->jti;
$fields = [
'sub', 'iss', 'aud', 'iat',
'exp', 'nbf', 'nat', 'jti'
];

foreach ($fields as $field) {
if (!empty($this->{$field})) {
$data[$field] = $this->{$field};
}
}

if ($this->refresh) {
Expand Down

0 comments on commit 947dc58

Please sign in to comment.