-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add support for skipping anonymous classes in DocBlock processing #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds detection of anonymous classes to DocBlockHeaderFixer by introducing a private helper that backtracks tokens (skipping whitespace and attributes) to detect a preceding T_NEW; applyFix now skips injecting docblocks for anonymous class definitions. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant F as DocBlockHeaderFixer
participant T as Tokens
participant C as Class Token
rect rgba(235,245,255,0.6)
Note over F: iterate tokens
F->>T: fetch next token
alt token is T_CLASS
F->>F: isAnonymousClass(T, index)
alt isAnonymousClass == true
Note right of C: Detected T_NEW before class (anonymous)
F-->>T: continue (skip docblock)
else isAnonymousClass == false
Note right of C: Regular class detected
F->>T: insert/adjust docblock before class
end
else other token
F-->>T: continue
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Pull Request Test Coverage Report for Build 18163462314Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Rules/DocBlockHeaderFixer.php
(1 hunks)
🔇 Additional comments (1)
src/Rules/DocBlockHeaderFixer.php (1)
124-127
: LGTM! Proper guard for anonymous classes.The guard correctly identifies and skips anonymous classes before processing. The check is appropriately limited to
T_CLASS
tokens since interfaces, traits, and enums cannot be anonymous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/src/Rules/DocBlockHeaderFixerTest.php (1)
849-952
: Consider adding a test for anonymous classes with modifiers.While the existing tests provide solid coverage, consider adding a test case for anonymous classes with modifiers like
new readonly class {}
ornew final class {}
to ensure the modifier-skipping logic works correctly.Example test:
public function testIsAnonymousClassWithModifier(): void { $code = '<?php $obj = new readonly class {};'; $tokens = Tokens::fromCode($code); $method = new ReflectionMethod($this->fixer, 'isAnonymousClass'); // Find the class token index $classIndex = null; for ($i = 0; $i < $tokens->count(); ++$i) { if ($tokens[$i]->isGivenKind(T_CLASS)) { $classIndex = $i; break; } } $result = $method->invoke($this->fixer, $tokens, $classIndex); self::assertTrue($result); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/Rules/DocBlockHeaderFixer.php
(1 hunks)tests/src/Rules/DocBlockHeaderFixerTest.php
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/src/Rules/DocBlockHeaderFixerTest.php (1)
src/Rules/DocBlockHeaderFixer.php (1)
configure
(105-108)
🔇 Additional comments (6)
src/Rules/DocBlockHeaderFixer.php (1)
124-127
: LGTM!The guard correctly skips anonymous classes while processing only T_CLASS tokens, which is appropriate since interfaces, traits, and enums cannot be anonymous in PHP.
tests/src/Rules/DocBlockHeaderFixerTest.php (5)
849-866
: LGTM!The test correctly verifies that anonymous classes are skipped and remain unmodified when the fixer is applied.
868-889
: LGTM!This test effectively verifies that the fixer correctly distinguishes between regular and anonymous classes, processing only the former.
891-910
: LGTM!The test properly validates the
isAnonymousClass
helper method's ability to detect anonymous classes.
912-931
: LGTM!This negative test case properly validates that regular classes are not incorrectly identified as anonymous.
933-952
: LGTM!This test covers an important edge case—anonymous classes with attributes—ensuring the backward token traversal correctly handles attribute syntax.
Summary by CodeRabbit
Bug Fixes
Tests