diff --git a/administrator/components/com_categories/src/Field/CategoryeditField.php b/administrator/components/com_categories/src/Field/CategoryeditField.php index b443379088c5f..c824639799c3b 100644 --- a/administrator/components/com_categories/src/Field/CategoryeditField.php +++ b/administrator/components/com_categories/src/Field/CategoryeditField.php @@ -242,23 +242,23 @@ protected function getOptions() } // Pad the option text with spaces using depth level as a multiplier. - for ($i = 0, $n = \count($options); $i < $n; $i++) { + foreach ($options as $option) { // Translate ROOT if ($this->element['parent'] == true || $jinput->get('option') == 'com_categories') { - if ($options[$i]->level == 0) { - $options[$i]->text = Text::_('JGLOBAL_ROOT_PARENT'); + if ($option->level == 0) { + $option->text = Text::_('JGLOBAL_ROOT_PARENT'); } } - if ($options[$i]->published == 1) { - $options[$i]->text = str_repeat('- ', !$options[$i]->level ? 0 : $options[$i]->level - 1) . $options[$i]->text; + if ($option->published == 1) { + $option->text = str_repeat('- ', !$option->level ? 0 : $option->level - 1) . $option->text; } else { - $options[$i]->text = str_repeat('- ', !$options[$i]->level ? 0 : $options[$i]->level - 1) . '[' . $options[$i]->text . ']'; + $option->text = str_repeat('- ', !$option->level ? 0 : $option->level - 1) . '[' . $option->text . ']'; } // Displays language code if not set to All - if ($options[$i]->language !== '*') { - $options[$i]->text .= ' (' . $options[$i]->language . ')'; + if ($option->language !== '*') { + $option->text .= ' (' . $option->language . ')'; } } diff --git a/administrator/components/com_finder/src/Indexer/Adapter.php b/administrator/components/com_finder/src/Indexer/Adapter.php index f398751b16d3d..d554f0c5b6799 100644 --- a/administrator/components/com_finder/src/Indexer/Adapter.php +++ b/administrator/components/com_finder/src/Indexer/Adapter.php @@ -256,9 +256,9 @@ public function onBuildIndex() $items = $this->getItems($offset, $limit); // Iterate through the items and index them. - for ($i = 0, $n = \count($items); $i < $n; $i++) { + foreach ($items as $item) { // Index the item. - $this->index($items[$i]); + $this->index($item); // Adjust the offsets. $offset++; diff --git a/administrator/components/com_finder/src/Indexer/DebugAdapter.php b/administrator/components/com_finder/src/Indexer/DebugAdapter.php index b389c897aa040..11f5ea49d0f7d 100644 --- a/administrator/components/com_finder/src/Indexer/DebugAdapter.php +++ b/administrator/components/com_finder/src/Indexer/DebugAdapter.php @@ -254,9 +254,9 @@ public function onBuildIndex() $items = $this->getItems($offset, $limit); // Iterate through the items and index them. - for ($i = 0, $n = \count($items); $i < $n; $i++) { + foreach ($items as $item) { // Index the item. - $this->index($items[$i]); + $this->index($item); // Adjust the offsets. $offset++; diff --git a/administrator/components/com_finder/src/Indexer/Query.php b/administrator/components/com_finder/src/Indexer/Query.php index 708f4d046c5fd..61b1bd4cd9b5f 100644 --- a/administrator/components/com_finder/src/Indexer/Query.php +++ b/administrator/components/com_finder/src/Indexer/Query.php @@ -392,8 +392,8 @@ public function getExcludedTermIds() $results = []; // Iterate through the excluded tokens and compile the matching terms. - for ($i = 0, $c = \count($this->excluded); $i < $c; $i++) { - foreach ($this->excluded[$i]->matches as $match) { + foreach ($this->excluded as $item) { + foreach ($item->matches as $match) { $results = array_merge($results, $match); } } @@ -416,14 +416,14 @@ public function getIncludedTermIds() $results = []; // Iterate through the included tokens and compile the matching terms. - for ($i = 0, $c = \count($this->included); $i < $c; $i++) { + foreach ($this->included as $item) { // Check if we have any terms. - if (empty($this->included[$i]->matches)) { + if (empty($item->matches)) { continue; } // Get the term. - $term = $this->included[$i]->term; + $term = $item->term; // Prepare the container for the term if necessary. if (!\array_key_exists($term, $results)) { @@ -431,7 +431,7 @@ public function getIncludedTermIds() } // Add the matches to the stack. - foreach ($this->included[$i]->matches as $match) { + foreach ($item->matches as $match) { $results[$term] = array_merge($results[$term], $match); } } @@ -457,11 +457,11 @@ public function getRequiredTermIds() $results = []; // Iterate through the included tokens and compile the matching terms. - for ($i = 0, $c = \count($this->included); $i < $c; $i++) { + foreach ($this->included as $item) { // Check if the token is required. - if ($this->included[$i]->required) { + if ($item->required) { // Get the term. - $term = $this->included[$i]->term; + $term = $item->term; // Prepare the container for the term if necessary. if (!\array_key_exists($term, $results)) { @@ -469,7 +469,7 @@ public function getRequiredTermIds() } // Add the matches to the stack. - foreach ($this->included[$i]->matches as $match) { + foreach ($item->matches as $match) { $results[$term] = array_merge($results[$term], $match); } } @@ -1282,12 +1282,12 @@ protected function getTokenData($token) // Check the matching terms. if ((bool) $matches) { // Add the matches to the token. - for ($i = 0, $c = \count($matches); $i < $c; $i++) { - if (!isset($token->matches[$matches[$i]->term])) { - $token->matches[$matches[$i]->term] = []; + foreach ($matches as $item) { + if (!isset($token->matches[$item->term])) { + $token->matches[$item->term] = []; } - $token->matches[$matches[$i]->term][] = (int) $matches[$i]->term_id; + $token->matches[$item->term][] = (int) $item->term_id; } } diff --git a/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php b/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php index c2ebb09c28c2f..430b28db8f451 100644 --- a/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php @@ -1320,10 +1320,9 @@ public function getIniParserAvailability() if (!empty($disabledFunctions)) { // Attempt to detect them in the PHP INI disable_functions variable. $disabledFunctions = explode(',', trim($disabledFunctions)); - $numberOfDisabledFunctions = \count($disabledFunctions); - for ($i = 0; $i < $numberOfDisabledFunctions; $i++) { - $disabledFunctions[$i] = trim($disabledFunctions[$i]); + foreach ($disabledFunctions as &$disabledFunction) { + $disabledFunction = trim($disabledFunction); } $result = !\in_array('parse_ini_string', $disabledFunctions); diff --git a/administrator/components/com_login/src/Model/LoginModel.php b/administrator/components/com_login/src/Model/LoginModel.php index af855dbce62ea..5c664a1104cdb 100644 --- a/administrator/components/com_login/src/Model/LoginModel.php +++ b/administrator/components/com_login/src/Model/LoginModel.php @@ -80,12 +80,11 @@ public static function getLoginModule($name = 'mod_login', $title = null) { $result = null; $modules = self::_load($name); - $total = \count($modules); - for ($i = 0; $i < $total; $i++) { + foreach ($modules as $module) { // Match the title if we're looking for a specific instance of the module. - if (!$title || $modules[$i]->title == $title) { - $result = $modules[$i]; + if (!$title || $module->title == $title) { + $result = $module; break; } } diff --git a/administrator/components/com_menus/src/Controller/ItemController.php b/administrator/components/com_menus/src/Controller/ItemController.php index a9993ae573d17..27e515ecccfd3 100644 --- a/administrator/components/com_menus/src/Controller/ItemController.php +++ b/administrator/components/com_menus/src/Controller/ItemController.php @@ -578,8 +578,8 @@ public function getParentItem() $results = $model->getItems(); // Pad the option text with spaces using depth level as a multiplier. - for ($i = 0, $n = \count($results); $i < $n; $i++) { - $results[$i]->title = str_repeat(' - ', $results[$i]->level) . $results[$i]->title; + foreach ($results as $result) { + $result->title = str_repeat(' - ', $result->level) . $result->title; } } diff --git a/administrator/components/com_menus/src/Field/MenuParentField.php b/administrator/components/com_menus/src/Field/MenuParentField.php index cb85bd1a6ac48..432293e6c6970 100644 --- a/administrator/components/com_menus/src/Field/MenuParentField.php +++ b/administrator/components/com_menus/src/Field/MenuParentField.php @@ -99,12 +99,12 @@ protected function getOptions() } // Pad the option text with spaces using depth level as a multiplier. - for ($i = 0, $n = \count($options); $i < $n; $i++) { + foreach ($options as $option) { if ($clientId != 0) { // Allow translation of custom admin menus - $options[$i]->text = str_repeat('- ', $options[$i]->level) . Text::_($options[$i]->text); + $option->text = str_repeat('- ', $option->level) . Text::_($option->text); } else { - $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text; + $option->text = str_repeat('- ', $option->level) . $option->text; } } diff --git a/administrator/components/com_modules/src/Controller/ModuleController.php b/administrator/components/com_modules/src/Controller/ModuleController.php index 172d2dad9aa3e..90a83929d08b9 100644 --- a/administrator/components/com_modules/src/Controller/ModuleController.php +++ b/administrator/components/com_modules/src/Controller/ModuleController.php @@ -307,19 +307,18 @@ public function orderPosition() } $orders2 = []; - $n = \count($orders); - if ($n > 0) { - for ($i = 0; $i < $n; $i++) { - if (!isset($orders2[$orders[$i]->position])) { - $orders2[$orders[$i]->position] = 0; + if (\count($orders)) { + foreach ($orders as $order) { + if (!isset($orders2[$order->position])) { + $orders2[$order->position] = 0; } - $orders2[$orders[$i]->position]++; - $ord = $orders2[$orders[$i]->position]; - $title = Text::sprintf('COM_MODULES_OPTION_ORDER_POSITION', $ord, htmlspecialchars($orders[$i]->title, ENT_QUOTES, 'UTF-8')); + $orders2[$order->position]++; + $ord = $orders2[$order->position]; + $title = Text::sprintf('COM_MODULES_OPTION_ORDER_POSITION', $ord, htmlspecialchars($order->title, ENT_QUOTES, 'UTF-8')); - $html[] = $orders[$i]->position . ',' . $ord . ',' . $title; + $html[] = $order->position . ',' . $ord . ',' . $title; } } else { $html[] = $position . ',' . 1 . ',' . Text::_('JNONE'); diff --git a/administrator/components/com_users/src/Field/GroupparentField.php b/administrator/components/com_users/src/Field/GroupparentField.php index 2537c7047cc17..905f1a2971204 100644 --- a/administrator/components/com_users/src/Field/GroupparentField.php +++ b/administrator/components/com_users/src/Field/GroupparentField.php @@ -84,11 +84,11 @@ protected function getOptions() $isSuperAdmin = $this->getCurrentUser()->authorise('core.admin'); // Pad the option text with spaces using depth level as a multiplier. - for ($i = 0, $n = \count($options); $i < $n; $i++) { + foreach ($options as $i => $option) { // Show groups only if user is super admin or group is not super admin - if ($isSuperAdmin || !Access::checkGroup($options[$i]->id, 'core.admin')) { - $options[$i]->value = $options[$i]->id; - $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->title; + if ($isSuperAdmin || !Access::checkGroup($option->id, 'core.admin')) { + $option->value = $option->id; + $option->text = str_repeat('- ', $option->level) . $option->title; } else { unset($options[$i]); } diff --git a/administrator/components/com_users/src/Model/BackupcodesModel.php b/administrator/components/com_users/src/Model/BackupcodesModel.php index 098005a310dd4..cae3ab133197b 100644 --- a/administrator/components/com_users/src/Model/BackupcodesModel.php +++ b/administrator/components/com_users/src/Model/BackupcodesModel.php @@ -230,17 +230,17 @@ public function isBackupCode($code, ?User $user = null): bool $realLength = \count($codes); $restLength = 10 - $realLength; - for ($i = 0; $i < $realLength; $i++) { - if (hash_equals($codes[$i], $code)) { + foreach ($codes as $value) { + if (hash_equals($value, $code)) { // This may seem redundant but makes sure both branches of the if-block are isochronous $result = $result || true; $newArray[] = ''; - $dummyArray[] = $codes[$i]; + $dummyArray[] = $value; } else { // This may seem redundant but makes sure both branches of the if-block are isochronous $result = $result || false; $dummyArray[] = ''; - $newArray[] = $codes[$i]; + $newArray[] = $value; } } diff --git a/administrator/components/com_users/src/Model/LevelModel.php b/administrator/components/com_users/src/Model/LevelModel.php index 8e557d36b7774..066bd36478bd8 100644 --- a/administrator/components/com_users/src/Model/LevelModel.php +++ b/administrator/components/com_users/src/Model/LevelModel.php @@ -300,11 +300,11 @@ public function validate($form, $data, $group = null) $rules = ArrayHelper::toInteger($rules); - for ($i = 0, $n = \count($groups); $i < $n; ++$i) { - if (Access::checkGroup((int) $groups[$i]->id, 'core.admin')) { - if (\in_array((int) $groups[$i]->id, $rules) && !\in_array((int) $groups[$i]->id, $data['rules'])) { - $data['rules'][] = (int) $groups[$i]->id; - } elseif (!\in_array((int) $groups[$i]->id, $rules) && \in_array((int) $groups[$i]->id, $data['rules'])) { + foreach ($groups as $value) { + if (Access::checkGroup((int) $value->id, 'core.admin')) { + if (\in_array((int) $value->id, $rules) && !\in_array((int) $value->id, $data['rules'])) { + $data['rules'][] = (int) $value->id; + } elseif (!\in_array((int) $value->id, $rules) && \in_array((int) $value->id, $data['rules'])) { $this->setError(Text::_('JLIB_USER_ERROR_NOT_SUPERADMIN')); return false; diff --git a/components/com_banners/src/Service/Router.php b/components/com_banners/src/Service/Router.php index ad7b74fa6b18d..33e96e5f64ce8 100644 --- a/components/com_banners/src/Service/Router.php +++ b/components/com_banners/src/Service/Router.php @@ -46,10 +46,8 @@ public function build(&$query) unset($query['id']); } - $total = \count($segments); - - for ($i = 0; $i < $total; $i++) { - $segments[$i] = str_replace(':', '-', $segments[$i]); + foreach ($segments as &$segment) { + $segment = str_replace(':', '-', $segment); } return $segments; @@ -66,12 +64,12 @@ public function build(&$query) */ public function parse(&$segments) { - $total = \count($segments); $vars = []; - for ($i = 0; $i < $total; $i++) { - $segments[$i] = preg_replace('/-/', ':', $segments[$i], 1); + foreach ($segments as &$segment) { + $segment = preg_replace('/-/', ':', $segment, 1); } + unset($segment); // View is always the first element of the array $count = \count($segments); diff --git a/components/com_contact/src/Model/FeaturedModel.php b/components/com_contact/src/Model/FeaturedModel.php index 990340740df2c..7c2e7b6aa81e3 100644 --- a/components/com_contact/src/Model/FeaturedModel.php +++ b/components/com_contact/src/Model/FeaturedModel.php @@ -64,9 +64,7 @@ public function getItems() $items = parent::getItems(); // Convert the params field into an object, saving original in _params - for ($i = 0, $n = \count($items); $i < $n; $i++) { - $item = &$items[$i]; - + foreach ($items as $item) { if (!isset($this->_params)) { $item->params = new Registry($item->params); } diff --git a/components/com_contact/src/View/Featured/HtmlView.php b/components/com_contact/src/View/Featured/HtmlView.php index f7849b5de99c1..9a5832db13814 100644 --- a/components/com_contact/src/View/Featured/HtmlView.php +++ b/components/com_contact/src/View/Featured/HtmlView.php @@ -105,8 +105,7 @@ public function display($tpl = null) // Prepare the data. // Compute the contact slug. - for ($i = 0, $n = \count($items); $i < $n; $i++) { - $item = &$items[$i]; + foreach ($items as $item) { $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; $temp = $item->params; $item->params = clone $params; diff --git a/components/com_content/src/View/Archive/HtmlView.php b/components/com_content/src/View/Archive/HtmlView.php index 343318bd64991..5d06925652d52 100644 --- a/components/com_content/src/View/Archive/HtmlView.php +++ b/components/com_content/src/View/Archive/HtmlView.php @@ -197,8 +197,8 @@ public function display($tpl = null) $years = []; $years[] = HTMLHelper::_('select.option', null, Text::_('JYEAR')); - for ($i = 0, $iMax = \count($this->years); $i < $iMax; $i++) { - $years[] = HTMLHelper::_('select.option', $this->years[$i], $this->years[$i]); + foreach ($this->years as $year) { + $years[] = HTMLHelper::_('select.option', $year, $year); } $form->yearField = HTMLHelper::_( diff --git a/components/com_finder/src/Model/SearchModel.php b/components/com_finder/src/Model/SearchModel.php index c61252fce42a3..30da21a70b307 100644 --- a/components/com_finder/src/Model/SearchModel.php +++ b/components/com_finder/src/Model/SearchModel.php @@ -198,8 +198,8 @@ protected function getListQuery() ->where('t.node_id IN (' . implode(',', array_unique($taxonomies)) . ')'); // Iterate through each taxonomy group. - for ($i = 0, $c = \count($groups); $i < $c; $i++) { - $query->having('SUM(CASE WHEN t.node_id IN (' . implode(',', $groups[$i]) . ') THEN 1 ELSE 0 END) > 0'); + foreach ($groups as $group) { + $query->having('SUM(CASE WHEN t.node_id IN (' . implode(',', $group) . ') THEN 1 ELSE 0 END) > 0'); } } diff --git a/libraries/src/Cache/Storage/FileStorage.php b/libraries/src/Cache/Storage/FileStorage.php index de8be744fe705..b5bd935ec0dce 100644 --- a/libraries/src/Cache/Storage/FileStorage.php +++ b/libraries/src/Cache/Storage/FileStorage.php @@ -260,9 +260,9 @@ public function clean($group, $mode = null) case 'notgroup': $folders = $this->_folders($this->_root); - for ($i = 0, $n = \count($folders); $i < $n; $i++) { - if ($folders[$i] != $folder) { - $return |= $this->_deleteFolder($this->_root . '/' . $folders[$i]); + foreach ($folders as $value) { + if ($value != $folder) { + $return |= $this->_deleteFolder($this->_root . '/' . $value); } } diff --git a/libraries/src/Component/Router/RouterLegacy.php b/libraries/src/Component/Router/RouterLegacy.php index 112f53cc4b7d9..e333d551602d1 100644 --- a/libraries/src/Component/Router/RouterLegacy.php +++ b/libraries/src/Component/Router/RouterLegacy.php @@ -72,10 +72,9 @@ public function build(&$query) if (\function_exists($function)) { $segments = $function($query); - $total = \count($segments); - for ($i = 0; $i < $total; $i++) { - $segments[$i] = str_replace(':', '-', $segments[$i]); + foreach ($segments as &$segment) { + $segment = str_replace(':', '-', $segment); } return $segments; @@ -98,10 +97,8 @@ public function parse(&$segments) $function = $this->component . 'ParseRoute'; if (\function_exists($function)) { - $total = \count($segments); - - for ($i = 0; $i < $total; $i++) { - $segments[$i] = preg_replace('/-/', ':', $segments[$i], 1); + foreach ($segments as &$segment) { + $segment = preg_replace('/-/', ':', $segment, 1); } return $function($segments); diff --git a/libraries/src/Document/Renderer/Feed/AtomRenderer.php b/libraries/src/Document/Renderer/Feed/AtomRenderer.php index 3519cb4f7a567..129486ceefa1e 100644 --- a/libraries/src/Document/Renderer/Feed/AtomRenderer.php +++ b/libraries/src/Document/Renderer/Feed/AtomRenderer.php @@ -123,63 +123,63 @@ public function render($name = '', $params = null, $content = null) $feed .= " <generator uri=\"https://www.joomla.org\"" . $versionHtmlEscaped . ">" . $data->getGenerator() . "</generator>\n"; $feed .= " <link rel=\"self\" type=\"application/atom+xml\" href=\"" . str_replace(' ', '%20', $url . $syndicationURL) . "\"/>\n"; - for ($i = 0, $count = \count($data->items); $i < $count; $i++) { - $itemlink = $data->items[$i]->link; + foreach ($data->items as $item) { + $itemlink = $item->link; if (preg_match('/[\x80-\xFF]/', $itemlink)) { $itemlink = implode('/', array_map('rawurlencode', explode('/', $itemlink))); } $feed .= " <entry>\n"; - $feed .= " <title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8') . "</title>\n"; + $feed .= " <title>" . htmlspecialchars(strip_tags($item->title), ENT_COMPAT, 'UTF-8') . "</title>\n"; $feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"" . $url . $itemlink . "\"/>\n"; - if ($data->items[$i]->date == '') { - $data->items[$i]->date = $now->toUnix(); + if ($item->date == '') { + $item->date = $now->toUnix(); } - $itemDate = Factory::getDate($data->items[$i]->date); + $itemDate = Factory::getDate($item->date); $itemDate->setTimezone($tz); $feed .= " <published>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</published>\n"; $feed .= " <updated>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n"; - if (empty($data->items[$i]->guid)) { + if (empty($item->guid)) { $itemGuid = str_replace(' ', '%20', $url . $itemlink); } else { - $itemGuid = htmlspecialchars($data->items[$i]->guid, ENT_COMPAT, 'UTF-8'); + $itemGuid = htmlspecialchars($item->guid, ENT_COMPAT, 'UTF-8'); } $feed .= " <id>" . $itemGuid . "</id>\n"; - if ($data->items[$i]->author != '') { + if ($item->author != '') { $feed .= " <author>\n"; - $feed .= " <name>" . htmlspecialchars($data->items[$i]->author, ENT_COMPAT, 'UTF-8') . "</name>\n"; + $feed .= " <name>" . htmlspecialchars($item->author, ENT_COMPAT, 'UTF-8') . "</name>\n"; - if (!empty($data->items[$i]->authorEmail)) { - $feed .= " <email>" . htmlspecialchars($data->items[$i]->authorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n"; + if (!empty($item->authorEmail)) { + $feed .= " <email>" . htmlspecialchars($item->authorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n"; } $feed .= " </author>\n"; } - if (!empty($data->items[$i]->description)) { - $feed .= " <summary type=\"html\">" . htmlspecialchars($this->_relToAbs($data->items[$i]->description), ENT_COMPAT, 'UTF-8') . "</summary>\n"; - $feed .= " <content type=\"html\">" . htmlspecialchars($this->_relToAbs($data->items[$i]->description), ENT_COMPAT, 'UTF-8') . "</content>\n"; + if (!empty($item->description)) { + $feed .= " <summary type=\"html\">" . htmlspecialchars($this->_relToAbs($item->description), ENT_COMPAT, 'UTF-8') . "</summary>\n"; + $feed .= " <content type=\"html\">" . htmlspecialchars($this->_relToAbs($item->description), ENT_COMPAT, 'UTF-8') . "</content>\n"; } - if (!empty($data->items[$i]->category)) { - if (\is_array($data->items[$i]->category)) { - foreach ($data->items[$i]->category as $cat) { + if (!empty($item->category)) { + if (\is_array($item->category)) { + foreach ($item->category as $cat) { $feed .= " <category term=\"" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "\" />\n"; } } else { - $feed .= " <category term=\"" . htmlspecialchars($data->items[$i]->category, ENT_COMPAT, 'UTF-8') . "\" />\n"; + $feed .= " <category term=\"" . htmlspecialchars($item->category, ENT_COMPAT, 'UTF-8') . "\" />\n"; } } - if ($data->items[$i]->enclosure != null) { - $feed .= " <link rel=\"enclosure\" href=\"" . $data->items[$i]->enclosure->url . "\" type=\"" - . $data->items[$i]->enclosure->type . "\" length=\"" . $data->items[$i]->enclosure->length . "\"/>\n"; + if ($item->enclosure != null) { + $feed .= " <link rel=\"enclosure\" href=\"" . $item->enclosure->url . "\" type=\"" + . $item->enclosure->type . "\" length=\"" . $item->enclosure->length . "\"/>\n"; } $feed .= " </entry>\n"; diff --git a/libraries/src/Document/Renderer/Feed/RssRenderer.php b/libraries/src/Document/Renderer/Feed/RssRenderer.php index 9c6d533027cb0..5522faec5b00a 100644 --- a/libraries/src/Document/Renderer/Feed/RssRenderer.php +++ b/libraries/src/Document/Renderer/Feed/RssRenderer.php @@ -166,8 +166,8 @@ public function render($name = '', $params = null, $content = null) $feed .= " <skipDays>" . htmlspecialchars($data->skipDays, ENT_COMPAT, 'UTF-8') . "</skipDays>\n"; } - for ($i = 0, $count = \count($data->items); $i < $count; $i++) { - $itemlink = $data->items[$i]->link; + foreach ($data->items as $item) { + $itemlink = $item->link; if (preg_match('/[\x80-\xFF]/', $itemlink)) { $itemlink = implode('/', array_map('rawurlencode', explode('/', $itemlink))); @@ -178,20 +178,20 @@ public function render($name = '', $params = null, $content = null) } $feed .= " <item>\n"; - $feed .= " <title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8') . "</title>\n"; + $feed .= " <title>" . htmlspecialchars(strip_tags($item->title), ENT_COMPAT, 'UTF-8') . "</title>\n"; $feed .= " <link>" . str_replace(' ', '%20', $itemlink) . "</link>\n"; - if (empty($data->items[$i]->guid)) { + if (empty($item->guid)) { $feed .= " <guid isPermaLink=\"true\">" . str_replace(' ', '%20', $itemlink) . "</guid>\n"; } else { - $feed .= " <guid isPermaLink=\"false\">" . htmlspecialchars($data->items[$i]->guid, ENT_COMPAT, 'UTF-8') . "</guid>\n"; + $feed .= " <guid isPermaLink=\"false\">" . htmlspecialchars($item->guid, ENT_COMPAT, 'UTF-8') . "</guid>\n"; } - $feed .= " <description><![CDATA[" . $this->_relToAbs($data->items[$i]->description) . "]]></description>\n"; + $feed .= " <description><![CDATA[" . $this->_relToAbs($item->description) . "]]></description>\n"; - if ($data->items[$i]->authorEmail != '') { + if ($item->authorEmail != '') { $feed .= ' <author>' - . htmlspecialchars($data->items[$i]->authorEmail . ' (' . $data->items[$i]->author . ')', ENT_COMPAT, 'UTF-8') . "</author>\n"; + . htmlspecialchars($item->authorEmail . ' (' . $item->author . ')', ENT_COMPAT, 'UTF-8') . "</author>\n"; } /* @@ -202,33 +202,33 @@ public function render($name = '', $params = null, $content = null) * } */ - if (empty($data->items[$i]->category) === false) { - if (\is_array($data->items[$i]->category)) { - foreach ($data->items[$i]->category as $cat) { + if (empty($item->category) === false) { + if (\is_array($item->category)) { + foreach ($item->category as $cat) { $feed .= " <category>" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "</category>\n"; } } else { - $feed .= " <category>" . htmlspecialchars($data->items[$i]->category, ENT_COMPAT, 'UTF-8') . "</category>\n"; + $feed .= " <category>" . htmlspecialchars($item->category, ENT_COMPAT, 'UTF-8') . "</category>\n"; } } - if ($data->items[$i]->comments != '') { - $feed .= " <comments>" . htmlspecialchars($data->items[$i]->comments, ENT_COMPAT, 'UTF-8') . "</comments>\n"; + if ($item->comments != '') { + $feed .= " <comments>" . htmlspecialchars($item->comments, ENT_COMPAT, 'UTF-8') . "</comments>\n"; } - if ($data->items[$i]->date != '') { - $itemDate = Factory::getDate($data->items[$i]->date); + if ($item->date != '') { + $itemDate = Factory::getDate($item->date); $itemDate->setTimezone($tz); $feed .= " <pubDate>" . htmlspecialchars($itemDate->toRFC822(true), ENT_COMPAT, 'UTF-8') . "</pubDate>\n"; } - if ($data->items[$i]->enclosure != null) { + if ($item->enclosure != null) { $feed .= " <enclosure url=\""; - $feed .= $data->items[$i]->enclosure->url; + $feed .= $item->enclosure->url; $feed .= "\" length=\""; - $feed .= $data->items[$i]->enclosure->length; + $feed .= $item->enclosure->length; $feed .= "\" type=\""; - $feed .= $data->items[$i]->enclosure->type; + $feed .= $item->enclosure->type; $feed .= "\"/>\n"; } diff --git a/libraries/src/Form/FormHelper.php b/libraries/src/Form/FormHelper.php index 97d2e71c7a638..602745aaaecaf 100644 --- a/libraries/src/Form/FormHelper.php +++ b/libraries/src/Form/FormHelper.php @@ -244,9 +244,9 @@ protected static function loadClass($entity, $type) // If the type is complex, add the base type to the paths. if ($pos = strpos($type, '_')) { // Add the complex type prefix to the paths. - for ($i = 0, $n = \count($paths); $i < $n; $i++) { + foreach ($paths as $value) { // Derive the new path. - $path = $paths[$i] . '/' . strtolower(substr($type, 0, $pos)); + $path = $value . '/' . strtolower(substr($type, 0, $pos)); // If the path does not exist, add it. if (!\in_array($path, $paths)) { diff --git a/libraries/src/HTML/Helpers/Access.php b/libraries/src/HTML/Helpers/Access.php index dd4b2f44f432f..9de65e389c1e3 100644 --- a/libraries/src/HTML/Helpers/Access.php +++ b/libraries/src/HTML/Helpers/Access.php @@ -116,9 +116,9 @@ public static function usergroup($name, $selected, $attribs = '', $allowAll = tr { $options = array_values(UserGroupsHelper::getInstance()->getAll()); - for ($i = 0, $n = \count($options); $i < $n; $i++) { - $options[$i]->value = $options[$i]->id; - $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->title; + foreach ($options as $option) { + $option->value = $option->id; + $option->text = str_repeat('- ', $option->level) . $option->title; } // If all usergroups is allowed, push it into the array. @@ -152,9 +152,7 @@ public static function usergroups($name, $selected, $checkSuperAdmin = false) $html = []; - for ($i = 0, $n = \count($groups); $i < $n; $i++) { - $item = &$groups[$i]; - + foreach ($groups as $item) { // If checkSuperAdmin is true, only add item if the user is superadmin or the group is not super admin if ((!$checkSuperAdmin) || $isSuperAdmin || (!AccessCheck::checkGroup($item->id, 'core.admin'))) { // Set up the variable attributes. ID may not start with a number (CSS) @@ -212,9 +210,7 @@ public static function actions($name, $selected, $component, $section = 'global' $html = []; $html[] = '<ul class="checklist access-actions">'; - for ($i = 0, $n = \count($actions); $i < $n; $i++) { - $item = &$actions[$i]; - + foreach ($actions as $item) { // Setup the variable attributes. $eid = $count . 'action_' . $item->id; $checked = \in_array($item->id, $selected) ? ' checked="checked"' : ''; diff --git a/libraries/src/HTML/Helpers/StringHelper.php b/libraries/src/HTML/Helpers/StringHelper.php index 40db6bf243703..099a9f9b49105 100644 --- a/libraries/src/HTML/Helpers/StringHelper.php +++ b/libraries/src/HTML/Helpers/StringHelper.php @@ -101,19 +101,17 @@ public static function truncate($text, $length = 0, $noSplit = true, $allowHtml preg_match_all("#</([a-z][a-z0-9]*)\b(?:[^>]*?)>#iU", $tmp, $result); $closedTags = $result[1]; - $numOpened = \count($openedTags); - // Not all tags are closed so trim the text and finish. - if (\count($closedTags) !== $numOpened) { + if (\count($closedTags) !== \count($openedTags)) { // Closing tags need to be in the reverse order of opening tags. $openedTags = array_reverse($openedTags); // Close tags - for ($i = 0; $i < $numOpened; $i++) { - if (!\in_array($openedTags[$i], $closedTags)) { - $tmp .= '</' . $openedTags[$i] . '>'; + foreach ($openedTags as $openedTag) { + if (!\in_array($openedTag, $closedTags)) { + $tmp .= '</' . $openedTag . '>'; } else { - unset($closedTags[array_search($openedTags[$i], $closedTags)]); + unset($closedTags[array_search($openedTag, $closedTags)]); } } } diff --git a/libraries/src/HTML/Helpers/User.php b/libraries/src/HTML/Helpers/User.php index 00ecb79fb4593..0a7bb53b739b3 100644 --- a/libraries/src/HTML/Helpers/User.php +++ b/libraries/src/HTML/Helpers/User.php @@ -38,10 +38,10 @@ public static function groups($includeSuperAdmin = false) { $options = array_values(UserGroupsHelper::getInstance()->getAll()); - for ($i = 0, $n = \count($options); $i < $n; $i++) { - $options[$i]->value = $options[$i]->id; - $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->title; - $groups[] = HTMLHelper::_('select.option', $options[$i]->value, $options[$i]->text); + foreach ($options as $option) { + $option->value = $option->id; + $option->text = str_repeat('- ', $option->level) . $option->title; + $groups[] = HTMLHelper::_('select.option', $option->value, $option->text); } // Exclude super admin groups if requested diff --git a/libraries/src/Helper/ModuleHelper.php b/libraries/src/Helper/ModuleHelper.php index 7ded94f7d26b5..4a92863884e51 100644 --- a/libraries/src/Helper/ModuleHelper.php +++ b/libraries/src/Helper/ModuleHelper.php @@ -41,7 +41,7 @@ abstract class ModuleHelper * @param string $name The name of the module * @param string $title The title of the module, optional * - * @return \stdClass The Module object + * @return \stdClass|null The Module object * * @since 1.5 */ @@ -49,15 +49,14 @@ public static function &getModule($name, $title = null) { $result = null; $modules =& static::load(); - $total = \count($modules); - for ($i = 0; $i < $total; $i++) { + foreach ($modules as $module) { // Match the name of the module - if ($modules[$i]->name === $name || $modules[$i]->module === $name) { + if ($module->name === $name || $module->module === $name) { // Match the title if we're looking for a specific instance of the module - if (!$title || $modules[$i]->title === $title) { + if (!$title || $module->title === $title) { // Found it - $result = &$modules[$i]; + $result = $module; break; } } @@ -87,11 +86,10 @@ public static function &getModules($position) $result = []; $input = Factory::getApplication()->getInput(); $modules = &static::load(); - $total = \count($modules); - for ($i = 0; $i < $total; $i++) { - if ($modules[$i]->position === $position) { - $result[] = &$modules[$i]; + foreach ($modules as $module) { + if ($module->position === $position) { + $result[] = $module; } } @@ -695,13 +693,11 @@ public static function &getModuleById($id) { $modules =& static::load(); - $total = \count($modules); - - for ($i = 0; $i < $total; $i++) { + foreach ($modules as $module) { // Match the id of the module - if ((string) $modules[$i]->id === $id) { + if ((string) $module->id === $id) { // Found it - return $modules[$i]; + return $module; } } diff --git a/libraries/src/Plugin/PluginHelper.php b/libraries/src/Plugin/PluginHelper.php index b35348dd7e15b..9977628cc163d 100644 --- a/libraries/src/Plugin/PluginHelper.php +++ b/libraries/src/Plugin/PluginHelper.php @@ -187,9 +187,9 @@ public static function importPlugin($type, $plugin = null, $autocreate = true, ? $plugins = static::load(); // Get the specified plugin(s). - for ($i = 0, $t = \count($plugins); $i < $t; $i++) { - if ($plugins[$i]->type === $type && ($plugin === null || $plugins[$i]->name === $plugin)) { - static::import($plugins[$i], $autocreate, $dispatcher); + foreach ($plugins as $value) { + if ($value->type === $type && ($plugin === null || $value->name === $plugin)) { + static::import($value, $autocreate, $dispatcher); $results = true; } } diff --git a/libraries/src/Table/Usergroup.php b/libraries/src/Table/Usergroup.php index fbc964da0d0b7..a9fdc4c9e4cbc 100644 --- a/libraries/src/Table/Usergroup.php +++ b/libraries/src/Table/Usergroup.php @@ -158,9 +158,9 @@ public function rebuild($parentId = 0, $left = 0) $right = $left + 1; // Execute this function recursively over all children - for ($i = 0, $n = \count($children); $i < $n; $i++) { + foreach ($children as $child) { // $right is the current right value, which is incremented on recursion return - $right = $this->rebuild($children[$i], $right); + $right = $this->rebuild($child, $right); // If there is an update failure, return false to break out of the recursion if ($right === false) { diff --git a/libraries/src/User/UserHelper.php b/libraries/src/User/UserHelper.php index b3c1ae9c0f2c5..8e40457a88504 100644 --- a/libraries/src/User/UserHelper.php +++ b/libraries/src/User/UserHelper.php @@ -295,8 +295,8 @@ public static function setUserGroups($userId, $groups) $results = $db->loadObjectList(); // Set the titles for the user groups. - for ($i = 0, $n = \count($results); $i < $n; $i++) { - $user->groups[$results[$i]->id] = $results[$i]->id; + foreach ($results as $result) { + $user->groups[$result->id] = $result->id; } // Store the user object. diff --git a/plugins/sampledata/blog/src/Extension/Blog.php b/plugins/sampledata/blog/src/Extension/Blog.php index 68138976df258..53f9529987c21 100644 --- a/plugins/sampledata/blog/src/Extension/Blog.php +++ b/plugins/sampledata/blog/src/Extension/Blog.php @@ -427,12 +427,12 @@ public function onAjaxSampledataApplyStep1() ]; // Create Transitions. - for ($i = 0; $i < \count($fromTo); $i++) { + foreach ($fromTo as $i => $item) { $trTable = new \Joomla\Component\Workflow\Administrator\Table\TransitionTable($this->getDatabase()); - $trTable->from_stage_id = $fromTo[$i]['from_stage_id']; - $trTable->to_stage_id = $fromTo[$i]['to_stage_id']; - $trTable->options = $fromTo[$i]['options']; + $trTable->from_stage_id = $item['from_stage_id']; + $trTable->to_stage_id = $item['to_stage_id']; + $trTable->options = $item['options']; // Set values from language strings. $trTable->title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_TRANSITION' . ($i + 1) . '_TITLE');