refactor: fix code style

This commit is contained in:
Jay Trees 2024-05-29 17:08:43 +02:00
parent 262608544f
commit cf9e699ec9
31 changed files with 227 additions and 225 deletions

View file

@ -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
);

View file

@ -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;
}

View file

@ -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';

View file

@ -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;

View file

@ -32,9 +32,9 @@ class API
if (file_exists($this->module_path)) {
ob_start();
$response = array(
$response = [
'success' => false,
);
];
require $this->module_path;

View file

@ -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));

View file

@ -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);

View file

@ -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')) {

View file

@ -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

View file

@ -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;

View file

@ -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);

View file

@ -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,
)
]
);
}
}

View file

@ -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);

View file

@ -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;

View file

@ -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)) {

View file

@ -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;
}

View file

@ -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();

View file

@ -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()) {

View file

@ -19,9 +19,9 @@ if (isset($_POST['email'])) {
'SELECT *
FROM `users`
WHERE `email` = :user_email;',
array(
[
'user_email' => $email,
)
]
);
$success = false !== $userQuery;

View file

@ -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');

View file

@ -19,10 +19,10 @@ if (
'UPDATE `users`
SET `password` = :password
WHERE `id` = :user_id',
array(
[
'password' => $password,
'user_id' => $userId,
)
]
);
$loginRequired = true;

View file

@ -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);

View file

@ -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);

View file

