From cf9e699ec93d78f38fb4a6cf109947521a4e491a Mon Sep 17 00:00:00 2001 From: Jay Trees Date: Wed, 29 May 2024 17:08:43 +0200 Subject: [PATCH] refactor: fix code style --- src/api/statistics.php | 8 +- src/api/url.php | 4 +- src/api/wishlists-saved.php | 16 +-- src/api/wishlists.php | 60 +++++----- src/classes/wishthis/API.php | 4 +- src/classes/wishthis/Blog.php | 6 +- src/classes/wishthis/Cache/Blog.php | 2 +- src/classes/wishthis/Cache/Embed.php | 4 +- src/classes/wishthis/Cache/Query.php | 6 +- src/classes/wishthis/Database.php | 10 +- src/classes/wishthis/Email.php | 4 +- src/classes/wishthis/Options.php | 16 +-- src/classes/wishthis/Page.php | 110 +++++++++--------- src/classes/wishthis/Sanitiser.php | 6 +- src/classes/wishthis/URL.php | 12 +- src/classes/wishthis/Wish.php | 32 ++--- src/classes/wishthis/Wishlist.php | 14 +-- src/pages/blog.php | 2 +- src/pages/home.php | 4 +- src/pages/login-as.php | 4 +- src/pages/login.php | 8 +- .../profile/profile-handle-post-password.php | 4 +- .../profile/profile-handle-post-personal.php | 20 ++-- .../profile-handle-post-preferences.php | 22 ++-- src/pages/profile/profile.php | 2 +- src/pages/register.php | 30 ++--- src/pages/update.php | 6 +- src/pages/wishlists-saved.php | 2 +- tests/CreateWishTest.php | 22 ++-- tests/LogInTest.php | 4 +- tests/PrettyUrlTest.php | 8 +- 31 files changed, 227 insertions(+), 225 deletions(-) diff --git a/src/api/statistics.php b/src/api/statistics.php index e616794d..881e35ec 100644 --- a/src/api/statistics.php +++ b/src/api/statistics.php @@ -21,20 +21,20 @@ switch ($_SERVER['REQUEST_METHOD']) { case 'GET': if (isset($_GET['table'])) { if ('all' === $_GET['table']) { - $tables = array( + $tables = [ 'wishes', 'wishlists', 'users', - ); + ]; - $response['data'] = array(); + $response['data'] = []; foreach ($tables as $table) { /** Get count */ $countQuery = new Cache\Query( 'SELECT COUNT(`id`) AS "count" FROM `' . $table . '`;', - array(), + [], Duration::DAY ); diff --git a/src/api/url.php b/src/api/url.php index 18424610..fd04371e 100644 --- a/src/api/url.php +++ b/src/api/url.php @@ -21,11 +21,11 @@ switch ($_SERVER['REQUEST_METHOD']) { $url_old = base64_decode($_GET['url']); $url = new URL($url_old); - $response['data'] = array( + $response['data'] = [ 'url' => $url_old, 'url_pretty' => $url->getPretty(), 'url_is_pretty' => $url->isPretty(), - ); + ]; } break; } diff --git a/src/api/wishlists-saved.php b/src/api/wishlists-saved.php index 2c42b4e8..e7738379 100644 --- a/src/api/wishlists-saved.php +++ b/src/api/wishlists-saved.php @@ -41,10 +41,10 @@ switch ($_SERVER['REQUEST_METHOD']) { LEFT OUTER JOIN `wishlists` ON `wishlists`.`id` = `wishlists_saved`.`wishlist` WHERE `wishlists_saved`.`user` = :user_id AND `wishlist` = :wishlist_id;', - array( + [ 'wishlist_id' => Sanitiser::getNumber($_POST['wishlist']), - 'user_id' => $user->getId() - ) + 'user_id' => $user->getId(), + ] ) ->fetch(); @@ -54,9 +54,9 @@ switch ($_SERVER['REQUEST_METHOD']) { ->query( 'DELETE FROM `wishlists_saved` WHERE `wishlist` = :wishlist_id', - array( - 'wishlist_id' => Sanitiser::getNumber($_POST['wishlist']) - ) + [ + 'wishlist_id' => Sanitiser::getNumber($_POST['wishlist']), + ] ); $response['action'] = 'deleted'; @@ -71,10 +71,10 @@ switch ($_SERVER['REQUEST_METHOD']) { :user_id, :wishlist_id );', - array( + [ 'user_id' => $user->getId(), 'wishlist_id' => Sanitiser::getNumber($_POST['wishlist']), - ) + ] ); $response['action'] = 'created'; diff --git a/src/api/wishlists.php b/src/api/wishlists.php index 5033e865..b5b33632 100644 --- a/src/api/wishlists.php +++ b/src/api/wishlists.php @@ -32,16 +32,16 @@ switch ($_SERVER['REQUEST_METHOD']) { :wishlist_name, :wishlist_hash );', - array( + [ 'user_id' => $user_id, 'wishlist_name' => $wishlist_name, 'wishlist_hash' => $wishlist_hash, - ) + ] ); - $response['data'] = array( + $response['data'] = [ 'lastInsertId' => $database->lastInsertId(), - ); + ]; } elseif (isset($_POST['wishlist-id'])) { /** * Request more wishes @@ -55,9 +55,9 @@ switch ($_SERVER['REQUEST_METHOD']) { FROM `wishlists` WHERE `id` = :wishlist_id AND (`notification_sent` < (CURRENT_TIMESTAMP - INTERVAL 1 DAY) OR `notification_sent` IS NULL);', - array( + [ 'wishlist_id' => $wishlist_id, - ) + ] ); $wishlist = $wishlistQuery->fetch(); @@ -90,9 +90,9 @@ switch ($_SERVER['REQUEST_METHOD']) { 'UPDATE `wishlists` SET `notification_sent` = CURRENT_TIMESTAMP WHERE `id` = :wishlist_id;', - array( + [ 'wishlist_id' => $wishlist['id'], - ) + ] ); } } @@ -119,9 +119,9 @@ switch ($_SERVER['REQUEST_METHOD']) { 'SELECT `id` FROM `wishlists` WHERE `user` = :wishlist_user_id', - array( + [ 'wishlist_user_id' => $user->getId(), - ) + ] ); if (false === $wishlist || false === $userWishlistsQuery) { @@ -147,14 +147,14 @@ switch ($_SERVER['REQUEST_METHOD']) { $priorityNone = 0; $priority = (int) $_GET['priority'] ?? $priorityAll; - $options = array( + $options = [ 'style' => $_GET['style'], - 'placeholders' => array(), - ); - $where = array( + 'placeholders' => [], + ]; + $where = [ 'wishlist' => '`wishlist` = ' . $wishlist->getId(), 'priority' => '`priority` = ' . $priority, - ); + ]; if ($priorityAll === $priority) { unset($where['priority']); @@ -174,14 +174,14 @@ switch ($_SERVER['REQUEST_METHOD']) { $priorityNone = 0; $priority = (int) $_GET['priority'] ?? $priorityAll; - $options = array( + $options = [ 'style' => $_GET['style'], - 'placeholders' => array(), - ); - $where = array( + 'placeholders' => [], + ]; + $where = [ 'wishlist' => '`wishlist` = ' . $wishlist->getId(), 'priority' => '`priority` = ' . $priority, - ); + ]; if ($priorityAll === $priority) { unset($where['priority']); @@ -195,24 +195,24 @@ switch ($_SERVER['REQUEST_METHOD']) { $response['results'] = $wishlist->getCards($options); } elseif ($getOwnWishlists) { - $wishlists = array(); - $wishlistsItems = array(); + $wishlists = []; + $wishlistsItems = []; foreach ($user->getWishlists() as $wishlistData) { $wishlist = new Wishlist($wishlistData); $wishlistId = $wishlist->getId(); $wishlistName = $wishlist->getName(); - $wishlists[] = array( + $wishlists[] = [ 'id' => $wishlistId, 'hash' => $wishlist->getHash(), 'userId' => $wishlist->getUserId(), - ); - $wishlistsItems[] = array( + ]; + $wishlistsItems[] = [ 'name' => $wishlistName, 'value' => $wishlistId, 'text' => $wishlistName, - ); + ]; } $response['wishlists'] = $wishlists; @@ -236,10 +236,10 @@ switch ($_SERVER['REQUEST_METHOD']) { 'UPDATE `wishlists` SET `name` = :wishlist_name WHERE `id` = :wishlist_id', - array( + [ 'wishlist_name' => Sanitiser::getTitle($_PUT['wishlist_title']), 'wishlist_id' => Sanitiser::getNumber($_PUT['wishlist_id']), - ) + ] ); $response['success'] = true; @@ -259,9 +259,9 @@ switch ($_SERVER['REQUEST_METHOD']) { $database->query( 'DELETE FROM `wishlists` WHERE `id` = :wishlist_id;', - array( + [ 'wishlist_id' => Sanitiser::getNumber($_DELETE['wishlist_id']), - ) + ] ); $response['success'] = true; diff --git a/src/classes/wishthis/API.php b/src/classes/wishthis/API.php index 2e516493..c65c965c 100644 --- a/src/classes/wishthis/API.php +++ b/src/classes/wishthis/API.php @@ -32,9 +32,9 @@ class API if (file_exists($this->module_path)) { ob_start(); - $response = array( + $response = [ 'success' => false, - ); + ]; require $this->module_path; diff --git a/src/classes/wishthis/Blog.php b/src/classes/wishthis/Blog.php index f5587855..c2dacf91 100644 --- a/src/classes/wishthis/Blog.php +++ b/src/classes/wishthis/Blog.php @@ -52,11 +52,11 @@ class Blog $next = $psots[$i + 1] ?? null; if ($slug === $current->slug) { - return array( + return [ 'previous' => $previous, 'current' => $current, 'next' => $next, - ); + ]; } } @@ -116,7 +116,7 @@ class Blog public static function getCategoriesHTML(array $categoryIDs): string { $categoriesHTML = ''; - $categoriesName = array(); + $categoriesName = []; foreach ($categoryIDs as $categoryID) { $category = self::get(sprintf(self::ENDPOINT_CATEGORIES, $categoryID)); diff --git a/src/classes/wishthis/Cache/Blog.php b/src/classes/wishthis/Cache/Blog.php index 72ae56e5..30642e0e 100644 --- a/src/classes/wishthis/Cache/Blog.php +++ b/src/classes/wishthis/Cache/Blog.php @@ -30,7 +30,7 @@ class Blog extends Cache { $filepath = $this->getFilepath(); - $response = $this->exists() ? json_decode(file_get_contents($filepath)) : array(); + $response = $this->exists() ? json_decode(file_get_contents($filepath)) : []; if (true === $this->generateCache() || empty($response)) { $postsRemote = file_get_contents($this->url); diff --git a/src/classes/wishthis/Cache/Embed.php b/src/classes/wishthis/Cache/Embed.php index a9d16027..aae9eb28 100644 --- a/src/classes/wishthis/Cache/Embed.php +++ b/src/classes/wishthis/Cache/Embed.php @@ -74,7 +74,7 @@ class Embed extends Cache } if ($generateCache) { - $ch_options = array( + $ch_options = [ CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_FOLLOWLOCATION => true, @@ -84,7 +84,7 @@ class Embed extends Cache CURLOPT_SSL_VERIFYPEER => false, CURLOPT_TIMEOUT => 30, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0', - ); + ]; /** Favicon */ if (str_contains(pathinfo($info->favicon, PATHINFO_EXTENSION), 'ico')) { diff --git a/src/classes/wishthis/Cache/Query.php b/src/classes/wishthis/Cache/Query.php index aa1f622f..c649d6ad 100644 --- a/src/classes/wishthis/Cache/Query.php +++ b/src/classes/wishthis/Cache/Query.php @@ -12,12 +12,12 @@ class Query extends Cache * Private */ private \wishthis\Database $database; - private array $placeholders = array(); + private array $placeholders = []; /** * Public */ - public function __construct(string $url, array $placeholders = array(), int $maxAge = \wishthis\Duration::YEAR) + public function __construct(string $url, array $placeholders = [], int $maxAge = \wishthis\Duration::YEAR) { global $database; @@ -31,7 +31,7 @@ class Query extends Cache { $filepath = $this->getFilepath(); - $response = $this->exists() ? json_decode(file_get_contents($filepath), true) : array(); + $response = $this->exists() ? json_decode(file_get_contents($filepath), true) : []; if (true === $this->generateCache()) { $pdoStatement = $this->database diff --git a/src/classes/wishthis/Database.php b/src/classes/wishthis/Database.php index 68169146..b0e9108a 100644 --- a/src/classes/wishthis/Database.php +++ b/src/classes/wishthis/Database.php @@ -33,14 +33,14 @@ class Database public function connect(): void { $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database . ';port=3306;charset=utf8mb4'; - $options = array('placeholders' => array()); + $options = ['placeholders' => []]; $this->pdo = new \PDO($dsn, $this->user, $this->password, $options); } - public function query(string $query, array $placeholders = array()): \PDOStatement|false + public function query(string $query, array $placeholders = []): \PDOStatement|false { - $statement = $this->pdo->prepare($query, array(\PDO::FETCH_ASSOC)); + $statement = $this->pdo->prepare($query, [\PDO::FETCH_ASSOC]); foreach ($placeholders as $name => $value) { switch (gettype($value)) { @@ -103,10 +103,10 @@ class Database FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_NAME` = :table_name AND `COLUMN_NAME` = :column_name', - array( + [ 'table_name' => $table_to_check, 'column_name' => $column_to_check, - ) + ] ) ->fetch(); $exists = false !== $result; diff --git a/src/classes/wishthis/Email.php b/src/classes/wishthis/Email.php index 9e72696d..8589f852 100644 --- a/src/classes/wishthis/Email.php +++ b/src/classes/wishthis/Email.php @@ -56,10 +56,10 @@ class Email $to = $this->to; $subject = $this->subject; $message = $html; - $headers = array( + $headers = [ 'From' => 'no-reply@' . $_SERVER['HTTP_HOST'], 'Content-type' => 'text/html; charset=utf-8', - ); + ]; $success = mail($to, $subject, $message, $headers); diff --git a/src/classes/wishthis/Options.php b/src/classes/wishthis/Options.php index f3475eb8..c932ef06 100644 --- a/src/classes/wishthis/Options.php +++ b/src/classes/wishthis/Options.php @@ -30,9 +30,9 @@ class Options 'SELECT * FROM `options` WHERE `key` = :option_key', - array( + [ 'option_key' => Sanitiser::getOption($key), - ) + ] ) ->fetch(); @@ -51,9 +51,9 @@ class Options 'SELECT * FROM `options` WHERE `key` = :option_key;', - array( + [ 'option_key' => $key, - ) + ] ) ->rowCount(); @@ -62,10 +62,10 @@ class Options 'UPDATE `options` SET `value` = :option_value WHERE `key` = :option_key;', - array( + [ 'option_value' => $value, 'option_key' => $key, - ) + ] ); } else { $this->database->query( @@ -73,10 +73,10 @@ class Options (`key`, `value`) VALUES (:option_key, :option_value);', - array( + [ 'option_key' => $key, 'option_value' => $value, - ) + ] ); } } diff --git a/src/classes/wishthis/Page.php b/src/classes/wishthis/Page.php index f8c6fd8d..43e89409 100644 --- a/src/classes/wishthis/Page.php +++ b/src/classes/wishthis/Page.php @@ -45,8 +45,8 @@ class Page { ob_start(); - $containerClasses = array('ui', 'message', $class); - $iconClasses = array('ui', 'icon'); + $containerClasses = ['ui', 'message', $class]; + $iconClasses = ['ui', 'icon']; switch ($type) { case 'error': @@ -120,12 +120,12 @@ class Page */ private string $name; public string $language = DEFAULT_LOCALE; - public array $messages = array(); + public array $messages = []; public string $link_preview; public string $description; - public array $stylesheets = array(); - public array $scripts = array(); + public array $stylesheets = []; + public array $scripts = []; /** * __construct @@ -185,12 +185,12 @@ class Page /** * Update */ - $ignoreUpdateRedirect = array( + $ignoreUpdateRedirect = [ 'maintenance', 'login', 'logout', 'update', - ); + ]; if ($options && $options->getOption('updateAvailable') && !in_array($this->name, $ignoreUpdateRedirect)) { if (100 === $user->getPower()) { @@ -251,20 +251,20 @@ class Page /** * Stylesheets */ - $this->stylesheets = array( + $this->stylesheets = [ 'fomantic-ui' => 'semantic/dist/semantic.min.css', 'default' => 'src/assets/css/default.css', 'dark' => 'src/assets/css/default/dark.css', - ); + ]; /** * Scripts */ - $this->scripts = array( + $this->scripts = [ 'j-query' => 'node_modules/jquery/dist/jquery.min.js', 'fomantic-ui' => 'semantic/dist/semantic.min.js', 'default' => 'src/assets/js/default.js', - ); + ]; /** html2canvas */ $CrawlerDetect = new \Jaybizzle\CrawlerDetect\CrawlerDetect(); @@ -398,12 +398,12 @@ class Page } /** AdSense */ - $wishthis_hosts = array( + $wishthis_hosts = [ 'wishthis.localhost', 'wishthis.online', 'rc.wishthis.online', 'dev.wishthis.online', - ); + ]; $CrawlerDetect = new \Jaybizzle\CrawlerDetect\CrawlerDetect(); if ( @@ -443,100 +443,100 @@ class Page $login = Navigation::Login->value; $register = Navigation::Register->value; - $pages = array( - $blog => array( + $pages = [ + $blog => [ 'text' => __('Blog'), 'alignment' => 'left', - 'items' => array( - array( + 'items' => [ + [ 'text' => __('Blog'), 'url' => self::PAGE_BLOG, 'icon' => 'rss', - ), - ), - ), - $system => array( + ], + ], + ], + $system => [ 'text' => __('System'), 'icon' => 'wrench', 'alignment' => 'right', - 'items' => array(), - ), - $account => array( + 'items' => [], + ], + $account => [ 'text' => __('Account'), 'icon' => 'user circle', 'alignment' => 'right', - 'items' => array(), - ), - ); + 'items' => [], + ], + ]; if ($user->isLoggedIn()) { - $pages[$wishlists] = array( + $pages[$wishlists] = [ 'text' => __('Wishlists'), 'alignment' => 'left', - 'items' => array( - array( + 'items' => [ + [ 'text' => __('My lists'), 'url' => Page::PAGE_WISHLISTS, 'icon' => 'list', - ), - array( + ], + [ 'text' => __('Remembered lists'), 'url' => Page::PAGE_WISHLISTS_SAVED, 'icon' => 'heart', - ), - ), - ); + ], + ], + ]; } if ($user->isLoggedIn()) { - $pages[$account]['items'][] = array( + $pages[$account]['items'][] = [ 'text' => __('Profile'), 'url' => Page::PAGE_PROFILE, 'icon' => 'user circle alternate', - ); + ]; if (100 === $user->getPower()) { - $pages[$account]['items'][] = array( + $pages[$account]['items'][] = [ 'text' => __('Login as'), 'url' => Page::PAGE_LOGIN_AS, 'icon' => 'sign out alternate', - ); + ]; } - $pages[$account]['items'][] = array( + $pages[$account]['items'][] = [ 'text' => __('Logout'), 'url' => Page::PAGE_LOGOUT, 'icon' => 'sign out alternate', - ); + ]; } else { - $pages[$login] = array( + $pages[$login] = [ 'text' => __('Login'), 'alignment' => 'right', - 'items' => array( - array( + 'items' => [ + [ 'text' => __('Login'), 'url' => Page::PAGE_LOGIN, 'icon' => 'sign in alternate', - ), - ), - ); - $pages[$register] = array( + ], + ], + ]; + $pages[$register] = [ 'text' => __('Register'), 'alignment' => 'right', - 'items' => array( - array( + 'items' => [ + [ 'text' => __('Register'), 'url' => Page::PAGE_REGISTER, 'icon' => 'user plus alternate', - ), - ), - ); + ], + ], + ]; } if (100 === $user->getPower()) { - $pages[$system]['items'][] = array( + $pages[$system]['items'][] = [ 'text' => __('Settings'), 'url' => Page::PAGE_SETTINGS, 'icon' => 'cog', - ); + ]; } ksort($pages); diff --git a/src/classes/wishthis/Sanitiser.php b/src/classes/wishthis/Sanitiser.php index 4740cb3b..05340a88 100644 --- a/src/classes/wishthis/Sanitiser.php +++ b/src/classes/wishthis/Sanitiser.php @@ -115,7 +115,8 @@ class Sanitiser * * @return string */ - public static function sanitiseText(string $text): string { + public static function sanitiseText(string $text): string + { $sanitisedText = \trim(\addslashes(\filter_var($text, \FILTER_SANITIZE_SPECIAL_CHARS))); return $sanitisedText; @@ -128,7 +129,8 @@ class Sanitiser * * @return string */ - public static function sanitiseEmail(string $email): string { + public static function sanitiseEmail(string $email): string + { $sanitisedEmail = \trim(\addslashes(\filter_var($email, \FILTER_SANITIZE_EMAIL))); return $sanitisedEmail; diff --git a/src/classes/wishthis/URL.php b/src/classes/wishthis/URL.php index 7a058569..a4de6e65 100644 --- a/src/classes/wishthis/URL.php +++ b/src/classes/wishthis/URL.php @@ -19,7 +19,7 @@ class URL */ public static function getResponseCode(string $url): int { - $ch_options = array( + $ch_options = [ CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_FOLLOWLOCATION => true, @@ -29,7 +29,7 @@ class URL CURLOPT_SSL_VERIFYPEER => false, CURLOPT_TIMEOUT => 30, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0', - ); + ]; $ch = curl_init($url); curl_setopt_array($ch, $ch_options); @@ -159,7 +159,7 @@ class URL }, explode('&', parse_url($target, PHP_URL_QUERY)) ); - $flags = explode(',', substr($parts[3], 1, -1)) ?? array(); + $flags = explode(',', substr($parts[3], 1, -1)) ?? []; \parse_str(\parse_url($target, PHP_URL_QUERY), $parameters); /** */ @@ -185,7 +185,7 @@ class URL } $match = preg_match( - '/^' . str_replace(array('/'), array('\/'), $rewriteRule) . '$/', + '/^' . str_replace(['/'], ['\/'], $rewriteRule) . '$/', $potential_url ); @@ -212,14 +212,14 @@ class URL public function getGET(): array { $queryString = $this->url; - $GET = array(); + $GET = []; if ($this->isPretty()) { $queryString = parse_url($this->getPermalink(), PHP_URL_QUERY); } if (null === $queryString) { - return array(); + return []; } if ('/?' === substr($queryString, 0, 2)) { diff --git a/src/classes/wishthis/Wish.php b/src/classes/wishthis/Wish.php index 3a284328..f64c2158 100644 --- a/src/classes/wishthis/Wish.php +++ b/src/classes/wishthis/Wish.php @@ -26,26 +26,26 @@ class Wish public const STATUS_FULFILLED = 'fulfilled'; public static array $priorities; - public static array $affiliates = array( + public static array $affiliates = [ 'amazon.de' => 'grandel0b-21', - ); + ]; public static function initialize() { - self::$priorities = array( - '1' => array( + self::$priorities = [ + '1' => [ 'name' => __('Unsure about it'), 'color' => 'teal', - ), - '2' => array( + ], + '2' => [ 'name' => __('Nice to have'), 'color' => 'olive', - ), - '3' => array( + ], + '3' => [ 'name' => __('Would love it'), 'color' => 'yellow', - ), - ); + ], + ]; } public static function getFromId(int $wishId): self|false @@ -57,9 +57,9 @@ class Wish FROM `wishes` LEFT JOIN `products` ON `wishes`.`id` = `products`.`wish` WHERE `wishes`.`id` = :wish_id', - array( + [ 'wish_id' => $wishId, - ) + ] ); if (false === $wishQuery) { @@ -79,7 +79,7 @@ class Wish if (isset($urlParts['query'])) { \parse_str($urlParts['query'], $urlParameters); } else { - $urlParameters = array(); + $urlParameters = []; } foreach (self::$affiliates as $host => $tagId) { @@ -102,7 +102,7 @@ class Wish if (isset($urlParts['query'])) { \parse_str($urlParts['query'], $urlParameters); } else { - $urlParameters = array(); + $urlParameters = []; } foreach (self::$affiliates as $host => $tagId) { @@ -439,7 +439,7 @@ class Wish public function serialise(): array { - $wishArray = array( + $wishArray = [ 'id' => $this->id, 'wishlist' => $this->wishlist, 'title' => $this->title, @@ -451,7 +451,7 @@ class Wish 'is_purchasable' => $this->is_purchasable, 'edited' => $this->edited, 'price' => $this->price, - ); + ]; return $wishArray; } diff --git a/src/classes/wishthis/Wishlist.php b/src/classes/wishthis/Wishlist.php index dde4aa18..f8da19fe 100644 --- a/src/classes/wishthis/Wishlist.php +++ b/src/classes/wishthis/Wishlist.php @@ -18,9 +18,9 @@ class Wishlist 'SELECT * FROM `wishlists` WHERE `wishlists`.`id` = :wishlist_id', - array( + [ 'wishlist_id' => $id, - ) + ] ); if (false === $wishlistQuery) { @@ -46,9 +46,9 @@ class Wishlist 'SELECT * FROM `wishlists` WHERE `wishlists`.`hash` = :wishlist_hash', - array( + [ 'wishlist_hash' => $hash, - ) + ] ); $wishlistData = $wishlistQuery->fetch(); @@ -100,7 +100,7 @@ class Wishlist */ private int $notification_sent; - public array $wishes = array(); + public array $wishes = []; public bool $exists = false; @@ -113,7 +113,7 @@ class Wishlist $this->notification_sent = $wishlist_data['notification_sent'] ? \strtotime($wishlist_data['notification_sent']) : 0; } - public function getWishes(array $options = array('placeholders' => array())): array + public function getWishes(array $options = ['placeholders' => []]): array { global $database; @@ -173,7 +173,7 @@ class Wishlist return $this->wishes; } - public function getCards(array $options = array('placeholders' => array())): string + public function getCards(array $options = ['placeholders' => []]): string { ob_start(); diff --git a/src/pages/blog.php b/src/pages/blog.php index e299cf20..1be5b783 100644 --- a/src/pages/blog.php +++ b/src/pages/blog.php @@ -14,7 +14,7 @@ $page->bodyStart(); $page->navigation(); $posts = Blog::getPosts(); -$user = User::getCurrent(); +$user = User::getCurrent(); if ('en' !== \Locale::getPrimaryLanguage($user->getLocale())) { $page->messages[] = Page::warning( diff --git a/src/pages/home.php b/src/pages/home.php index 23b0c1d4..fc791e40 100644 --- a/src/pages/home.php +++ b/src/pages/home.php @@ -48,9 +48,9 @@ $user = User::getCurrent(); WHERE `users`.`id` = :user_id ORDER BY `wishes`.`edited` DESC LIMIT 1;', - array( + [ 'user_id' => $user->getId(), - ) + ] ); if (false !== $lastWishlistQuery && 1 === $lastWishlistQuery->rowCount()) { diff --git a/src/pages/login-as.php b/src/pages/login-as.php index bcf97a02..bebca2fe 100644 --- a/src/pages/login-as.php +++ b/src/pages/login-as.php @@ -19,9 +19,9 @@ if (isset($_POST['email'])) { 'SELECT * FROM `users` WHERE `email` = :user_email;', - array( + [ 'user_email' => $email, - ) + ] ); $success = false !== $userQuery; diff --git a/src/pages/login.php b/src/pages/login.php index 6040bcc7..714b9c81 100644 --- a/src/pages/login.php +++ b/src/pages/login.php @@ -46,9 +46,9 @@ if (isset($_POST['reset'], $_POST['email'])) { 'SELECT * FROM `users` WHERE `email` = :user_email;', - array( + [ 'user_email' => Sanitiser::getEmail($_POST['email']), - ) + ] ); $user = false !== $userQuery ? new User($userQuery->fetch()) : new User(); @@ -62,10 +62,10 @@ if (isset($_POST['reset'], $_POST['email'])) { SET `password_reset_token` = :user_password_reset_token, `password_reset_valid_until` = :user_reset_valid_until WHERE `id` = ' . $user->getId() . ';', - array( + [ 'user_password_reset_token' => $token, 'user_reset_valid_until' => date('Y-m-d H:i:s', $validUntil), - ) + ] ); $emailReset = new Email($_POST['email'], __('Password reset link', null, $user), 'default', 'password-reset'); diff --git a/src/pages/profile/profile-handle-post-password.php b/src/pages/profile/profile-handle-post-password.php index cb159379..540e8690 100644 --- a/src/pages/profile/profile-handle-post-password.php +++ b/src/pages/profile/profile-handle-post-password.php @@ -19,10 +19,10 @@ if ( 'UPDATE `users` SET `password` = :password WHERE `id` = :user_id', - array( + [ 'password' => $password, 'user_id' => $userId, - ) + ] ); $loginRequired = true; diff --git a/src/pages/profile/profile-handle-post-personal.php b/src/pages/profile/profile-handle-post-personal.php index 6681393a..4b9df837 100644 --- a/src/pages/profile/profile-handle-post-personal.php +++ b/src/pages/profile/profile-handle-post-personal.php @@ -17,10 +17,10 @@ if (isset($_POST['user-name-first'])) { 'UPDATE `users` SET `name_first` = :name_first WHERE `id` = :user_id', - array( + [ 'name_first' => $nameFirst, 'user_id' => $userId, - ) + ] ); $user->setNameFirst($nameFirst); @@ -47,10 +47,10 @@ if (isset($_POST['user-name-last'])) { 'UPDATE `users` SET `name_last` = :name_last WHERE `id` = :user_id', - array( + [ 'name_last' => $nameLast, 'user_id' => $userId, - ) + ] ); $user->setNameLast($nameLast); @@ -77,10 +77,10 @@ if (isset($_POST['user-name-nick'])) { 'UPDATE `users` SET `name_nick` = :name_nick WHERE `id` = :user_id', - array( + [ 'name_nick' => $nameNick, 'user_id' => $userId, - ) + ] ); $user->setNameNick($nameNick); @@ -107,10 +107,10 @@ if (isset($_POST['user-email'])) { 'UPDATE `users` SET `email` = :email WHERE `id` = :user_id', - array( + [ 'email' => $email, 'user_id' => $userId, - ) + ] ); $user->setEmail($email); @@ -140,10 +140,10 @@ if (isset($_POST['user-birthdate'])) { 'UPDATE `users` SET `birthdate` = :birthdate WHERE `id` = :user_id', - array( + [ 'birthdate' => $birthdate, 'user_id' => $userId, - ) + ] ); $user->setBirthdate($birthdate); diff --git a/src/pages/profile/profile-handle-post-preferences.php b/src/pages/profile/profile-handle-post-preferences.php index 073e8180..88bfc4e1 100644 --- a/src/pages/profile/profile-handle-post-preferences.php +++ b/src/pages/profile/profile-handle-post-preferences.php @@ -24,10 +24,10 @@ if (isset($_POST['user-language'])) { 'UPDATE `users` SET `language` = :language WHERE `id` = :user_id', - array( + [ 'language' => $userLocale, 'user_id' => $userId, - ) + ] ); $user->setLocale($userLocale); @@ -61,10 +61,10 @@ if (isset($_POST['user-currency'])) { 'UPDATE `users` SET `currency` = :currency WHERE `id` = :user_id', - array( + [ 'currency' => $userCurrency, 'user_id' => $userId, - ) + ] ); $user->setCurrency($userCurrency); @@ -92,17 +92,17 @@ if (isset($_POST['user-channel'])) { }, CHANNELS ) - : array(); + : []; if (\in_array($userChannel, $channels, true) && $userChannel !== $user->getChannel()) { $database->query( 'UPDATE `users` SET `channel` = :channel WHERE `id` = :user_id', - array( + [ 'channel' => $userChannel, 'user_id' => $userId, - ) + ] ); $user->setChannel($userChannel); @@ -122,10 +122,10 @@ if (isset($_POST['user-channel'])) { 'UPDATE `users` SET `channel` = :channel WHERE `id` = :user_id', - array( + [ 'channel' => null, 'user_id' => $userId, - ) + ] ); $user->setChannel($userChannel); @@ -147,10 +147,10 @@ if ($userAdvertisements !== $user->getAdvertisements()) { 'UPDATE `users` SET `advertisements` = :advertisements WHERE `id` = :user_id', - array( + [ 'advertisements' => $userAdvertisements, 'user_id' => $userId, - ) + ] ); $user->setAdvertisements($userAdvertisements); diff --git a/src/pages/profile/profile.php b/src/pages/profile/profile.php index 5315e451..fe3669dd 100644 --- a/src/pages/profile/profile.php +++ b/src/pages/profile/profile.php @@ -205,7 +205,7 @@ $page->navigation();