Added email fields to V1User and also reordering to match with API output.
This commit is contained in:
parent
6a93d31375
commit
6661830422
2 changed files with 32 additions and 18 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
0.2.1
|
0.2.2
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
// V1User.php
|
// V1User.php
|
||||||
// Created: 2024-11-16
|
// Created: 2024-11-16
|
||||||
// Updated: 2024-11-16
|
// Updated: 2024-11-21
|
||||||
|
|
||||||
namespace Flashii\V1\Users;
|
namespace Flashii\V1\Users;
|
||||||
|
|
||||||
|
@ -18,33 +18,35 @@ final class V1User {
|
||||||
/**
|
/**
|
||||||
* @param string $id User ID.
|
* @param string $id User ID.
|
||||||
* @param string $name User name.
|
* @param string $name User name.
|
||||||
|
* @param string $email User e-mail address, if identify:email scope is requested, otherwise blank.
|
||||||
* @param ?int $colourRaw Raw 24-bit RGB value, null for inherit.
|
* @param ?int $colourRaw Raw 24-bit RGB value, null for inherit.
|
||||||
* @param string $colourCss CSS colour.
|
* @param string $colourCss CSS colour.
|
||||||
* @param int $rank User rank.
|
* @param int $rank User rank.
|
||||||
* @param string $countryCode ISO 3166-1 alpha-2 (adjacent) country code.
|
* @param string $countryCode ISO 3166-1 alpha-2 (adjacent) country code.
|
||||||
* @param V1UserAvatar[] $avatarUrls Avatar URIs.
|
* @param string[] $roles User role strings.
|
||||||
* @param string $profileUrl Profile URI.
|
* @param bool $super Super user status.
|
||||||
|
* @param string $title User title.
|
||||||
* @param DateTimeInterface $createdAt User registration date.
|
* @param DateTimeInterface $createdAt User registration date.
|
||||||
* @param ?DateTimeInterface $lastActiveAt Last user activity, null for none or hidden.
|
* @param ?DateTimeInterface $lastActiveAt Last user activity, null for none or hidden.
|
||||||
* @param string[] $roles User role strings.
|
* @param string $profileUrl Profile URI.
|
||||||
* @param string $title User title.
|
* @param V1UserAvatar[] $avatarUrls Avatar URIs.
|
||||||
* @param bool $super Super user status.
|
|
||||||
* @param bool $deleted Deleted status.
|
* @param bool $deleted Deleted status.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly string $id,
|
private readonly string $id,
|
||||||
private readonly string $name,
|
private readonly string $name,
|
||||||
|
private readonly string $email,
|
||||||
private readonly ?int $colourRaw,
|
private readonly ?int $colourRaw,
|
||||||
private readonly string $colourCss,
|
private readonly string $colourCss,
|
||||||
private readonly int $rank,
|
private readonly int $rank,
|
||||||
private readonly string $countryCode,
|
private readonly string $countryCode,
|
||||||
private readonly array $avatarUrls,
|
private readonly array $roles,
|
||||||
private readonly string $profileUrl,
|
private readonly bool $super,
|
||||||
|
private readonly string $title,
|
||||||
private readonly DateTimeInterface $createdAt,
|
private readonly DateTimeInterface $createdAt,
|
||||||
private readonly ?DateTimeInterface $lastActiveAt,
|
private readonly ?DateTimeInterface $lastActiveAt,
|
||||||
private readonly array $roles,
|
private readonly string $profileUrl,
|
||||||
private readonly string $title,
|
private readonly array $avatarUrls,
|
||||||
private readonly bool $super,
|
|
||||||
private readonly bool $deleted
|
private readonly bool $deleted
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
@ -66,6 +68,17 @@ final class V1User {
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets user e-mail address.
|
||||||
|
*
|
||||||
|
* Will be blank regardless of anything if the identify:email scope isn't granted.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getEMailAddress(): string {
|
||||||
|
return $this->email;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether a raw 24-bit RGB colour is present.
|
* Whether a raw 24-bit RGB colour is present.
|
||||||
*
|
*
|
||||||
|
@ -260,18 +273,19 @@ final class V1User {
|
||||||
return new static(
|
return new static(
|
||||||
isset($info->id) && is_string($info->id) ? $info->id : '',
|
isset($info->id) && is_string($info->id) ? $info->id : '',
|
||||||
isset($info->name) && is_string($info->name) ? $info->name : '',
|
isset($info->name) && is_string($info->name) ? $info->name : '',
|
||||||
|
isset($info->email) && is_string($info->email) ? $info->email : '',
|
||||||
isset($info->colour_raw) && is_int($info->colour_raw) ? $info->colour_raw : null,
|
isset($info->colour_raw) && is_int($info->colour_raw) ? $info->colour_raw : null,
|
||||||
isset($info->colour_css) && is_string($info->colour_css) ? $info->colour_css : '',
|
isset($info->colour_css) && is_string($info->colour_css) ? $info->colour_css : '',
|
||||||
isset($info->rank) && is_int($info->rank) ? $info->rank : 0,
|
isset($info->rank) && is_int($info->rank) ? $info->rank : 0,
|
||||||
isset($info->country_code) && is_string($info->country_code) ? $info->country_code : '',
|
isset($info->country_code) && is_string($info->country_code) ? $info->country_code : '',
|
||||||
isset($info->avatar_urls) && is_array($info->avatar_urls) ? array_map(fn(mixed $item) => (is_object($item) ? V1UserAvatar::decode($item) : V1UserAvatar::empty()), $info->avatar_urls) : [],
|
isset($info->roles) && is_array($info->roles) ? $info->roles : [], // @phpstan-ignore-line
|
||||||
isset($info->profile_url) && is_string($info->profile_url) ? $info->profile_url : '',
|
isset($info->is_super) && is_bool($info->is_super) ? $info->is_super : false,
|
||||||
|
isset($info->title) && is_string($info->title) ? $info->title : '',
|
||||||
new DateTimeImmutable(isset($info->created_at) && is_string($info->created_at) ? $info->created_at : '@0'),
|
new DateTimeImmutable(isset($info->created_at) && is_string($info->created_at) ? $info->created_at : '@0'),
|
||||||
isset($info->last_active_at) && is_string($info->last_active_at) ? new DateTimeImmutable($info->last_active_at) : null,
|
isset($info->last_active_at) && is_string($info->last_active_at) ? new DateTimeImmutable($info->last_active_at) : null,
|
||||||
isset($info->roles) && is_array($info->roles) ? $info->roles : [], // @phpstan-ignore-line
|
isset($info->profile_url) && is_string($info->profile_url) ? $info->profile_url : '',
|
||||||
isset($info->title) && is_string($info->title) ? $info->title : '',
|
isset($info->avatar_urls) && is_array($info->avatar_urls) ? array_map(fn(mixed $item) => (is_object($item) ? V1UserAvatar::decode($item) : V1UserAvatar::empty()), $info->avatar_urls) : [],
|
||||||
isset($info->super) && is_bool($info->super) ? $info->super : false,
|
isset($info->is_deleted) && is_bool($info->is_deleted) ? $info->is_deleted : false
|
||||||
isset($info->deleted) && is_bool($info->deleted) ? $info->deleted : false
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue