Skip to content
This repository has been archived by the owner on Jul 2, 2022. It is now read-only.

Add flags & premium type to User #6

Merged
merged 2 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Provider/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ protected function createResourceOwner(array $response, AccessToken $token)
->setDiscriminator(new UserDiscriminator((string)$response['discriminator']))
->setAvatar($response['avatar'])
->setBot(array_key_exists('bot', $response) ? $response['bot'] : false)
->setMfaEnabled($response['mfa_enabled']);
->setMfaEnabled($response['mfa_enabled'])
->setFlags($response['flags'])
->setPublicFlags($response['public_flags'])
->setPremiumType(array_key_exists('premium_type', $response) ? $response['premium_type'] : 0);
}

if (array_key_exists('email', $response) === true && $response['email'] !== null) { // Has 'email' scope
Expand Down
92 changes: 82 additions & 10 deletions src/Provider/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ class User implements ResourceOwnerInterface
*/
private $guilds;

/**
* @var int
*/
private $flags;

/**
* @var int
*/
private $public_flags;

/**
* @var int
*/
private $premium_type;

/**
* @var AccessToken
*/
Expand Down Expand Up @@ -94,6 +109,60 @@ public function setId(string $id)
return $this;
}

/**
* @return int
*/
public function getFlags(): int
{
return $this->flags;
}

/**
* @param int $flags
* @return $this
*/
public function setFlags($flags)
{
$this->flags = $flags;
return $this;
}

/**
* @return int
*/
public function getPublicFlags()
{
return $this->public_flags;
}

/**
* @param int $flags
* @return User
*/
public function setPublicFlags($flags)
{
$this->public_flags = $flags;
return $this;
}

/**
* @return int
*/
public function getPremiumType()
{
return $this->premium_type;
}

/**
* @param int $premiumType
* @return $this
*/
public function setPremiumType($premiumType)
{
$this->premium_type = $premiumType;
return $this;
}

/**
* @return UserName
*/
Expand Down Expand Up @@ -154,7 +223,7 @@ public function setAvatar($avatar)
/**
* @return bool
*/
public function isBot(): bool
public function isBot()
{
return $this->bot;
}
Expand All @@ -164,7 +233,7 @@ public function isBot(): bool
*
* @return $this
*/
public function setBot(bool $bot)
public function setBot($bot)
{
$this->bot = $bot;
return $this;
Expand All @@ -173,7 +242,7 @@ public function setBot(bool $bot)
/**
* @return bool
*/
public function isMfaEnabled(): bool
public function isMfaEnabled()
{
return $this->mfa_enabled;
}
Expand All @@ -183,7 +252,7 @@ public function isMfaEnabled(): bool
*
* @return $this
*/
public function setMfaEnabled(bool $mfa_enabled)
public function setMfaEnabled($mfa_enabled)
{
$this->mfa_enabled = $mfa_enabled;
return $this;
Expand All @@ -192,7 +261,7 @@ public function setMfaEnabled(bool $mfa_enabled)
/**
* @return bool
*/
public function isVerified(): bool
public function isVerified()
{
return boolval($this->verified);
}
Expand All @@ -202,7 +271,7 @@ public function isVerified(): bool
*
* @return $this
*/
public function setVerified(bool $verified)
public function setVerified($verified)
{
$this->verified = $verified;
return $this;
Expand Down Expand Up @@ -279,15 +348,18 @@ public function setAccessToken(AccessToken $access_token)
}

/**
* @inheritDoc
* @return array
*/
public function toArray()
{
return [
'id' => $this->id,
'username' => $this->username,
'id' => $this->id,
'username' => $this->username,
'discriminator' => $this->discriminator,
'avatar' => $this->avatar
'avatar' => $this->avatar,
'flags' => $this->flags,
'public_flags' => $this->public_flags,
'premium_type' => $this->premium_type
];
}
}