@ -205,7 +205,7 @@ $page->navigation();
<select class="ui search dropdown currency" name="user-currency">
<?php
$currencies = array();
$currencies = [];
?>
<?php foreach ($locales as $locale) { ?>

View file

@ -33,7 +33,7 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
$isHuman = false;
$planet = strtolower(Sanitiser::getTitle($_POST['planet']));
$planetName = strtoupper($planet[0]) . substr($planet, 1);
$planets = array(
$planets = [
strtolower(__('Mercury')),
strtolower(__('Venus')),
strtolower(__('Earth')),
@ -42,11 +42,11 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
strtolower(__('Saturn')),
strtolower(__('Uranus')),
strtolower(__('Neptune')),
);
$not_planets = array(
];
$not_planets = [
strtolower(__('Pluto')),
strtolower(__('Sun')),
);
];
if (in_array($planet, array_merge($planets, $not_planets))) {
$isHuman = true;
@ -75,10 +75,10 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
FROM `users`
WHERE `email` = :user_email
AND `password_reset_token` = :user_password_reset_token',
array(
[
'user_email' => $user_email,
'user_password_reset_token' => $user_token,
)
]
);
if (false !== $userQuery) {
@ -91,10 +91,10 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
'UPDATE `users`
SET `password` = :user_password
WHERE `id` = :user_id;',
array(
[
'user_password' => User::passwordToHash($_POST['password']),
'user_id' => $user->getId(),
)
]
);
$page->messages[] = Page::success(
@ -115,7 +115,7 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
$locale_user = $locale_browser;
}
if(defined('DISABLE_USER_REGISTRATION') && true === DISABLE_USER_REGISTRATION) {
if (defined('DISABLE_USER_REGISTRATION') && true === DISABLE_USER_REGISTRATION) {
\http_response_code(403);
die(__('The owner of this site has disabled user registrations.'));
@ -140,11 +140,11 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
100,
:user_language
);',
array(
[
'user_email' => $user_email,
'user_password' => User::passwordToHash($_POST['password']),
'user_language' => $locale_user,
)
]
);
$userRegistered = true;
} else {
@ -164,11 +164,11 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
:user_password,
:user_language
);',
array(
[
'user_email' => $user_email,
'user_password' => User::passwordToHash($_POST['password']),
'user_language' => $locale_user,
)
]
);
$userRegistered = true;
@ -196,11 +196,11 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
:wishlist_name,
:wishlist_hash
);',
array(
[
'wishlist_user_id' => $user_id,
'wishlist_name' => $wishlist_name,
'wishlist_hash' => $wishlist_hash,
)
]
);
}
} else {

View file

@ -16,17 +16,17 @@ $page = new Page(__FILE__, __('Update'), 100);
if ('POST' === $_SERVER['REQUEST_METHOD']) {
$versions_directory = ROOT . '/src/update';
$versions_contents = scandir($versions_directory);
$versions = array();
$versions = [];
foreach ($versions_contents as $filename) {
$filepath = $versions_directory . '/' . $filename;
$pathinfo = pathinfo($filepath);
if ('sql' === $pathinfo['extension']) {
$versions[] = array(
$versions[] = [
'version' => str_replace('-', '.', $pathinfo['filename']),
'filepath' => $filepath,
);
];
}
}

View file

@ -16,7 +16,7 @@ $page->navigation();
$user = User::getCurrent();
$wishlists = $user->getSavedWishlists();
$wishlists_by_user = array();
$wishlists_by_user = [];
foreach ($wishlists as $wishlist_saved) {
if (!isset($wishlist_saved['user'])) {

View file

@ -10,7 +10,7 @@ final class CreateWishTest extends TestCase
{
private int $testWishlistId = 5;
private function apiRequest(string $endpoint, int $method, array $data = array()): string|false
private function apiRequest(string $endpoint, int $method, array $data = []): string|false
{
$queryString = http_build_query($data);
@ -32,10 +32,10 @@ final class CreateWishTest extends TestCase
$apiResponse = $this->apiRequest(
'http://wishthis.online.localhost/api/wishes',
\CURLOPT_POST,
array(
[
'wish_title' => 'WD Red SA500 NAS SATA SSD 2TB 2.5": Amazon.de: Computer & Accessories',
'wishlist_id' => $this->testWishlistId,
)
]
);
$this->assertNotFalse($apiResponse);
@ -50,10 +50,10 @@ final class CreateWishTest extends TestCase
$apiResponse = $this->apiRequest(
'http://wishthis.online.localhost/api/wishes',
\CURLOPT_POST,
array(
[
'wish_title' => '0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789',
'wishlist_id' => $this->testWishlistId,
)
]
);
$this->assertNotFalse($apiResponse);
@ -93,10 +93,10 @@ final class CreateWishTest extends TestCase
$apiResponse = $this->apiRequest(
'http://wishthis.online.localhost/api/wishes',
\CURLOPT_POST,
array(
[
'wish_description' => 'WD Red SA500 NAS SATA SSD 2TB 2.5": Amazon.de: Computer & Accessories',
'wishlist_id' => $this->testWishlistId,
)
]
);
$this->assertNotFalse($apiResponse);
@ -111,10 +111,10 @@ final class CreateWishTest extends TestCase
$apiResponse = $this->apiRequest(
'http://wishthis.online.localhost/api/wishes',
\CURLOPT_POST,
array(
[
'wish_url' => 'https://www.amazon.com/Red-SA500-NAS-NAND-Internal/dp/B07YFGG261',
'wishlist_id' => $this->testWishlistId,
)
]
);
$this->assertNotFalse($apiResponse);
@ -129,10 +129,10 @@ final class CreateWishTest extends TestCase
$apiResponse = $this->apiRequest(
'http://wishthis.online.localhost/api/wishes',
\CURLOPT_POST,
array(
[
'wish_url' => 'https://www.amazon.com/Red-SA500-NAS-NAND-Internal/dp/B07YFGG261?012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789',
'wishlist_id' => $this->testWishlistId,
)
]
);
$this->assertNotFalse($apiResponse);

View file

@ -36,10 +36,10 @@ final class LogInTest extends TestCase
'REPLACE INTO `users`
(`email`, `password`) VALUES
(:userEmail, :userPassword)',
array(
[
'userEmail' => $userEmail,
'userPassword' => $userPassword,
)
]
);
$userLoginSuccessful = $user->logIn($userEmail, $userPassword);

View file

@ -13,20 +13,20 @@ final class PrettyUrlTest extends TestCase
{
\define('ROOT', \dirname(__DIR__));
$requestUris = array(
$requestUris = [
'//api/database-test',
'/api/database-test',
'api/database-test',
'http://wishthis.online.localhost/index.php/api/database-test',
'http://wishthis.online.localhost/index.php//api/database-test',
);
];
require __DIR__ . '/../src/classes/wishthis/URL.php';
$expected_GET = array(
$expected_GET = [
'page' => 'api',
'module' => 'database-test',
);
];
foreach ($requestUris as $requestUri) {
$url = new URL($requestUri);