diff options
author | quietone <quietone@2572884.no-reply.drupal.org> | 2025-02-18 12:28:27 +1300 |
---|---|---|
committer | quietone <quietone@2572884.no-reply.drupal.org> | 2025-02-18 12:28:27 +1300 |
commit | 7488aea757938c62c4f660281d0c0a5b39b0eff3 (patch) | |
tree | 0bf48c5cff5c6ab4635b05d1141a23d2d1d85256 | |
parent | bd35301f4051810966c7b79e30d16c7caa3883f7 (diff) | |
download | drupal-7488aea757938c62c4f660281d0c0a5b39b0eff3.tar.gz drupal-7488aea757938c62c4f660281d0c0a5b39b0eff3.zip |
Issue #3501886 by mstrelan, smustgrave, nicxvan: Add return type to hook implementations without obvious group
16 files changed, 24 insertions, 113 deletions
diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php index 7cfae86c332..5468cfee172 100644 --- a/core/.phpstan-baseline.php +++ b/core/.phpstan-baseline.php @@ -13448,12 +13448,6 @@ $ignoreErrors[] = [ 'path' => __DIR__ . '/modules/comment/src/Hook/CommentHooks.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\comment\\\\Hook\\\\CommentHooks\\:\\:nodeUpdateIndex\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/comment/src/Hook/CommentHooks.php', -]; -$ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\comment\\\\Plugin\\\\EntityReferenceSelection\\\\CommentSelection\\:\\:entityQueryAlter\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, @@ -16610,12 +16604,6 @@ $ignoreErrors[] = [ 'path' => __DIR__ . '/modules/content_translation/tests/src/Unit/Menu/ContentTranslationLocalTasksTest.php', ]; $ignoreErrors[] = [ - 'message' => '#^Function contextual_preprocess\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/contextual/contextual.module', -]; -$ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\contextual\\\\ContextualController\\:\\:create\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, @@ -31610,12 +31598,6 @@ $ignoreErrors[] = [ 'path' => __DIR__ . '/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method Drupal\\\\search_langcode_test\\\\Hook\\\\SearchLangcodeTestHooks\\:\\:searchPreprocess\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/search/tests/modules/search_langcode_test/src/Hook/SearchLangcodeTestHooks.php', -]; -$ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\Tests\\\\search\\\\Functional\\\\Rest\\\\SearchPageJsonAnonTest\\:\\:assertAuthenticationEdgeCases\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, @@ -33878,12 +33860,6 @@ $ignoreErrors[] = [ 'path' => __DIR__ . '/modules/system/tests/modules/default_format_test/src/DefaultFormatTestController.php', ]; $ignoreErrors[] = [ - 'message' => '#^Function deprecation_test_deprecated_hook\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/tests/modules/deprecation_test/deprecation_test.module', -]; -$ignoreErrors[] = [ 'message' => '#^Call to deprecated function deprecation_test_function\\(\\)\\: in drupal\\:8\\.4\\.0 and is removed from drupal\\:9\\.0\\.0\\. This is the deprecation message for deprecated_test_function\\(\\)\\.$#', @@ -35668,36 +35644,12 @@ $ignoreErrors[] = [ 'path' => __DIR__ . '/modules/system/tests/modules/module_autoload_test/src/SomeClass.php', ]; $ignoreErrors[] = [ - 'message' => '#^Function module_test_test_hook\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/tests/modules/module_test/module_test.file.inc', -]; -$ignoreErrors[] = [ - 'message' => '#^Function module_test_altered_test_hook\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/tests/modules/module_test/module_test.implementations.inc', -]; -$ignoreErrors[] = [ 'message' => '#^Function module_test_load\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, 'path' => __DIR__ . '/modules/system/tests/modules/module_test/module_test.module', ]; $ignoreErrors[] = [ - 'message' => '#^Function module_test_modules_installed\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/tests/modules/module_test/module_test.module', -]; -$ignoreErrors[] = [ - 'message' => '#^Function module_test_modules_uninstalled\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/tests/modules/module_test/module_test.module', -]; -$ignoreErrors[] = [ 'message' => '#^Function module_test_post_update_test\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, @@ -38410,30 +38362,6 @@ $ignoreErrors[] = [ 'path' => __DIR__ . '/modules/system/tests/src/Unit/Routing/AdminRouteSubscriberTest.php', ]; $ignoreErrors[] = [ - 'message' => '#^Function nyan_cat_extension\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/tests/themes/engines/nyan_cat/nyan_cat.engine', -]; -$ignoreErrors[] = [ - 'message' => '#^Function nyan_cat_render_template\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/tests/themes/engines/nyan_cat/nyan_cat.engine', -]; -$ignoreErrors[] = [ - 'message' => '#^Function test_subtheme_views_post_render\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/tests/themes/test_subtheme/test_subtheme.theme', -]; -$ignoreErrors[] = [ - 'message' => '#^Function test_subtheme_views_pre_render\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/tests/themes/test_subtheme/test_subtheme.theme', -]; -$ignoreErrors[] = [ 'message' => '#^Function test_theme_depending_on_modules_post_update_module_install\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, @@ -58345,12 +58273,6 @@ $ignoreErrors[] = [ 'path' => __DIR__ . '/themes/claro/claro.theme', ]; $ignoreErrors[] = [ - 'message' => '#^Function claro_views_pre_render\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/themes/claro/claro.theme', -]; -$ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\claro\\\\ClaroPreRender\\:\\:managedFile\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, @@ -58375,18 +58297,6 @@ $ignoreErrors[] = [ 'path' => __DIR__ . '/themes/claro/src/ClaroPreRender.php', ]; $ignoreErrors[] = [ - 'message' => '#^Function twig_extension\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/themes/engines/twig/twig.engine', -]; -$ignoreErrors[] = [ - 'message' => '#^Function twig_render_template\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/themes/engines/twig/twig.engine', -]; -$ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\olivero\\\\OliveroPreRender\\:\\:textFormat\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, diff --git a/core/lib/Drupal/Core/Render/theme.api.php b/core/lib/Drupal/Core/Render/theme.api.php index a43abacddf8..0d3cd45c9ea 100644 --- a/core/lib/Drupal/Core/Render/theme.api.php +++ b/core/lib/Drupal/Core/Render/theme.api.php @@ -556,7 +556,7 @@ function hook_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormSta * @param string $hook * The name of the theme hook. */ -function hook_preprocess(&$variables, $hook) { +function hook_preprocess(&$variables, $hook): void { static $hooks; // Add contextual links to the variables, if the user has permission. @@ -807,7 +807,7 @@ function hook_themes_uninstalled(array $themes): void { * @return string * The file extension the theme engine will recognize. */ -function hook_extension() { +function hook_extension(): string { // Extension for template base names in Twig. return '.html.twig'; } @@ -833,7 +833,7 @@ function hook_extension() { * The output generated from the template. In most cases this will be a string * containing HTML markup. */ -function hook_render_template($template_file, $variables) { +function hook_render_template($template_file, $variables): string|\Stringable { $twig_service = \Drupal::service('twig'); return $twig_service->loadTemplate($template_file)->render($variables); diff --git a/core/modules/comment/src/Hook/CommentHooks.php b/core/modules/comment/src/Hook/CommentHooks.php index 67dcbd6c6e6..196fdf6890b 100644 --- a/core/modules/comment/src/Hook/CommentHooks.php +++ b/core/modules/comment/src/Hook/CommentHooks.php @@ -337,7 +337,7 @@ class CommentHooks { * Implements hook_node_update_index(). */ #[Hook('node_update_index')] - public function nodeUpdateIndex(EntityInterface $node) { + public function nodeUpdateIndex(EntityInterface $node): string { $index_comments =& drupal_static('comment_node_update_index'); if ($index_comments === NULL) { // Do not index in the following three cases: diff --git a/core/modules/contextual/contextual.module b/core/modules/contextual/contextual.module index a875584d1fa..5dcddfab211 100644 --- a/core/modules/contextual/contextual.module +++ b/core/modules/contextual/contextual.module @@ -14,7 +14,7 @@ use Drupal\Core\Language\LanguageInterface; * @see contextual_page_attachments() * @see \Drupal\contextual\ContextualController::render() */ -function contextual_preprocess(&$variables, $hook, $info) { +function contextual_preprocess(&$variables, $hook, $info): void { // Determine the primary theme function argument. if (!empty($info['variables'])) { $keys = array_keys($info['variables']); diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index 9823a2cdac7..dac7282575f 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -315,12 +315,12 @@ function hook_node_search_result(NodeInterface $node): array { * @param \Drupal\node\NodeInterface $node * The node being indexed. * - * @return string + * @return string|\Stringable * Additional node information to be indexed. * * @ingroup entity_crud */ -function hook_node_update_index(NodeInterface $node) { +function hook_node_update_index(NodeInterface $node): string|\Stringable { $text = ''; $ratings = \Drupal::database()->query('SELECT [title], [description] FROM {my_ratings} WHERE [nid] = :nid', [':nid' => $node->id()]); foreach ($ratings as $rating) { diff --git a/core/modules/search/search.api.php b/core/modules/search/search.api.php index 47744998e35..4dfa804d607 100644 --- a/core/modules/search/search.api.php +++ b/core/modules/search/search.api.php @@ -46,7 +46,7 @@ * * @ingroup search */ -function hook_search_preprocess($text, $langcode = NULL) { +function hook_search_preprocess($text, $langcode = NULL): string { // If the language is not set, get it from the language manager. if (!isset($langcode)) { $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); diff --git a/core/modules/search/tests/modules/search_langcode_test/src/Hook/SearchLangcodeTestHooks.php b/core/modules/search/tests/modules/search_langcode_test/src/Hook/SearchLangcodeTestHooks.php index 6b09bde12a9..626d5fe9779 100644 --- a/core/modules/search/tests/modules/search_langcode_test/src/Hook/SearchLangcodeTestHooks.php +++ b/core/modules/search/tests/modules/search_langcode_test/src/Hook/SearchLangcodeTestHooks.php @@ -15,7 +15,7 @@ class SearchLangcodeTestHooks { * Implements hook_search_preprocess(). */ #[Hook('search_preprocess')] - public function searchPreprocess($text, $langcode = NULL) { + public function searchPreprocess($text, $langcode = NULL): string { if (isset($langcode) && $langcode == 'en') { // Add the alternate verb forms for the word "testing". if ($text == 'we are testing') { diff --git a/core/modules/system/tests/modules/deprecation_test/deprecation_test.module b/core/modules/system/tests/modules/deprecation_test/deprecation_test.module index 8ed02e6d043..6e37d3c44b5 100644 --- a/core/modules/system/tests/modules/deprecation_test/deprecation_test.module +++ b/core/modules/system/tests/modules/deprecation_test/deprecation_test.module @@ -27,7 +27,7 @@ function deprecation_test_function() { /** * Implements hook_deprecated_hook(). */ -function deprecation_test_deprecated_hook($arg) { +function deprecation_test_deprecated_hook($arg): mixed { return $arg; } diff --git a/core/modules/system/tests/modules/module_test/module_test.file.inc b/core/modules/system/tests/modules/module_test/module_test.file.inc index df26b1b2339..c0cee6f1905 100644 --- a/core/modules/system/tests/modules/module_test/module_test.file.inc +++ b/core/modules/system/tests/modules/module_test/module_test.file.inc @@ -13,6 +13,6 @@ declare(strict_types=1); /** * Implements hook_test_hook(). */ -function module_test_test_hook() { +function module_test_test_hook(): array { return ['module_test' => 'success!']; } diff --git a/core/modules/system/tests/modules/module_test/module_test.implementations.inc b/core/modules/system/tests/modules/module_test/module_test.implementations.inc index 90c045e3f59..b971af58c8c 100644 --- a/core/modules/system/tests/modules/module_test/module_test.implementations.inc +++ b/core/modules/system/tests/modules/module_test/module_test.implementations.inc @@ -12,6 +12,6 @@ declare(strict_types=1); * * @see module_test_module_implements_alter() */ -function module_test_altered_test_hook() { +function module_test_altered_test_hook(): string { return __FUNCTION__; } diff --git a/core/modules/system/tests/modules/module_test/module_test.module b/core/modules/system/tests/modules/module_test/module_test.module index eb8af1a7dc9..b7f320a35e3 100644 --- a/core/modules/system/tests/modules/module_test/module_test.module +++ b/core/modules/system/tests/modules/module_test/module_test.module @@ -81,7 +81,7 @@ function module_test_load($param) { /** * Implements hook_modules_installed(). */ -function module_test_modules_installed($modules) { +function module_test_modules_installed($modules): void { // Record the ordered list of modules that were passed in to this hook so we // can check that the modules were enabled in the correct sequence. \Drupal::state()->set('module_test.install_order', $modules); @@ -90,7 +90,7 @@ function module_test_modules_installed($modules) { /** * Implements hook_modules_uninstalled(). */ -function module_test_modules_uninstalled($modules) { +function module_test_modules_uninstalled($modules): void { // Record the ordered list of modules that were passed in to this hook so we // can check that the modules were uninstalled in the correct sequence. \Drupal::state()->set('module_test.uninstall_order', $modules); diff --git a/core/modules/system/tests/themes/engines/nyan_cat/nyan_cat.engine b/core/modules/system/tests/themes/engines/nyan_cat/nyan_cat.engine index ec74b2aa163..4c63cf64d5a 100644 --- a/core/modules/system/tests/themes/engines/nyan_cat/nyan_cat.engine +++ b/core/modules/system/tests/themes/engines/nyan_cat/nyan_cat.engine @@ -21,14 +21,14 @@ function nyan_cat_theme($existing, $type, $theme, $path): array { /** * Implements hook_extension(). */ -function nyan_cat_extension() { +function nyan_cat_extension(): string { return '.nyan-cat.html'; } /** * Implements hook_render_template(). */ -function nyan_cat_render_template($template_file, $variables) { +function nyan_cat_render_template($template_file, $variables): string { $output = str_replace('div', 'nyancat', file_get_contents(\Drupal::root() . '/' . $template_file)); foreach ($variables as $key => $variable) { if (str_contains($output, '9' . $key)) { diff --git a/core/modules/system/tests/themes/test_subtheme/test_subtheme.theme b/core/modules/system/tests/themes/test_subtheme/test_subtheme.theme index 36065bfe4ea..d80189e0e63 100644 --- a/core/modules/system/tests/themes/test_subtheme/test_subtheme.theme +++ b/core/modules/system/tests/themes/test_subtheme/test_subtheme.theme @@ -13,7 +13,7 @@ use Drupal\views\ViewExecutable; /** * Implements hook_views_pre_render(). */ -function test_subtheme_views_pre_render(ViewExecutable $view) { +function test_subtheme_views_pre_render(ViewExecutable $view): void { // We append the function name to the title for test to check for. $view->setTitle($view->getTitle() . ":" . __FUNCTION__); } @@ -21,7 +21,7 @@ function test_subtheme_views_pre_render(ViewExecutable $view) { /** * Implements hook_views_post_render(). */ -function test_subtheme_views_post_render(ViewExecutable $view, &$output, CachePluginBase $cache) { +function test_subtheme_views_post_render(ViewExecutable $view, &$output, CachePluginBase $cache): void { // We append the function name to the title for test to check for. $view->setTitle($view->getTitle() . ":" . __FUNCTION__); if ($view->id() == 'test_page_display') { diff --git a/core/modules/views/views.api.php b/core/modules/views/views.api.php index cb62e66c32a..4fbcad6730e 100644 --- a/core/modules/views/views.api.php +++ b/core/modules/views/views.api.php @@ -843,7 +843,7 @@ function hook_views_post_execute(ViewExecutable $view) { * * @see \Drupal\views\ViewExecutable */ -function hook_views_pre_render(ViewExecutable $view) { +function hook_views_pre_render(ViewExecutable $view): void { // Scramble the order of the rows shown on this result page. // Note that this could be done earlier, but not later in the view execution // process. @@ -881,7 +881,7 @@ function hook_views_pre_render(ViewExecutable $view) { * * @see \Drupal\views\ViewExecutable */ -function hook_views_post_render(ViewExecutable $view, array &$output, CachePluginBase $cache) { +function hook_views_post_render(ViewExecutable $view, array &$output, CachePluginBase $cache): void { // When using full pager, disable any time-based caching if there are fewer // than 10 results. if ($view->pager instanceof Full && $cache instanceof Time && count($view->result) < 10) { diff --git a/core/themes/claro/claro.theme b/core/themes/claro/claro.theme index bb2c9034662..c4a95ffbc6c 100644 --- a/core/themes/claro/claro.theme +++ b/core/themes/claro/claro.theme @@ -1605,7 +1605,7 @@ function claro_preprocess_fieldset__media_library_widget(array &$variables): voi /** * Implements hook_views_pre_render(). */ -function claro_views_pre_render(ViewExecutable $view) { +function claro_views_pre_render(ViewExecutable $view): void { $add_classes = function (&$option, array $classes_to_add) { $classes = preg_split('/\s+/', $option); $classes = array_filter($classes); diff --git a/core/themes/engines/twig/twig.engine b/core/themes/engines/twig/twig.engine index bcf68499adf..7ba1c275c64 100644 --- a/core/themes/engines/twig/twig.engine +++ b/core/themes/engines/twig/twig.engine @@ -5,6 +5,7 @@ * Handles integration of Twig templates with the Drupal theme system. */ +use Drupal\Component\Render\MarkupInterface; use Drupal\Component\Utility\Html; use Drupal\Core\Render\Markup; use Twig\Error\RuntimeError; @@ -19,14 +20,14 @@ function twig_theme($existing, $type, $theme, $path): array { /** * Implements hook_extension(). */ -function twig_extension() { +function twig_extension(): string { return '.html.twig'; } /** * Implements hook_render_template(). */ -function twig_render_template($template_file, array $variables) { +function twig_render_template($template_file, array $variables): string|MarkupInterface { /** @var \Twig\Environment $twig_service */ $twig_service = \Drupal::service('twig'); try { |