From 3355bd78b97374beefa36202e468c8bb2891b0ec Mon Sep 17 00:00:00 2001 From: grandeljay Date: Wed, 30 Aug 2023 12:51:23 +0200 Subject: [PATCH] fix: define class properties for php 8.2 --- index.php | 3 +- src/classes/wishthis/User.php | 130 +++++++++++++++++++++++++++--- src/classes/wishthis/Wish.php | 95 +++++++++++++++++++--- src/classes/wishthis/Wishlist.php | 50 ++++++++++-- 4 files changed, 247 insertions(+), 31 deletions(-) diff --git a/index.php b/index.php index 4a5bef23..cf05e8da 100644 --- a/index.php +++ b/index.php @@ -48,7 +48,8 @@ if (file_exists($configPath)) { */ session_start( array( - 'name' => 'wishthis', + 'name' => 'wishthis', + 'read_and_close' => true, ) ); diff --git a/src/classes/wishthis/User.php b/src/classes/wishthis/User.php index 311e8acf..6c6b0c5a 100644 --- a/src/classes/wishthis/User.php +++ b/src/classes/wishthis/User.php @@ -12,9 +12,6 @@ namespace wishthis; class User { - /** - * Static - */ public static function getFromID(int $user_id): self { global $database; @@ -36,7 +33,7 @@ class User return $user; } - throw new Exception('Unable to find user with ID ' . $user_id . '. Does it exist?'); + throw new \Exception('Unable to find user with ID ' . $user_id . '. Does it exist?'); } public static function generatePassword(string $plainPassword): string @@ -45,24 +42,137 @@ class User } /** - * Private + * The users unique ID. + * + * @var int + */ + private int $id; + + /** + * The users unique email address. They are not verified and may be made + * up. + * + * @var string + */ + private string $email; + + /** + * The users hashed password. + * + * @var string + */ + private string $password; + + /** + * The users password reset token. + * + * @var string + */ + private string $password_reset_token; + + /** + * A unix timestamp indicating until when the users password reset token is + * valid. + * + * @var int + */ + private int $password_reset_valid_until; + + /** + * A unix timestamp of when the user has logged in last. + * + * @var int + */ + private int $last_login; + + /** + * The users power. Administrator have 100, users 1 and unregistered guests + * 0. + * + * @var int + */ + private int $power = 0; + + /** + * A unix timestamp of the users birthdate. + * + * @var int + */ + private int $birthdate; + + /** + * More accurately, this is the users locale (e. g. `en_GB`). + * + * @var string */ private string $language; + + /** + * The users currency (e. g. `EUR`). + * + * @var string + */ private string $currency; + /** + * The users first name. + * + * @var string + */ + private string $name_first; + + /** + * The users last name. + * + * @var string + */ + private string $name_last; + + /** + * The users nick name. + * + * @var string + */ + private string $name_nick; + + /** + * The users preferred release channel. Usually `stable` or + * `release-candidate` but can also be unset if not defined. + * + * @var string + */ + private string $channel; + + /** + * Whether the user consented to seeing advertisements. + * + * @var bool + */ + private bool $advertisements = false; + /** * Non-Static */ - public int $power = 0; public ?\Gettext\Translations $translations = null; - public bool $advertisements = false; public function __construct(array $fields = array()) { if (!empty($fields)) { - foreach ($fields as $key => $value) { - $this->$key = $value; - } + $this->id = $fields['id']; + $this->email = $fields['email']; + $this->password = $fields['password']; + $this->password_reset_token = $fields['password_reset_token']; + $this->password_reset_valid_until = $fields['password_reset_valid_until']; + $this->last_login = $fields['last_login']; + $this->power = $fields['power']; + $this->birthdate = $fields['birthdate']; + $this->language = $fields['language']; + $this->currency = $fields['currency']; + $this->name_first = $fields['name_first']; + $this->name_last = $fields['name_last']; + $this->name_nick = $fields['name_nick']; + $this->channel = $fields['channel']; + $this->advertisements = $fields['advertisements']; } /** Set Language */ diff --git a/src/classes/wishthis/Wish.php b/src/classes/wishthis/Wish.php index e8ddbcab..b118ee80 100644 --- a/src/classes/wishthis/Wish.php +++ b/src/classes/wishthis/Wish.php @@ -50,16 +50,78 @@ class Wish */ private Cache\Embed $cache; - /** General */ - public int $id; - public int $wishlist; - public ?string $title; - public ?string $description; - public ?string $image; - public ?string $url; - public ?int $priority; - public bool $is_purchasable; - public ?string $status; + /** + * The unique wish id. + * + * @var int + */ + private int $id; + + /** + * The wishlist id for this wish. + * + * TODO: rename this to wishlist_id (the database column too). + * + * @var int + */ + private int $wishlist; + + /** + * The wish title. + * + * @var string|null + */ + private string $title; + + /** + * The wish description. + * + * @var string|null + */ + private string $description; + + /** + * The wish image url. + * + * @var string|null + */ + private string $image; + + /** + * The wish (product) url. + * + * @var string|null + */ + private string $url; + + /** + * The wish priority + * + * @var int|null + */ + private ?int $priority; + + /** + * The wish status. + * + * @var string|null + */ + private ?string $status; + + /** + * Whether this wish is purchasable. + * + * @var bool + */ + private bool $is_purchasable; + + /** + * A unix timestamp of when this wish was last edited. + * + * @var int + */ + private int $edited; + public string $style = 'grid'; /** Product */ @@ -96,9 +158,16 @@ class Wish if ($columns) { $this->exists = true; - foreach ($columns as $key => $value) { - $this->$key = $value; - } + $this->id = $columns['id']; + $this->wishlist = $columns['wishlist']; + $this->title = $columns['title']; + $this->description = $columns['description']; + $this->image = $columns['image']; + $this->url = $columns['url']; + $this->priority = $columns['priority']; + $this->status = $columns['status']; + $this->is_purchasable = $columns['is_purchasable']; + $this->edited = $columns['edited']; $this->info = new \stdClass(); diff --git a/src/classes/wishthis/Wishlist.php b/src/classes/wishthis/Wishlist.php index 32a667b7..f42897b8 100644 --- a/src/classes/wishthis/Wishlist.php +++ b/src/classes/wishthis/Wishlist.php @@ -10,6 +10,44 @@ namespace wishthis; class Wishlist { + /** + * The unique wishlist id. + * + * @var int + */ + private int $id; + + /** + * The user id this wishlist belongs to. + * + * TODO: rename this to user_id (the database column too). + * + * @var int + */ + private int $user; + + /** + * The wishlist name. + * + * @var string + */ + private string $name; + + /** + * The unique wishlist hash. + * + * @var string + */ + private string $hash; + + /** + * A unix timestamp of when the last notification was sent to the wishlist + * owner. + * + * @var int + */ + private int $notification_send; + public array $wishes = array(); public bool $exists = false; @@ -43,13 +81,11 @@ class Wishlist if ($columns) { $this->exists = true; - foreach ($columns as $key => $value) { - if (is_string($value)) { - $this->$key = html_entity_decode($value); - } else { - $this->$key = $value; - } - } + $this->id = $columns['id']; + $this->user = $columns['user']; + $this->name = html_entity_decode($columns['name']); + $this->hash = $columns['hash']; + $this->notification_send = $columns['notification_send']; } else { return; }