Skip to content

Conversation

@AlexSkrypnyk
Copy link
Member

@AlexSkrypnyk AlexSkrypnyk commented Nov 24, 2025

Summary by CodeRabbit

New Features

  • Parameter naming convention checker now automatically updates docblock @param tags when fixing parameter names to snake_case.

Tests

  • Added test fixtures with various docblock-parameter mismatch scenarios.
  • Added functional and unit tests to verify docblock updates.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 24, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

The changes enhance the ParameterSnakeCaseSniff by adding docblock synchronization capabilities. Two private helper methods locate a function's docblock and update @param tags when parameter names are fixed. Test coverage includes a new fixture with parameter-docblock mismatches and functional/unit tests validating the auto-fix behavior.

Changes

Cohort / File(s) Summary
Sniff Enhancement
src/DrevOps/Sniffs/NamingConventions/ParameterSnakeCaseSniff.php
Added private methods findFunctionDocblock() to locate enclosing function docblocks and fixDocblockParam() to update @param tags. Integrated docblock updates into the parameter renaming auto-fix path.
Test Fixture
tests/Fixtures/ParameterDocblockMismatch.php
New fixture file with class containing six methods and standalone function, each with docblocks featuring mismatched parameter names and edge cases (multiline types, missing tags, complex types).
Functional Test
tests/Functional/ParameterSnakeCaseSniffFunctionalTest.php
Added testPhpcbfFixesDocblockParams() method validating that phpcbf correctly updates both parameter signatures and docblock @param tags to snake_case while preserving complex types and multiline descriptions.
Unit Tests
tests/Unit/ParameterSnakeCaseSniffTest.php
Added testFindFunctionDocblock() test method with providerFindFunctionDocblock() data provider covering docblock discovery for functions with/without docblocks, single-line comments, and methods with visibility modifiers.

Sequence Diagram

sequenceDiagram
    participant CodeSniffer as PHP_CodeSniffer
    participant Sniff as ParameterSnakeCaseSniff
    participant Helper1 as findFunctionDocblock()
    participant Helper2 as fixDocblockParam()
    participant Tokens as Token Stream

    CodeSniffer->>Sniff: Process parameter violation
    activate Sniff
    Sniff->>Sniff: Fix parameter name
    Sniff->>Helper2: fixDocblockParam(oldName, newName)
    activate Helper2
    Helper2->>Helper1: findFunctionDocblock()
    activate Helper1
    Helper1->>Tokens: Scan backwards for docblock
    Tokens-->>Helper1: Docblock position or FALSE
    deactivate Helper1
    
    alt Docblock found
        Helper2->>Tokens: Locate `@param` tags
        Tokens-->>Helper2: `@param` tag positions
        Helper2->>Tokens: Update matching param name
        Tokens-->>Helper2: Success
    else No docblock
        Helper2->>Helper2: Exit early
    end
    deactivate Helper2
    Sniff-->>CodeSniffer: Fix complete
    deactivate Sniff
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

  • Areas requiring extra attention:
    • Logic in findFunctionDocblock() for backward scanning and handling various token types
    • Docblock parsing and @param tag matching in fixDocblockParam() to ensure correct parameter name replacement
    • Edge cases in fixture file (multiline docblocks, mixed valid/invalid params, complex types)
    • Test assertions validating both signature and docblock updates remain synchronized

Possibly related PRs

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/fix-case-docblock

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 094fa98 and eca1a92.

📒 Files selected for processing (4)
  • src/DrevOps/Sniffs/NamingConventions/ParameterSnakeCaseSniff.php (1 hunks)
  • tests/Fixtures/ParameterDocblockMismatch.php (1 hunks)
  • tests/Functional/ParameterSnakeCaseSniffFunctionalTest.php (1 hunks)
  • tests/Unit/ParameterSnakeCaseSniffTest.php (1 hunks)

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (094fa98) to head (eca1a92).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main        #8   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          370       387   +17     
=========================================
+ Hits           370       387   +17     

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

@AlexSkrypnyk AlexSkrypnyk merged commit d5a6b58 into main Nov 24, 2025
9 of 10 checks passed
@AlexSkrypnyk AlexSkrypnyk deleted the feature/fix-case-docblock branch November 24, 2025 05:43
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.

3 participants