From 9f92d6dfd63c6fa9e59ea3f9c84d9f4749332679 Mon Sep 17 00:00:00 2001
From: Igor Biki <ibiki@uwaterloo.ca>
Date: Tue, 25 Mar 2025 11:26:25 -0400
Subject: [PATCH] ISTWCMS-7275: Improve type definition for batch context
 parameters

Updated function signatures to explicitly define $context and related parameters as arrays. This enhances code clarity and enforces stricter type safety, reducing potential errors during batch operations.
---
 uw_custom_blocks.post_update.php | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/uw_custom_blocks.post_update.php b/uw_custom_blocks.post_update.php
index 2afcb8ce..bdf143cc 100644
--- a/uw_custom_blocks.post_update.php
+++ b/uw_custom_blocks.post_update.php
@@ -55,7 +55,7 @@ function uw_custom_blocks_post_update_references_block_titles_updates_12(&$sandb
  *   The batch context array, which is updated with initial counts and a status
  *   message for the batch process.
  */
-function _references_block_titles_updates_batch_start($count, &$context): void {
+function _references_block_titles_updates_batch_start($count, array &$context): void {
   $context['results']['nodes_count'] = $count;
   $context['results']['nodes_processed'] = 0;
   $context['results']['nodes_updated'] = 0;
@@ -77,12 +77,8 @@ function _references_block_titles_updates_batch_start($count, &$context): void {
  * @param array $context
  *   A reference to the batch context array that tracks progress and statistics,
  *   including the number of nodes and revisions processed and updated.
- *
- * @return void
- *   This function does not return a value. It modifies the $context array
- *   directly and updates the node and its revisions in-place.
  */
-function _references_block_titles_updates_batch_update($nid, &$context): void {
+function _references_block_titles_updates_batch_update($nid, array &$context): void {
   $node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
 
   if ($node) {
@@ -162,7 +158,7 @@ function _references_block_titles_updates_batch_update($nid, &$context): void {
  *   The batch context array, which is updated with a status message
  *   indicating the processing of temporary storage.
  */
-function _references_block_titles_updates_batch_temp_storage(&$context) {
+function _references_block_titles_updates_batch_temp_storage(array &$context) {
   // Make sure to load temp storage, and loop over sections there.
   $context['message'] = t('Processing temporary storage.');
 }
@@ -174,7 +170,7 @@ function _references_block_titles_updates_batch_temp_storage(&$context) {
  *   The batch context array, which gets updated with status messages
  *   about nodes and revisions processed during the batch operation.
  */
-function _references_block_titles_updates_batch_end(&$context) {
+function _references_block_titles_updates_batch_end(array &$context) {
   $context['message'] = t('Updated @nodes_updated out of @nodes_processed (total @total) nodes.', [
     '@nodes_updated' => $context['results']['nodes_updated'],
     '@nodes_processed' => $context['results']['nodes_processed'],
@@ -199,6 +195,6 @@ function _references_block_titles_updates_batch_end(&$context) {
  * @return string
  *   Translated message indicating the completion of the batch process.
  */
-function _references_block_titles_updates_batch_finished($success, $results, $operations) {
+function _references_block_titles_updates_batch_finished($success, array $results, array $operations) {
   return t('Finished.');
 }
-- 
GitLab