feat(helper): Add generic PHPStan annotations to Reflector for typed attribute inference in consumers.#10
Conversation
…d attribute inference in consumers.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (1)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🧰 Additional context used🧠 Learnings (1)📓 Common learnings🔇 Additional comments (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdded PHPStan generic annotations to Reflector docblocks (introducing template parameter TAttribute and conditional return shapes) and updated the changelog; no runtime signatures or behavior were changed. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@CHANGELOG.md`:
- Around line 3-7: Update the duplicate version header in the changelog: change
the "## 0.2.1 Under development" header to a new in-development version (e.g.,
"## 0.2.2 Under development") so it no longer conflicts with the released "##
0.2.1 March 3, 2026" entry; locate the string "## 0.2.1 Under development" in
CHANGELOG.md and edit it to the next appropriate version.
ℹ️ Review info
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
CHANGELOG.mdsrc/Reflector.php
📜 Review details
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: terabytesoftw
Repo: php-forge/helper PR: 9
File: tests/ReflectorTest.php:289-323
Timestamp: 2026-03-03T13:45:26.874Z
Learning: In the php-forge/helper repository, the Reflector helper's `propertyTypeNames()` method returns type names in a specific order, and tests intentionally use `assertSame` (rather than order-independent assertions) to verify this exact order is preserved for DNF, union, and intersection type declarations.
Learnt from: terabytesoftw
Repo: php-forge/foxy PR: 115
File: tests/Fallback/AssetFallbackTest.php:158-189
Timestamp: 2026-01-23T11:22:07.261Z
Learning: User terabytesoftw prefers not to use aliases when importing classes in PHP. They are comfortable with either fully-qualified class names or direct imports without aliases.
Learnt from: terabytesoftw
Repo: php-forge/support PR: 12
File: src/TestSupport.php:0-0
Timestamp: 2025-08-18T20:13:33.518Z
Learning: User terabytesoftw prefers clean trait-based designs over maintaining backward compatibility wrappers when refactoring utility classes in the php-forge/support project.
Learnt from: terabytesoftw
Repo: php-forge/actions PR: 65
File: .github/workflows/composer-require-checker.yml:80-83
Timestamp: 2025-09-28T15:12:48.345Z
Learning: The user terabytesoftw prefers using floating tags like v1 for third-party actions in GitHub workflows instead of pinning to specific commit SHAs, even when it's a security best practice to pin to immutable commits.
📚 Learning: 2026-03-03T13:45:26.874Z
Learnt from: terabytesoftw
Repo: php-forge/helper PR: 9
File: tests/ReflectorTest.php:289-323
Timestamp: 2026-03-03T13:45:26.874Z
Learning: In the php-forge/helper repository, the Reflector helper's `propertyTypeNames()` method returns type names in a specific order, and tests intentionally use `assertSame` (rather than order-independent assertions) to verify this exact order is preserved for DNF, union, and intersection type declarations.
Applied to files:
src/Reflector.php
🔇 Additional comments (4)
src/Reflector.php (4)
74-77: Well-structured PHPStan generic annotations.The conditional return type correctly describes the typed behavior based on whether
$attributeis provided. This enables proper type inference for consumers.
116-120: Correct generic annotation for typed attribute retrieval.The return type
TAttribute|nullaccurately reflects the method behavior, enabling consumers to get proper type inference when retrieving specific attribute instances.
214-217: Appropriate conditional return type for instantiated attributes.The annotation correctly differentiates between returning
list<object>when unfiltered andlist<TAttribute>when a specific attribute class is provided.
247-250: Consistent annotation pattern withclassAttributes.The PHPStan annotation follows the same conditional type pattern, providing symmetric behavior for property-level attribute retrieval.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 63 63
===========================================
Files 5 5
Lines 164 164
===========================================
Hits 164 164 ☔ View full report in Codecov by Sentry. |
Pull Request