SONARPHP-1806 Fix S117 FP and S116 FN on PHP 8 constructor property promotion#1674
SONARPHP-1806 Fix S117 FP and S116 FN on PHP 8 constructor property promotion#1674karim-ouerghemmi-sonarsource wants to merge 3 commits intomasterfrom
Conversation
SummaryThis PR fixes two issues with PHP 8 constructor property promotion:
Both fixes are minimal and surgical: they add a check for What reviewers should knowWhere to start:
Key points:
No gotchas: the fix is additive and focused — no existing behavior is changed beyond fixing the two reported issues.
|
…romotion S117 was raising false positives on promoted constructor properties by treating them as regular parameters. S116 was missing them entirely since it only visited CLASS_PROPERTY_DECLARATION nodes. - S117: skip parameters where isPropertyPromotion() is true; their naming is governed by S116 (FieldNameCheck) - S116: also visit METHOD_DECLARATION nodes and check promoted constructor parameters against the field naming pattern Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
b3dd59d to
84ce3bd
Compare
…HP 8.5) isPropertyPromotion() also returns true when finalToken() != null. Add test cases for final-only (no visibility modifier) promoted properties to cover this path in both S116 and S117. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|




Summary
LocalVariableAndParameterNameCheckwas checking promoted constructor properties as regular parameters. Fixed by skipping parameters whereisPropertyPromotion()is true — their naming is governed by S116 instead.FieldNameCheckonly visitedCLASS_PROPERTY_DECLARATIONnodes, missing promoted properties entirely. Fixed by also visitingMETHOD_DECLARATIONnodes and checking promoted constructor parameters against the field naming pattern.Fixes: https://sonarsource.atlassian.net/browse/SONARPHP-1806
Test plan
FieldNameCheckTest— default and custom format tests pass, including new promoted property casesLocalVariableAndParameterNameCheckTest— default and custom format tests pass, promoted properties no longer flagged