-
-
Notifications
You must be signed in to change notification settings - Fork 0
[#13] Fixed nullable class properties incorrectly triggering LocalVariableNaming.NotSnakeCase.
#14
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
…riableNaming.NotSnakeCase`.
📝 WalkthroughWalkthroughThe PR addresses a false positive where nullable class properties with fully-qualified namespaced types incorrectly triggered the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 409 415 +6
=========================================
+ Hits 409 415 +6 ☔ View full report in Codecov by Sentry. |
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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (3)
src/DrevOps/Sniffs/NamingConventions/AbstractVariableNamingSniff.php(2 hunks)tests/Fixtures/VariableNaming.php(2 hunks)tests/Unit/AbstractVariableNamingSniffTest.php(2 hunks)
🧰 Additional context used
🪛 PHPMD (2.15.0)
tests/Fixtures/VariableNaming.php
74-74: Avoid excessively long variable names like $promotedNullableProperty. Keep variable name length under 20. (undefined)
(LongVariable)
🔇 Additional comments (4)
src/DrevOps/Sniffs/NamingConventions/AbstractVariableNamingSniff.php (2)
314-317: LGTM! Correct fix for namespaced type handling.The addition of PHP 8+ namespaced type tokens (T_NAME_FULLY_QUALIFIED, T_NAME_QUALIFIED, T_NAME_RELATIVE) properly extends property detection to handle fully-qualified and namespace-qualified types like
\DOMDocumentorSome\Type. This directly addresses the false positive reported in issue #13.
408-411: LGTM! Consistent token handling for promoted properties.The same token additions applied to
isPromotedPropertyensure consistent behavior for PHP 8.0+ constructor property promotion with namespaced types. This maintains parity with theisPropertyfix.tests/Unit/AbstractVariableNamingSniffTest.php (1)
264-283: LGTM! Comprehensive test coverage for the fix.The new test cases thoroughly validate property detection for typed and nullable properties across multiple scenarios:
- Simple types with nullable (
?string)- Fully-qualified namespaced types (
?\DOMDocument)- Namespace-qualified types (
?Some\Type)- Promoted property variants
This coverage directly validates the fix for issue #13 and guards against regressions.
Also applies to: 351-360
tests/Fixtures/VariableNaming.php (1)
17-21: LGTM! Fixtures validate nullable property scenarios.The three new nullable property declarations effectively test the fix for issue #13, covering both simple nullable types (
?string) and fully-qualified namespaced nullable types (?\DOMDocument,?\DateTime).
| public function __construct( | ||
| public string $promotedPropertyOne, | ||
| public string $promoted_property_two, | ||
| public ?\DOMDocument $promotedNullableProperty = NULL, |
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.
🧹 Nitpick | 🔵 Trivial
Consider shortening the variable name.
PHPMD flags $promotedNullableProperty as exceeding the recommended 20-character limit (26 characters). While this is test fixture code and the name is descriptive, consider a shorter alternative like $promotedNullableDom or $nullableDom for better readability.
Based on learnings from static analysis hints.
🧰 Tools
🪛 PHPMD (2.15.0)
74-74: Avoid excessively long variable names like $promotedNullableProperty. Keep variable name length under 20. (undefined)
(LongVariable)
🤖 Prompt for AI Agents
In tests/Fixtures/VariableNaming.php around line 74, the property name
$promotedNullableProperty is too long per PHPMD; shorten it (for example to
$promotedNullableDom or $nullableDom) and update every occurrence in this file
(constructor promotion, any references, docblocks) so the type and nullability
remain the same (\DOMDocument|null). Ensure consistency by renaming usages in
related tests/fixtures if referenced elsewhere.
Closes #13
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.