Replace use of 'array_merge' with the spread operator and 'array_push' in various places.

This isn't supported for arrays with string keys until PHP 8.1.

https://wiki.php.net/rfc/spread_operator_for_array
This commit is contained in:
wn_
2022-08-12 15:31:19 +00:00
parent a63c949a55
commit 3487c922b3
17 changed files with 71 additions and 72 deletions

View File

@@ -1938,8 +1938,8 @@ class Feeds extends Handler_Protected {
$sth->execute([$cat, $owner_uid]);
while ($line = $sth->fetch()) {
array_push($rv, (int)$line["parent_cat"]);
$rv = array_merge($rv, self::_get_parent_cats($line["parent_cat"], $owner_uid));
$cat = (int) $line["parent_cat"];
array_push($rv, $cat, ...self::_get_parent_cats($cat, $owner_uid));
}
return $rv;
@@ -1958,8 +1958,7 @@ class Feeds extends Handler_Protected {
$sth->execute([$cat, $owner_uid]);
while ($line = $sth->fetch()) {
array_push($rv, $line["id"]);
$rv = array_merge($rv, self::_get_child_cats($line["id"], $owner_uid));
array_push($rv, $line["id"], ...self::_get_child_cats($line["id"], $owner_uid));
}
return $rv;
@@ -1980,16 +1979,18 @@ class Feeds extends Handler_Protected {
$sth = $pdo->prepare("SELECT DISTINCT cat_id, fc.parent_cat FROM ttrss_feeds f LEFT JOIN ttrss_feed_categories fc
ON (fc.id = f.cat_id)
WHERE f.owner_uid = ? AND f.id IN ($feeds_qmarks)");
$sth->execute(array_merge([$owner_uid], $feeds));
$sth->execute([$owner_uid, ...$feeds]);
$rv = [];
if ($row = $sth->fetch()) {
$cat_id = (int) $row["cat_id"];
$rv[] = $cat_id;
array_push($rv, (int)$row["cat_id"]);
if ($with_parents && $row["parent_cat"])
$rv = array_merge($rv,
self::_get_parent_cats($row["cat_id"], $owner_uid));
if ($with_parents && $row["parent_cat"]) {
array_push($rv, ...self::_get_parent_cats($cat_id, $owner_uid));
}
}
$rv = array_unique($rv);