Skip to content

Commit

Permalink
Merge pull request #8039 from Sesquipedalian/cast_vs_null_coalesce
Browse files Browse the repository at this point in the history
Fixes mistakes re: typcasting vs. null coalescing operator precedence
  • Loading branch information
Sesquipedalian authored Jan 24, 2024
2 parents 655fcfe + 2da2890 commit 09aba73
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Sources/Actions/Admin/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2470,7 +2470,7 @@ protected function setGroupsContext(): void
];
}

Group::countPermissionsBatch(array_keys(Utils::$context['groups']), (int) $_REQUEST['pid'] ?? null);
Group::countPermissionsBatch(array_keys(Utils::$context['groups']), isset($_REQUEST['pid']) ? (int) $_REQUEST['pid'] : null);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Sources/Actions/Admin/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function general(): void

// Ensure all URLs are aligned with the new force_ssl setting
// Treat unset like 0
$this->alignURLsWithSSLSetting((int) $_POST['force_ssl'] ?? 0);
$this->alignURLsWithSSLSetting((int) ($_POST['force_ssl'] ?? 0));

ACP::saveSettings($config_vars);
$_SESSION['adm-save'] = true;
Expand Down
4 changes: 2 additions & 2 deletions Sources/Actions/Unread.php
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,8 @@ protected function getTopicRequestWithoutTempTable(): void
list($num_topics, $min_message) = Db::$db->fetch_row($request);
Db::$db->free_result($request);

$this->num_topics = (int) $num_topics ?? 0;
$this->min_message = (int) $min_message ?? 0;
$this->num_topics = (int) ($num_topics ?? 0);
$this->min_message = (int) ($min_message ?? 0);

if ($this->num_topics == 0) {
$this->setNoTopics();
Expand Down
4 changes: 2 additions & 2 deletions Sources/Actions/UnreadReplies.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ protected function getTopicRequestWithoutTempTable(): void
list($num_topics, $min_message) = Db::$db->fetch_row($request);
Db::$db->free_result($request);

$this->num_topics = (int) $num_topics ?? 0;
$this->min_message = (int) $min_message ?? 0;
$this->num_topics = (int) ($num_topics ?? 0);
$this->min_message = (int) ($min_message ?? 0);

if ($this->num_topics == 0) {
$this->setNoTopics();
Expand Down
4 changes: 2 additions & 2 deletions Sources/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2800,8 +2800,8 @@ protected function setAvatarAttachment(string $filepath): ?string
}

// Check whether the image is too large.
$max_width = (int) Config::$modSettings['avatar_max_width_external'] ?? 0;
$max_height = (int) Config::$modSettings['avatar_max_height_external'] ?? 0;
$max_width = (int) (Config::$modSettings['avatar_max_width_external'] ?? 0);
$max_height = (int) (Config::$modSettings['avatar_max_height_external'] ?? 0);

if ($image->shouldResize($max_width, $max_height)) {
// Try to resize it, unless the admin disabled resizing.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Subs-Compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -3225,7 +3225,7 @@ function read_tgz_file(
): array|bool {
return PackageManager\SubsPackage::read_tgz_file(
$gzfilename,
(string) $destination ?? null,
isset($destination) ? (string) $destination : null,
$single_file,
$overwrite,
$files_to_extract,
Expand Down
2 changes: 1 addition & 1 deletion Sources/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ class User implements \ArrayAccess
public function __set(string $prop, mixed $value): void
{
if (in_array($this->prop_aliases[$prop] ?? $prop, ['additional_groups', 'buddies', 'ignoreusers', 'ignoreboards']) && is_string($value)) {
$prop = (string) $this->prop_aliases[$prop] ?? $prop;
$prop = (string) ($this->prop_aliases[$prop] ?? $prop);
$value = array_map('intval', array_filter(explode(',', $value), 'strlen'));
}

Expand Down

0 comments on commit 09aba73

Please sign in to comment.