Fix #124: Validate empty tag name in widget setters - #158
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #158 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 316 316
===========================================
Files 8 8
Lines 1005 1005
===========================================
Hits 1005 1005 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThis PR enforces empty HTML tag name validation at the setter level across three widget classes (Alert, Dropdown, Menu), moving validation from render-time to construction-time. Dropdowns and Menus gain Psalm type annotations and setter validation; render methods lose redundant checks. Tests are updated to call setters directly and use non-empty values in immutability assertions. ChangesEmpty tag name validation enforcement
Possibly related issues
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 PHPStan (2.1.55)PHP Parse error: syntax error, unexpected token "->", expecting ";" in /vendor/php-standard-library/php-standard-library/packages/class/src/Psl/Class/has_constant.php on line 18 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 |
What does this PR do?
Validates empty tag names in the setters of
Alert,Dropdown, andMenuso an empty string fails fast withInvalidArgumentExceptioninstead of slipping through to render time.Before this, the tag setters in
DropdownandMenuaccepted any string and only blew up later inside the render methods. The check now lives in the setter, next to the value it rejects, which matches whatAlert::bodyTag()andBreadcrumbs::containerTag()already do.Alert::headerTag()usedempty(), which also rejected the string"0"- a valid, if odd, tag name - so it now uses a strict=== ''check.With the setters guarding the value, the tag properties are annotated
non-empty-string(the typeHtml::normalTag()expects), so the old render-time checks are redundant and removed.Menu::tagName()had the same render-time check as the rest, so it's included here too even though the issue didn't list it.Breadcrumbs::tag()is left alone on purpose: there an empty string means "don't render a wrapping tag", so it's a real option, not a mistake.The exception type and message are unchanged. An empty tag never produced valid markup: for tags that always render it already threw at
render(), and for the conditionally rendered ones (a divider, a sub-dropdown header, abefore/afterwrapper) it used to slip by as dead configuration until that branch was hit. Both cases now fail at the setter. This is the fail-fast behaviorAlertandBreadcrumbs::containerTag()already had.Summary by CodeRabbit
Bug Fixes
Tests