Add typehints to hook definitions

Created on 21 August 2021, about 3 years ago
Updated 27 February 2024, 8 months ago

Problem/Motivation

Hooks are documented in *.api.php files. Developers tend to copy hooks from those files or from api.drupal.org which is bullt upon the code documentation. On the other hand drush generate and PhpStorm use these definitions as templates for generating hooks. Unfortunately, the hook definitions largely does not use typehints. As a result developers have to update the generated code manually or just do not use typehints at all.

Proposed resolution

Add proper typehints to hooks in all *.api.php files.
The changes would look like this.

- function hook_contextual_links_view_alter(&$element, $items) {
+ function hook_contextual_links_view_alter(array &$element, array $items): void {

Remaining tasks

Discuss, create a mega patch, review and commit it.

API changes

None.

📌 Task
Status

Active

Version

11.0 🔥

Component
Documentation 

Last updated about 14 hours ago

No maintainer
Created by

🇷🇺Russia Chi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • I think it's a good idea. I've been using type hints in my hook implementations, even if the hook itself doesn't specify types. I'm trying to use stricter coding standards.

Production build 0.71.5 2024