Skip to content

Add FunctionParameterAssignment sniff - #117

Merged
aik099 merged 1 commit into
masterfrom
feature/function-parameter-assignment-sniff
Jul 23, 2026
Merged

Add FunctionParameterAssignment sniff#117
aik099 merged 1 commit into
masterfrom
feature/function-parameter-assignment-sniff

Conversation

@aik099

@aik099 aik099 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds CodingStandard.CodeAnalysis.FunctionParameterAssignment, which warns when a function/method parameter not passed by reference is reassigned inside the function body — code reading the parameter afterwards would otherwise see the last-assigned value instead of the original argument.
  • Reports one warning per assignment occurrence (not just the first), so all offending lines are visible for a given parameter.
  • Abstract methods and interface methods (no body) are skipped, since there's nothing to analyze.

Test plan

  • vendor/bin/phpunit CodingStandard/Tests/CodeAnalysis/FunctionParameterAssignmentUnitTest.php
  • vendor/bin/phpunit (full suite, 30/30 passing)

Closes #104

Warns when a non-by-reference function/method parameter's value is
reassigned within the function body, since callers reading the
parameter later would see the last-assigned value instead of the
originally passed one.

Closes #104
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.72%. Comparing base (1ba8f6b) to head (3bb353d).

Files with missing lines Patch % Lines
.../CodeAnalysis/FunctionParameterAssignmentSniff.php 96.42% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #117      +/-   ##
============================================
- Coverage     97.74%   97.72%   -0.03%     
- Complexity      502      513      +11     
============================================
  Files            29       30       +1     
  Lines          1465     1493      +28     
============================================
+ Hits           1432     1459      +27     
- Misses           33       34       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aik099
aik099 merged commit 35d8c38 into master Jul 23, 2026
16 of 19 checks passed
@aik099
aik099 deleted the feature/function-parameter-assignment-sniff branch July 26, 2026 17:15
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.

Create function parameter assignment sniff

1 participant