Skip to content

Include constant name in deprecation message when a description exists - #201

Open
mglaman wants to merge 1 commit into
phpstan:2.0.xfrom
mglaman:fix-deprecated-const-message
Open

Include constant name in deprecation message when a description exists#201
mglaman wants to merge 1 commit into
phpstan:2.0.xfrom
mglaman:fix-deprecated-const-message

Conversation

@mglaman

@mglaman mglaman commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

FetchingDeprecatedConstRule passes the deprecation description to sprintf() as the format string:

RuleErrorBuilder::message(sprintf(
    $constantReflection->getDeprecatedDescription() ?? 'Use of constant %s is deprecated.',
    $constantReflection->getName(),
))

The %s placeholder for the constant name only exists in the fallback message, so any constant documented with @deprecated text reports the description alone. Analyzing Drupal code that uses REQUIREMENT_ERROR produces:

in drupal:11.2.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Extension\Requirement\RequirementSeverity::Error instead.

There is no way to tell which constant triggered it, which is a problem when a single line fetches several deprecated constants.

This formats the message the way the other deprecation checks do (RestrictedDeprecatedFunctionUsageExtension, RestrictedDeprecatedClassConstantUsageExtension) — name first, description on the next line:

Use of constant REQUIREMENT_ERROR is deprecated:
in drupal:11.2.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Extension\Requirement\RequirementSeverity::Error instead.

Messages for constants without a description are unchanged. Added a test covering the described case.

🤖 Generated with Claude Code

The deprecation description was passed to sprintf() as the format
string, so the %s placeholder for the constant name only existed in
the fallback message. Any constant documented with @deprecated text
reported just that text, with no indication of which constant was
used.

Format the message like the other deprecation checks do: name first,
description on the following line.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@staabm
staabm requested a review from VincentLanglet July 30, 2026 14:53
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.

1 participant