Skip to content

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

Merged
mglaman merged 7 commits into
mainfrom
feature/945-legacy-hook-attribute-stubs
Sep 18, 2026
Merged

mglaman merged 7 commits into
mainfrom
feature/945-legacy-hook-attribute-stubs

Conversation

@mglaman

@mglaman mglaman commented Apr 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #945

Drupal added LegacyHook, LegacyRequirementsHook, and LegacyModuleImplementsAlter as BC-bridge attributes across different minor versions, and Drupal 12 removes them again (LegacyModuleImplementsAlter is already gone from core main). No supported core version has all three, which puts module maintainers in a bind:

  • 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

This adds ignoreErrors entries to extension.neon, pinned to the attribute.notFound identifier and the exact message, with reportUnmatched: false. The error is suppressed where the class is missing, and there is no unmatched-ignore noise where it exists. Because this lives in the extension, it also covers upgrade_status and anything else that runs phpstan-drupal.

PHPStan stubs don't work here: stubs only override type information for classes that already exist, they can't make a missing class visible to attribute validation.

Test plan

  • php vendor/bin/phpstan analyze passes
  • php vendor/bin/phpunit passes
  • Locally with Drupal 11.4, the fixture is clean at level 9 with reportUnmatchedIgnoredErrors: true, both with all three classes present and with LegacyHook and LegacyModuleImplementsAlter removed
  • Build Integration jobs analyze tests/fixtures/integration/legacy-hook-attributes.php against ^10.4 (none of the classes exist), ~11.3.0, ~11.4.0, and 11.x-dev

🤖 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
mglaman and others added 2 commits September 18, 2026 10:24
Scope each ignore to the attribute.notFound identifier as well as the
message, and document why unmatched ignores are expected. Rename the
integration step and fixture docblock, which still described the stub
approach this PR moved away from, and type the fixture's arrays so it
passes at any level.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mglaman
mglaman merged commit cca32f2 into main Sep 18, 2026
19 of 20 checks passed
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