Skip to content

SONARPHP-1660,SONARPHP-1933 S1172 Fix FP with Laravel implicit route model binding - #1811

Merged
lijun-chen-sonarsource merged 5 commits into
masterfrom
lc/S1172-suppress-laravel
Sep 21, 2026
Merged

lijun-chen-sonarsource merged 5 commits into
masterfrom
lc/S1172-suppress-laravel

Conversation

@lijun-chen-sonarsource

@lijun-chen-sonarsource lijun-chen-sonarsource commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Several user feedback from the rule-feedback-dashboard state that S1172 is not applicable in some Laravel-specific methods.

In some cases, it is possible for users to rename the parameters to $_ so that we don't raise S1172. This work focuses on cases where this escape hatch is not possible.

Do not report unused model parameters that are likely consumed by
Laravel's implicit route model binding, where parameter names have to
correspond to route placeholders for it to work.
Detect also asController and handle methods from Laravel Actions
and suppress model-like parameters also there.

Use local heuristics instead of collecting route registrations. This
avoids extending project-level symbol data and the complexity of resolving
dynamic PHP route declarations, while keeping detection consistent
between normal (full) analysis and SQ IDE.


Stack created with GitHub Stacks CLI • Give Feedback 💬

@lijun-chen-sonarsource
lijun-chen-sonarsource added this pull request to stack #1812 September 17, 2026 07:59
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title S1172 Fix FP with Laravel implicit route model binding SONARPHP-1933 S1172 Fix FP with Laravel implicit route model binding Sep 17, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

SONARPHP-1933

@asya-vorobeva asya-vorobeva left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Base automatically changed from lc/SONARPHP-1619 to master September 18, 2026 14:40
Do not report unused model parameters that are likely consumed by
Laravel's implicit route model binding, where parameter names can
correspond to route placeholders.

Use local heuristics instead of collecting route registrations. This
avoids extending project-level symbol data and the complexity of resolving
dynamic PHP route declarations, while keeping detection consistent
between normal (full) analysis and SQ IDE.
@lijun-chen-sonarsource lijun-chen-sonarsource changed the title SONARPHP-1933 S1172 Fix FP with Laravel implicit route model binding SONARPHP-1660,SONARPHP-1933 S1172 Fix FP with Laravel implicit route model binding Sep 18, 2026
Avoid reporting unused model parameters injected through Laravel Actions
entry points.

Recognize public, non-static `asController` methods and `handle` methods
identified through Laravel Actions traits or conventional `Actions`
namespaces, including inherited action roles.
@gitar-bot

gitar-bot Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Code Review ✅ No issues found 1 closed / 1 findings

🟡 Medium risk · Adds Laravel-specific parameter suppression heuristics across PHP analysis paths

Fixes false positives in S1172 for Laravel implicit route model binding by using local heuristics to detect parameters consumed by Laravel's magic routing, addressing trait detection to properly recognize inherited traits in addition to declaring classes.

✅ 1 closed
✅ Edge Case: Trait detection only looks at the declaring class, not inherited traits

📄 php-checks/src/main/java/org/sonar/php/checks/UnusedFunctionParametersCheck.java:290 📄 php-checks/src/main/java/org/sonar/php/checks/UnusedFunctionParametersCheck.java:293-301 📄 php-checks/src/test/resources/checks/UnusedFunctionParametersCheckLaravelActions.php:127-141
usesLaravelActionTrait only looks at use statements declared directly in the method's class. If AsAction/AsController comes from a parent class (for example abstract class BaseAction { use AsAction; } in App\Support), a subclass's handle(Account $account) is still reported unless some ancestor sits in a namespace containing \actions\. The InheritedAccountHandler test says the action role is inherited from a parent class, but it only passes because BaseAction is in App\Actions. The namespace heuristic is what matches, not the inherited trait. A fix is to walk Symbols.get(owner).allSuperTypes() and check each ancestor's trait usage, or else change the test comment and add a case where the base class is outside an Actions namespace.

Review coverage

🧪 Functional validation No results

📋 Rules No rules evaluated

🤖 Auto-approval Not enabled · Set up

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next

Copy link
Copy Markdown

@lijun-chen-sonarsource
lijun-chen-sonarsource merged commit 33943d2 into master Sep 21, 2026
23 checks passed
@lijun-chen-sonarsource
lijun-chen-sonarsource deleted the lc/S1172-suppress-laravel branch September 21, 2026 09:28
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.

2 participants