Skip to content

Ignore missing legacy hook BC attributes (LegacyHook, LegacyRequirementsHook, LegacyModuleImplementsAlter)#967

Open
mglaman wants to merge 5 commits intomainfrom
feature/945-legacy-hook-attribute-stubs
Open

Ignore missing legacy hook BC attributes (LegacyHook, LegacyRequirementsHook, LegacyModuleImplementsAlter)#967
mglaman wants to merge 5 commits intomainfrom
feature/945-legacy-hook-attribute-stubs

Conversation

@mglaman
Copy link
Copy Markdown
Owner

@mglaman mglaman commented Apr 9, 2026

Summary

Closes #945

Drupal added LegacyHook, LegacyRequirementsHook, and LegacyModuleImplementsAlter as BC-bridge attributes across different minor versions, and LegacyHook is being removed in Drupal 12. This creates an impossible situation for module maintainers:

  • On Drupal versions where the class doesn't exist, PHPStan reports "Attribute class X does not exist"
  • If they add @phpstan-ignore to suppress that, PHPStan reports "Unused ignore" on versions where the class does exist

The fix adds ignoreErrors entries with reportUnmatched: false in extension.neon for each attribute. This suppresses the error when the class is missing, and stays silent (no "unused ignore" noise) when the class is present.

Note: PHPStan stubs were considered but don't work here — stubs only override type information for classes that already exist; they can't make missing classes visible to attribute validation.

Test plan

  • php vendor/bin/phpstan analyze passes
  • php vendor/bin/phpunit passes
  • Integration CI jobs scan tests/fixtures/integration/legacy-hook-attributes.php against real Drupal installations (^10.4, ~11.2.0, ~11.3.0, 11.x-dev), verifying no errors are reported across all versions

🤖 Generated with Claude Code

mglaman and others added 5 commits April 9, 2026 10:18
LegacyHook, LegacyRequirementsHook, and LegacyModuleImplementsAlter were
added across different Drupal minor versions and LegacyHook is being removed
in Drupal 12. Without stubs, PHPStan reports "class not found" errors against
Drupal versions where these attributes don't exist, and "unused ignore" errors
against versions where they do. Providing stubs makes these classes always
available to PHPStan regardless of the installed Drupal version.

Closes #945

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The test would pass even without the stubs because the fixture classes in
tests/fixtures/drupal/ are always present, and TypeInferenceTestCase does
not surface unknown class errors. StubTest already validates stub
well-formedness; integration coverage comes from the build_integration CI
jobs running against real Drupal installations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a fixture PHP file using LegacyHook, LegacyRequirementsHook, and
LegacyModuleImplementsAlter, and scans it in both build_integration jobs
across all Drupal version matrix entries. Against Drupal 10.4 these
classes don't exist in the installed package, so this verifies the stubs
make them available regardless of Drupal version.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy the fixture into the Drupal directory before analysing rather than
passing an absolute workspace path to PHPStan, which failed to resolve it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
PHPStan stubs only override type information for existing classes; they
cannot make missing classes available for attribute validation. The
integration tests confirmed this — attribute class errors still fired
on Drupal 10.4 where the classes don't exist.

Instead, add ignoreErrors entries with reportUnmatched: false so the
suppression is silent on Drupal versions where the classes do exist,
avoiding the "unused ignore" problem the issue describes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mglaman mglaman changed the title Add stubs for legacy hook BC attributes (LegacyHook, LegacyRequirementsHook, LegacyModuleImplementsAlter) Ignore missing legacy hook BC attributes (LegacyHook, LegacyRequirementsHook, LegacyModuleImplementsAlter) Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ignore legacy hook related attributes

1 participant