Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] useless array access #41644

Merged
merged 9 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public function fetchAssociations()
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_categories/tables');
$categoryTable = Table::getInstance('Category', '\\Joomla\\CMS\\Table\\');

foreach ($associations as $lang => $association) {
foreach ($associations as $association) {
$categoryTable->load($association->id);
$associations[$lang]->title = $categoryTable->title;
$association->title = $categoryTable->title;
}

$countContentLanguages = \count(LanguageHelper::getContentLanguages([0, 1], false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public function fetchAssociations()
// Add the title to each of the associated records
$contactTable = $this->factory->createTable('Contact', 'Administrator');

foreach ($associations as $lang => $association) {
foreach ($associations as $association) {
$contactTable->load($association->id);
$associations[$lang]->title = $contactTable->name;
$association->title = $contactTable->name;
}

$countContentLanguages = count(LanguageHelper::getContentLanguages([0, 1], false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public function fetchAssociations()
// Add the title to each of the associated records
$contentTable = Table::getInstance('Content', '\\Joomla\\CMS\\Table\\');

foreach ($associations as $lang => $association) {
foreach ($associations as $association) {
$contentTable->load($association->id);
$associations[$lang]->title = $contentTable->title;
$association->title = $contentTable->title;
}

$countContentLanguages = count(LanguageHelper::getContentLanguages([0, 1], false));
Expand Down
4 changes: 2 additions & 2 deletions administrator/components/com_finder/src/Indexer/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public function getIncludedTermIds()

// Sanitize the terms.
foreach ($results as $key => $value) {
$results[$key] = array_unique($results[$key]);
$results[$key] = array_unique($value);
$results[$key] = ArrayHelper::toInteger($results[$key]);
}

Expand Down Expand Up @@ -476,7 +476,7 @@ public function getRequiredTermIds()

// Sanitize the terms.
foreach ($results as $key => $value) {
$results[$key] = array_unique($results[$key]);
$results[$key] = array_unique($value);
$results[$key] = ArrayHelper::toInteger($results[$key]);
}

Expand Down
18 changes: 9 additions & 9 deletions administrator/components/com_finder/src/Service/HTML/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ public function slider($options = [])
// Translate node titles if possible.
$lang = Factory::getLanguage();

foreach ($nodes as $nk => $nv) {
foreach ($nodes as $nv) {
if (trim($nv->parent_title, '*') === 'Language') {
$title = LanguageHelper::branchLanguageTitle($nv->title);
} else {
$key = LanguageHelper::branchPlural($nv->title);
$title = $lang->hasKey($key) ? Text::_($key) : $nv->title;
}

$nodes[$nk]->title = $title;
$nv->title = $title;
}

// Adding slides
Expand Down Expand Up @@ -320,15 +320,15 @@ public function select($idxQuery, $options)
$db->setQuery($query);

try {
$branches[$bk]->nodes = $db->loadObjectList('id');
$bv->nodes = $db->loadObjectList('id');
} catch (\RuntimeException $e) {
return null;
}

// Translate branch nodes if possible.
$language = Factory::getLanguage();

foreach ($branches[$bk]->nodes as $node_id => $node) {
foreach ($bv->nodes as $node_id => $node) {
if (trim($node->parent_title, '*') === 'Language') {
$title = LanguageHelper::branchLanguageTitle($node->title);
} else {
Expand All @@ -337,14 +337,14 @@ public function select($idxQuery, $options)
}

if ($node->level > 2) {
$branches[$bk]->nodes[$node_id]->title = str_repeat('-', $node->level - 2) . $title;
$bv->nodes[$node_id]->title = str_repeat('-', $node->level - 2) . $title;
} else {
$branches[$bk]->nodes[$node_id]->title = $title;
$bv->nodes[$node_id]->title = $title;
}
}

// Add the Search All option to the branch.
array_unshift($branches[$bk]->nodes, ['id' => null, 'title' => Text::_('COM_FINDER_FILTER_SELECT_ALL_LABEL')]);
array_unshift($bv->nodes, ['id' => null, 'title' => Text::_('COM_FINDER_FILTER_SELECT_ALL_LABEL')]);
}

// Store the data in cache.
Expand All @@ -361,7 +361,7 @@ public function select($idxQuery, $options)
$html .= '<div class="filter-branch' . $classSuffix . '">';

// Iterate through all branches and build code.
foreach ($branches as $bk => $bv) {
foreach ($branches as $bv) {
// If the multi-lang plugin is enabled then drop the language branch.
if ($bv->title === 'Language' && Multilanguage::isEnabled()) {
continue;
Expand Down Expand Up @@ -389,7 +389,7 @@ public function select($idxQuery, $options)
$html .= '<div class="controls">';
$html .= HTMLHelper::_(
'select.genericlist',
$branches[$bk]->nodes,
$bv->nodes,
't[]',
'class="form-select advancedSelect"',
'id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public function fetchAssociations()
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/tables');
$menuTable = Table::getInstance('Menu', '\\Joomla\\CMS\\Table\\', []);

foreach ($associations as $lang => $association) {
foreach ($associations as $association) {
$menuTable->load($association->id);
$associations[$lang]->title = $menuTable->title;
$association->title = $menuTable->title;
}

$countContentLanguages = count(LanguageHelper::getContentLanguages([0, 1], false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ public static function getModules($clientId)
$modules = $db->loadObjectList();
$lang = Factory::getLanguage();

foreach ($modules as $i => $module) {
foreach ($modules as $module) {
$extension = $module->value;
$path = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE;
$source = $path . "/modules/$extension";
$lang->load("$extension.sys", $path)
|| $lang->load("$extension.sys", $source);
$modules[$i]->text = Text::_($module->text);
$module->text = Text::_($module->text);
}

$modules = ArrayHelper::sortObjects($modules, 'text', 1, true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public function fetchAssociations()
// Add the title to each of the associated records
$newsfeedsTable = $this->factory->createTable('Newsfeed', 'Administrator');

foreach ($associations as $lang => $association) {
foreach ($associations as $association) {
$newsfeedsTable->load($association->id);
$associations[$lang]->title = $newsfeedsTable->name;
$association->title = $newsfeedsTable->name;
}

$countContentLanguages = count(LanguageHelper::getContentLanguages([0, 1], false));
Expand Down
10 changes: 5 additions & 5 deletions administrator/modules/mod_logged/src/Helper/LoggedHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ public static function getList(Registry $params, CMSApplication $app, DatabaseIn
throw $e;
}

foreach ($results as $k => $result) {
$results[$k]->logoutLink = '';
foreach ($results as $result) {
$result->logoutLink = '';

if ($user->authorise('core.manage', 'com_users')) {
$results[$k]->editLink = Route::_('index.php?option=com_users&task=user.edit&id=' . $result->id);
$results[$k]->logoutLink = Route::_(
$result->editLink = Route::_('index.php?option=com_users&task=user.edit&id=' . $result->id);
$result->logoutLink = Route::_(
'index.php?option=com_login&task=logout&uid=' . $result->id . '&' . Session::getFormToken() . '=1'
);
}

if ($params->get('name', 1) == 0) {
$results[$k]->name = $results[$k]->username;
$result->name = $result->username;
}
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public function __construct($options)

// Overwrite default options with given options
foreach ($options as $option => $value) {
if (isset($options[$option]) && $options[$option] !== '') {
$this->_options[$option] = $options[$option];
if ($value !== null && $value !== '') {
$this->_options[$option] = $value;
}
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Cache/CacheController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function __construct($options)

// Overwrite default options with given options
foreach ($options as $option => $value) {
if (isset($options[$option])) {
$this->options[$option] = $options[$option];
if ($value !== null) {
$this->options[$option] = $value;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Form/Field/AliastagField.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ protected function getOptions()

$lang = Factory::getLanguage();

foreach ($options as $i => $item) {
foreach ($options as $item) {
$parts = explode('.', $item->value);
$extension = $parts[0];
$lang->load($extension . '.sys', JPATH_ADMINISTRATOR)
|| $lang->load($extension, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $extension));
$options[$i]->text = Text::_(strtoupper($extension) . '_TAGS_' . strtoupper($parts[1]));
$item->text = Text::_(strtoupper($extension) . '_TAGS_' . strtoupper($parts[1]));
}

// Merge any additional options in the XML definition.
Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Language/LanguageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public static function getInstalledLanguages(
continue;
}

$languages[$cId] = ArrayHelper::sortObjects($languages[$cId], $orderField, $orderDirection, true, true);
$languages[$cId] = ArrayHelper::sortObjects($language, $orderField, $orderDirection, true, true);
}
}

Expand All @@ -307,7 +307,7 @@ public static function getInstalledLanguages(
continue;
}

$languages[$cId] = ArrayHelper::pivot($languages[$cId], $pivot);
$languages[$cId] = ArrayHelper::pivot($language, $pivot);
}
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Language/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ private static function passSprintf(&$string, $jsSafe = false, $interpretBackSla
$string = $final_string;

if ($script) {
foreach ($string_parts as $i => $str) {
static::$strings[$str] = $string_parts[$i];
foreach ($string_parts as $str) {
static::$strings[$str] = $str;
}
}

Expand Down