From 416bc53aee48d4ac2e1efdfa2d7c76386418ba6a Mon Sep 17 00:00:00 2001 From: quietone <quietone@2572884.no-reply.drupal.org> Date: Tue, 19 Nov 2024 18:43:41 +1300 Subject: [PATCH] Issue #3487665 by mstrelan, nicxvan: Add void return type to all hook_cron implementations --- core/.phpstan-baseline.php | 90 ------------------- .../src/Hook/AnnouncementsFeedHooks.php | 2 +- .../modules/comment/src/Hook/CommentHooks.php | 2 +- core/modules/dblog/src/Hook/DblogHooks.php | 2 +- core/modules/field/src/Hook/FieldHooks.php | 2 +- core/modules/file/src/Hook/FileHooks.php | 2 +- .../modules/history/src/Hook/HistoryHooks.php | 2 +- .../src/Hook/LayoutBuilderHooks.php | 2 +- core/modules/locale/src/Hook/LocaleHooks.php | 2 +- core/modules/node/src/Hook/NodeHooks1.php | 2 +- core/modules/search/src/Hook/SearchHooks.php | 2 +- core/modules/system/src/Hook/SystemHooks.php | 2 +- .../common_test/src/Hook/CommonTestHooks.php | 2 +- .../src/Hook/CommonTestCronHelperHooks.php | 2 +- core/modules/update/src/Hook/UpdateHooks.php | 2 +- .../workspaces/src/Hook/WorkspacesHooks.php | 2 +- 16 files changed, 15 insertions(+), 105 deletions(-) diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php index 3ccdd046c004..03b39093fa7a 100644 --- a/core/.phpstan-baseline.php +++ b/core/.phpstan-baseline.php @@ -11380,12 +11380,6 @@ 'count' => 1, 'path' => __DIR__ . '/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldValueValidator.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\announcements_feed\\\\Hook\\\\AnnouncementsFeedHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/announcements_feed/src/Hook/AnnouncementsFeedHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\announcements_feed\\\\Hook\\\\AnnouncementsFeedHooks\\:\\:help\\(\\) has no return type specified\\.$#', @@ -13492,12 +13486,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/comment/src/Form/DeleteForm.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\comment\\\\Hook\\\\CommentHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/comment/src/Hook/CommentHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\comment\\\\Hook\\\\CommentHooks\\:\\:entityExtraFieldInfo\\(\\) has no return type specified\\.$#', @@ -17434,12 +17422,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/dblog/src/Form/DblogFilterForm.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\dblog\\\\Hook\\\\DblogHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/dblog/src/Hook/DblogHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\dblog\\\\Hook\\\\DblogHooks\\:\\:help\\(\\) has no return type specified\\.$#', @@ -17932,12 +17914,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/field/src/FieldConfigStorage.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\field\\\\Hook\\\\FieldHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/field/src/Hook/FieldHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\field\\\\Hook\\\\FieldHooks\\:\\:entityBundleDelete\\(\\) has no return type specified\\.$#', @@ -19672,12 +19648,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/file/src/FileUsage/FileUsageInterface.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\file\\\\Hook\\\\FileHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/file/src/Hook/FileHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\file\\\\Hook\\\\FileHooks\\:\\:fileDownload\\(\\) has no return type specified\\.$#', @@ -21082,12 +21052,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/history/src/Controller/HistoryController.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\history\\\\Hook\\\\HistoryHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/history/src/Hook/HistoryHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\history\\\\Hook\\\\HistoryHooks\\:\\:help\\(\\) has no return type specified\\.$#', @@ -24118,12 +24082,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/layout_builder/src/Hook/LayoutBuilderHooks.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\layout_builder\\\\Hook\\\\LayoutBuilderHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/layout_builder/src/Hook/LayoutBuilderHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\layout_builder\\\\Hook\\\\LayoutBuilderHooks\\:\\:entityDelete\\(\\) has no return type specified\\.$#', @@ -25564,12 +25522,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/locale/src/Hook/LocaleHooks.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\locale\\\\Hook\\\\LocaleHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/locale/src/Hook/LocaleHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\locale\\\\Hook\\\\LocaleHooks\\:\\:help\\(\\) has no return type specified\\.$#', @@ -30516,12 +30468,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/node/src/Hook/NodeHooks1.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\node\\\\Hook\\\\NodeHooks1\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/node/src/Hook/NodeHooks1.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\node\\\\Hook\\\\NodeHooks1\\:\\:entityExtraFieldInfo\\(\\) has no return type specified\\.$#', @@ -33528,12 +33474,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/search/src/Hook/SearchHooks.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\search\\\\Hook\\\\SearchHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/search/src/Hook/SearchHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\search\\\\Hook\\\\SearchHooks\\:\\:help\\(\\) has no return type specified\\.$#', @@ -35412,12 +35352,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/system/src/Form/ThemeSettingsForm.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\system\\\\Hook\\\\SystemHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/src/Hook/SystemHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\system\\\\Hook\\\\SystemHooks\\:\\:entityTypeBuild\\(\\) has no return type specified\\.$#', @@ -36384,12 +36318,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/system/tests/modules/common_test/src/Hook/CommonTestHooks.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\common_test\\\\Hook\\\\CommonTestHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/tests/modules/common_test/src/Hook/CommonTestHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\common_test\\\\Hook\\\\CommonTestHooks\\:\\:libraryInfoBuild\\(\\) has no return type specified\\.$#', @@ -36402,12 +36330,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/system/tests/modules/common_test/src/Hook/CommonTestHooks.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\common_test_cron_helper\\\\Hook\\\\CommonTestCronHelperHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/tests/modules/common_test_cron_helper/src/Hook/CommonTestCronHelperHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\condition_test\\\\FormController\\:\\:submitForm\\(\\) has no return type specified\\.$#', @@ -43509,12 +43431,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/update/src/Form/UpdateReady.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\update\\\\Hook\\\\UpdateHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/update/src/Hook/UpdateHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\update\\\\Hook\\\\UpdateHooks\\:\\:help\\(\\) has no return type specified\\.$#', @@ -55095,12 +55011,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/workspaces/src/FormOperations.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.return - 'message' => '#^Method Drupal\\\\workspaces\\\\Hook\\\\WorkspacesHooks\\:\\:cron\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/modules/workspaces/src/Hook/WorkspacesHooks.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method Drupal\\\\workspaces\\\\Hook\\\\WorkspacesHooks\\:\\:entityAccess\\(\\) has no return type specified\\.$#', diff --git a/core/modules/announcements_feed/src/Hook/AnnouncementsFeedHooks.php b/core/modules/announcements_feed/src/Hook/AnnouncementsFeedHooks.php index d49535e5c40f..47245c1f3644 100644 --- a/core/modules/announcements_feed/src/Hook/AnnouncementsFeedHooks.php +++ b/core/modules/announcements_feed/src/Hook/AnnouncementsFeedHooks.php @@ -123,7 +123,7 @@ public function theme($existing, $type, $theme, $path) : array { * Implements hook_cron(). */ #[Hook('cron')] - public function cron() { + public function cron(): void { $config = \Drupal::config('announcements_feed.settings'); $interval = $config->get('cron_interval'); $last_check = \Drupal::state()->get('announcements_feed.last_fetch', 0); diff --git a/core/modules/comment/src/Hook/CommentHooks.php b/core/modules/comment/src/Hook/CommentHooks.php index d63f0bc6e17a..e104fe978c6c 100644 --- a/core/modules/comment/src/Hook/CommentHooks.php +++ b/core/modules/comment/src/Hook/CommentHooks.php @@ -382,7 +382,7 @@ public function nodeUpdateIndex(EntityInterface $node) { * Implements hook_cron(). */ #[Hook('cron')] - public function cron() { + public function cron(): void { // Store the maximum possible comments per thread (used for node search // ranking by reply count). \Drupal::state()->set('comment.node_comment_statistics_scale', 1.0 / max(1, \Drupal::service('comment.statistics')->getMaximumCount('node'))); diff --git a/core/modules/dblog/src/Hook/DblogHooks.php b/core/modules/dblog/src/Hook/DblogHooks.php index 7db7b7123d2f..accfc02ec970 100644 --- a/core/modules/dblog/src/Hook/DblogHooks.php +++ b/core/modules/dblog/src/Hook/DblogHooks.php @@ -61,7 +61,7 @@ public function menuLinksDiscoveredAlter(&$links): void { * Controls the size of the log table, paring it to 'dblog_row_limit' messages. */ #[Hook('cron')] - public function cron() { + public function cron(): void { // Cleanup the watchdog table. $row_limit = \Drupal::config('dblog.settings')->get('row_limit'); // For row limit n, get the wid of the nth row in descending wid order. diff --git a/core/modules/field/src/Hook/FieldHooks.php b/core/modules/field/src/Hook/FieldHooks.php index bab9f2aebdb6..546a6e0c95db 100644 --- a/core/modules/field/src/Hook/FieldHooks.php +++ b/core/modules/field/src/Hook/FieldHooks.php @@ -161,7 +161,7 @@ public function help($route_name, RouteMatchInterface $route_match) { * Implements hook_cron(). */ #[Hook('cron')] - public function cron() { + public function cron(): void { // Do a pass of purging on deleted Field API data, if any exists. $limit = \Drupal::config('field.settings')->get('purge_batch_size'); field_purge_batch($limit); diff --git a/core/modules/file/src/Hook/FileHooks.php b/core/modules/file/src/Hook/FileHooks.php index 9553c5619644..c3cb60ca529d 100644 --- a/core/modules/file/src/Hook/FileHooks.php +++ b/core/modules/file/src/Hook/FileHooks.php @@ -163,7 +163,7 @@ public function fileDownload($uri) { * Implements hook_cron(). */ #[Hook('cron')] - public function cron() { + public function cron(): void { $age = \Drupal::config('system.file')->get('temporary_maximum_age'); $file_storage = \Drupal::entityTypeManager()->getStorage('file'); /** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */ diff --git a/core/modules/history/src/Hook/HistoryHooks.php b/core/modules/history/src/Hook/HistoryHooks.php index 5fe37506fda4..2b95304dfd2d 100644 --- a/core/modules/history/src/Hook/HistoryHooks.php +++ b/core/modules/history/src/Hook/HistoryHooks.php @@ -36,7 +36,7 @@ public function help($route_name, RouteMatchInterface $route_match) { * Implements hook_cron(). */ #[Hook('cron')] - public function cron() { + public function cron(): void { \Drupal::database()->delete('history')->condition('timestamp', HISTORY_READ_LIMIT, '<')->execute(); } diff --git a/core/modules/layout_builder/src/Hook/LayoutBuilderHooks.php b/core/modules/layout_builder/src/Hook/LayoutBuilderHooks.php index 1ecc0eb96060..195cb0db3d19 100644 --- a/core/modules/layout_builder/src/Hook/LayoutBuilderHooks.php +++ b/core/modules/layout_builder/src/Hook/LayoutBuilderHooks.php @@ -217,7 +217,7 @@ public function entityDelete(EntityInterface $entity) { * Implements hook_cron(). */ #[Hook('cron')] - public function cron() { + public function cron(): void { if (\Drupal::moduleHandler()->moduleExists('block_content')) { /** @var \Drupal\layout_builder\InlineBlockEntityOperations $entity_operations */ $entity_operations = \Drupal::classResolver(InlineBlockEntityOperations::class); diff --git a/core/modules/locale/src/Hook/LocaleHooks.php b/core/modules/locale/src/Hook/LocaleHooks.php index a526bdb90bcc..e0afe107c87c 100644 --- a/core/modules/locale/src/Hook/LocaleHooks.php +++ b/core/modules/locale/src/Hook/LocaleHooks.php @@ -196,7 +196,7 @@ public function themesUninstalled($themes) { * @see \Drupal\locale\Plugin\QueueWorker\LocaleTranslation */ #[Hook('cron')] - public function cron() { + public function cron(): void { // Update translations only when an update frequency was set by the admin // and a translatable language was set. // Update tasks are added to the queue here but processed by Drupal's cron. diff --git a/core/modules/node/src/Hook/NodeHooks1.php b/core/modules/node/src/Hook/NodeHooks1.php index cce417a67ae2..073090e03066 100644 --- a/core/modules/node/src/Hook/NodeHooks1.php +++ b/core/modules/node/src/Hook/NodeHooks1.php @@ -189,7 +189,7 @@ public function entityExtraFieldInfo() { * Implements hook_cron(). */ #[Hook('cron')] - public function cron() { + public function cron(): void { // Calculate the oldest and newest node created times, for use in search // rankings. (Note that field aliases have to be variables passed by // reference.) diff --git a/core/modules/search/src/Hook/SearchHooks.php b/core/modules/search/src/Hook/SearchHooks.php index dc507ce4504c..8e4d95a07185 100644 --- a/core/modules/search/src/Hook/SearchHooks.php +++ b/core/modules/search/src/Hook/SearchHooks.php @@ -93,7 +93,7 @@ public function theme() : array { * and cleans up dirty words. */ #[Hook('cron')] - public function cron() { + public function cron(): void { /** @var \Drupal\search\SearchPageRepositoryInterface $search_page_repository */ $search_page_repository = \Drupal::service('search.search_page_repository'); foreach ($search_page_repository->getIndexableSearchPages() as $entity) { diff --git a/core/modules/system/src/Hook/SystemHooks.php b/core/modules/system/src/Hook/SystemHooks.php index d6474e30e7bd..297fd35813e3 100644 --- a/core/modules/system/src/Hook/SystemHooks.php +++ b/core/modules/system/src/Hook/SystemHooks.php @@ -318,7 +318,7 @@ public function systemInfoAlter(&$info, Extension $file, $type): void { * ensure files directories have .htaccess files. */ #[Hook('cron')] - public function cron() { + public function cron(): void { // Clean up the flood. \Drupal::flood()->garbageCollection(); foreach (Cache::getBins() as $cache_backend) { diff --git a/core/modules/system/tests/modules/common_test/src/Hook/CommonTestHooks.php b/core/modules/system/tests/modules/common_test/src/Hook/CommonTestHooks.php index f3959b67212c..7df7924d82ed 100644 --- a/core/modules/system/tests/modules/common_test/src/Hook/CommonTestHooks.php +++ b/core/modules/system/tests/modules/common_test/src/Hook/CommonTestHooks.php @@ -114,7 +114,7 @@ public function libraryInfoAlter(&$libraries, $module): void { * @see common_test_cron_helper() */ #[Hook('cron')] - public function cron() { + public function cron(): void { throw new \Exception('Uncaught exception'); } diff --git a/core/modules/system/tests/modules/common_test_cron_helper/src/Hook/CommonTestCronHelperHooks.php b/core/modules/system/tests/modules/common_test_cron_helper/src/Hook/CommonTestCronHelperHooks.php index 024669c3da72..5cec42967d37 100644 --- a/core/modules/system/tests/modules/common_test_cron_helper/src/Hook/CommonTestCronHelperHooks.php +++ b/core/modules/system/tests/modules/common_test_cron_helper/src/Hook/CommonTestCronHelperHooks.php @@ -20,7 +20,7 @@ class CommonTestCronHelperHooks { * @see common_test_cron() */ #[Hook('cron')] - public function cron() { + public function cron(): void { \Drupal::state()->set('common_test.cron', 'success'); } diff --git a/core/modules/update/src/Hook/UpdateHooks.php b/core/modules/update/src/Hook/UpdateHooks.php index 999a4e4d630e..71fc5c6ea742 100644 --- a/core/modules/update/src/Hook/UpdateHooks.php +++ b/core/modules/update/src/Hook/UpdateHooks.php @@ -165,7 +165,7 @@ public function theme() : array { * Implements hook_cron(). */ #[Hook('cron')] - public function cron() { + public function cron(): void { $update_config = \Drupal::config('update.settings'); $frequency = $update_config->get('check.interval_days'); $interval = 60 * 60 * 24 * $frequency; diff --git a/core/modules/workspaces/src/Hook/WorkspacesHooks.php b/core/modules/workspaces/src/Hook/WorkspacesHooks.php index 6d1ca63d62fa..adcb10ffb241 100644 --- a/core/modules/workspaces/src/Hook/WorkspacesHooks.php +++ b/core/modules/workspaces/src/Hook/WorkspacesHooks.php @@ -228,7 +228,7 @@ public function viewsQueryAlter(ViewExecutable $view, QueryPluginBase $query): v * Implements hook_cron(). */ #[Hook('cron')] - public function cron() { + public function cron(): void { \Drupal::service('workspaces.manager')->purgeDeletedWorkspacesBatch(); } -- GitLab