Issue #3422539 by mstrelan, dpi: Make use of array_key_first and array_key_last functions

(cherry picked from commit d493af8c4d)
merge-requests/6880/head
catch 2024-03-03 10:44:26 +00:00
parent 9fa4a048e5
commit 9358fca0f9
12 changed files with 15 additions and 33 deletions

View File

@ -389,8 +389,7 @@ function install_begin_request($class_loader, &$install_state) {
if ($install_state['settings_verified']) {
try {
$system_schema = system_schema();
end($system_schema);
$table = key($system_schema);
$table = array_key_last($system_schema);
$install_state['base_system_verified'] = Database::getConnection()->schema()->tableExists($table);
}
catch (DatabaseExceptionWrapper $e) {
@ -558,9 +557,7 @@ function install_run_tasks(&$install_state, callable $callback = NULL) {
// so we regenerate the remaining tasks based on the installation state,
// each time through the loop.
$tasks_to_perform = install_tasks_to_perform($install_state);
// Run the first task on the list.
reset($tasks_to_perform);
$task_name = key($tasks_to_perform);
$task_name = array_key_first($tasks_to_perform);
$task = array_shift($tasks_to_perform);
$install_state['active_task'] = $task_name;
$original_parameters = $install_state['parameters'];
@ -1167,8 +1164,7 @@ function install_verify_database_settings($site_path) {
*/
function install_verify_database_ready() {
$system_schema = system_schema();
end($system_schema);
$table = key($system_schema);
$table = array_key_last($system_schema);
$existing_install = FALSE;
if (Database::getConnectionInfo()) {

View File

@ -141,8 +141,7 @@ class VariationCache implements VariationCacheInterface {
*/
public function delete(array $keys, CacheableDependencyInterface $initial_cacheability): void {
$chain = $this->getRedirectChain($keys, $initial_cacheability);
end($chain);
$this->cacheBackend->delete(key($chain));
$this->cacheBackend->delete(array_key_last($chain));
}
/**
@ -150,8 +149,7 @@ class VariationCache implements VariationCacheInterface {
*/
public function invalidate(array $keys, CacheableDependencyInterface $initial_cacheability): void {
$chain = $this->getRedirectChain($keys, $initial_cacheability);
end($chain);
$this->cacheBackend->invalidate(key($chain));
$this->cacheBackend->invalidate(array_key_last($chain));
}
/**

View File

@ -63,8 +63,7 @@ class SelectionPluginManager extends DefaultPluginManager implements SelectionPl
// Sort the selection plugins by weight and select the best match.
uasort($selection_handler_groups[$base_plugin_id], ['Drupal\Component\Utility\SortArray', 'sortByWeightElement']);
end($selection_handler_groups[$base_plugin_id]);
$plugin_id = key($selection_handler_groups[$base_plugin_id]);
$plugin_id = array_key_last($selection_handler_groups[$base_plugin_id]);
return $plugin_id;
}

View File

@ -35,8 +35,7 @@ class OptionsButtonsWidget extends OptionsWidgetBase {
// If required and there is one single option, preselect it.
if ($this->required && count($options) == 1) {
reset($options);
$selected = [key($options)];
$selected = [array_key_first($options)];
}
if ($this->multiple) {

View File

@ -65,8 +65,7 @@ class ImageToolkitManager extends DefaultPluginManager {
if (!isset($toolkits[$toolkit_id]) || !class_exists($toolkits[$toolkit_id]['class'])) {
// The selected toolkit isn't available so return the first one found. If
// none are available this will return FALSE.
reset($toolkits);
$toolkit_id = key($toolkits);
$toolkit_id = array_key_first($toolkits);
}
return $toolkit_id;

View File

@ -129,8 +129,7 @@ class LayoutBuilderOverridesTest extends LayoutBuilderTestBase {
// Get the UUID of the component.
$components = Node::load(1)->get('layout_builder__layout')->getSection(0)->getComponents();
end($components);
$uuid = key($components);
$uuid = array_key_last($components);
$this->drupalGet('layout_builder/update/block/overrides/node.1/0/content/' . $uuid);
$page->uncheckField('settings[label_display]');

View File

@ -45,8 +45,7 @@ abstract class MigrateSqlSourceTestBase extends MigrateSourceTestBase {
// Use the biggest row to build the table schema.
$counts = array_map('count', $rows);
asort($counts);
end($counts);
$pilot = $rows[key($counts)];
$pilot = $rows[array_key_last($counts)];
$connection->schema()
->createTable($table, [

View File

@ -57,9 +57,7 @@ class MigrationTest extends KernelTestBase {
'id' => 'foo',
'process' => $process,
];
reset($process);
$destination = key(($process));
$destination = array_key_first(($process));
$migration = \Drupal::service('plugin.manager.migration')
->createStubMigration($plugin_definition);

View File

@ -238,8 +238,7 @@ class QueryBatchTest extends KernelTestBase {
// Use the biggest row to build the table schema.
$counts = array_map('count', $rows);
asort($counts);
end($counts);
$pilot = $rows[key($counts)];
$pilot = $rows[array_key_last($counts)];
$connection->schema()
->createTable($table, [

View File

@ -28,8 +28,7 @@ trait AssertMenuActiveTrailTrait {
* (optional) The class of the active element. Defaults to 'is-active'.
*/
protected function assertMenuActiveTrail($tree, $last_active, $active_trail_class = 'menu-item--active-trail', $active_class = 'is-active') {
end($tree);
$active_link_path = key($tree);
$active_link_path = array_key_last($tree);
$active_link_title = array_pop($tree);
$xpath = '';
if ($tree) {

View File

@ -74,8 +74,7 @@ class TourViewBuilder extends EntityViewBuilder {
// If there is at least one tour item, build the tour.
if ($items) {
end($items);
$key = key($items);
$key = array_key_last($items);
$items[$key]['cancelText'] = t('End tour');
}

View File

@ -1176,9 +1176,7 @@ function claro_preprocess_table(&$variables) {
$variables['attributes']['class'][] = 'draggable-table';
$draggable_row_found = TRUE;
}
reset($row['cells']);
$first_cell_key = key($row['cells']);
$first_cell_key = array_key_first($row['cells']);
// The 'attributes' key is always here and it is an
// \Drupal\Core\Template\Attribute.
// @see template_preprocess_table();