fix(attribute): Update value() method in HasValue trait to accept boolean values and adjust related tests and data provider.#80
Conversation
… boolean values and adjust related tests and data provider.
📝 WalkthroughSummary by CodeRabbit
WalkthroughExtends the HasValue trait's value() parameter to accept boolean values; updates docblock and example, adjusts test signatures and the ValueProvider with two boolean test cases, and adds a changelog entry documenting the change. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
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
🤖 Fix all issues with AI agents
In `@src/HasValue.php`:
- Around line 29-30: Update the docblock for the $value parameter in
HasValue.php so the prose matches the union type: include "Stringable" and
"UnitEnum" in the descriptive text (e.g., "bool, int, float, string, Stringable,
UnitEnum, or null to remove the attribute") for the parameter $value in the
HasValue trait/method.
📜 Review details
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (4)
CHANGELOG.mdsrc/HasValue.phptests/HasValueTest.phptests/Provider/ValueProvider.php
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-01-09T16:05:15.502Z
Learnt from: terabytesoftw
Repo: ui-awesome/html-attribute PR: 18
File: tests/Support/Provider/Global/ContentEditableProvider.php:32-33
Timestamp: 2026-01-09T16:05:15.502Z
Learning: Preserve the original copyright year in file headers when moving PHP source files between packages within the ui-awesome repositories (e.g., from ui-awesome/html-core to ui-awesome/html-attribute). Do not update the header year to the current year; keep the original creation year as stated in the header. This applies to all PHP files throughout the repo that are moved between packages.
Applied to files:
src/HasValue.phptests/HasValueTest.phptests/Provider/ValueProvider.php
📚 Learning: 2026-02-07T13:44:00.931Z
Learnt from: terabytesoftw
Repo: ui-awesome/html-attribute PR: 78
File: tests/Global/HasDirTest.php:92-92
Timestamp: 2026-02-07T13:44:00.931Z
Learning: In PHP test methods that start with testThrowInvalidArgumentException, do not append 'Invalid' again in the method name suffix (e.g., prefer testThrowInvalidArgumentExceptionForSettingDirValue over testThrowInvalidArgumentExceptionForSettingInvalidDirValue). The exception type already communicates invalid input, so the repeated word is redundant. Apply this convention to all similar test methods under the tests/ directory.
Applied to files:
tests/HasValueTest.phptests/Provider/ValueProvider.php
🧬 Code graph analysis (1)
tests/HasValueTest.php (1)
src/HasValue.php (1)
value(44-47)
⏰ 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). (6)
- GitHub Check: phpstan / PHP 8.5-ubuntu-latest
- GitHub Check: mutation / PHP 8.5-ubuntu-latest
- GitHub Check: linter / Super Linter
- GitHub Check: phpunit / PHP 8.1-windows-2022
- GitHub Check: phpunit / PHP 8.5-ubuntu-latest
- GitHub Check: phpunit / PHP 8.4-windows-2022
🔇 Additional comments (5)
src/HasValue.php (1)
44-47: Type expansion looks correct.The
booladdition to the union type is consistent with the docblock, usage examples, and test data provider.CHANGELOG.md (1)
53-53: LGTM!Changelog entry follows the established format and accurately describes the change.
tests/Provider/ValueProvider.php (2)
43-56: Boolean test cases look well-structured.The
false→ empty render andtrue→' value'(boolean HTML attribute) pattern correctly follows HTML boolean attribute semantics.
24-30: PHPStan type annotation updated correctly.Removing
nullfrom the third tuple position is accurate — all data entries use a non-null expected value (thenullinput cases expect''as the resolved value).tests/HasValueTest.php (1)
64-70: Test method signature correctly expanded to accept boolean types.The type unions for
$valueand$expectedValueare consistent with both the trait's updated signature and the data provider's new boolean entries.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/HasValue.php`:
- Line 35: The docblock for HasValue::value currently shows only
$element->value(true); add a complementary example using $element->value(false)
that demonstrates the different string/casting behavior (e.g. that false yields
an empty string or other expected output) so users can see both cases; update
the docblock examples in HasValue.php near the existing value(true) example and
make the expected returned/printed representation for value(false) explicit.
📜 Review details
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
src/HasValue.php
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-01-09T16:05:15.502Z
Learnt from: terabytesoftw
Repo: ui-awesome/html-attribute PR: 18
File: tests/Support/Provider/Global/ContentEditableProvider.php:32-33
Timestamp: 2026-01-09T16:05:15.502Z
Learning: Preserve the original copyright year in file headers when moving PHP source files between packages within the ui-awesome repositories (e.g., from ui-awesome/html-core to ui-awesome/html-attribute). Do not update the header year to the current year; keep the original creation year as stated in the header. This applies to all PHP files throughout the repo that are moved between packages.
Applied to files:
src/HasValue.php
⏰ 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). (12)
- GitHub Check: mutation / PHP 8.5-ubuntu-latest
- GitHub Check: phpunit / PHP 8.4-ubuntu-latest
- GitHub Check: phpunit / PHP 8.3-windows-2022
- GitHub Check: phpunit / PHP 8.5-windows-2022
- GitHub Check: phpunit / PHP 8.1-windows-2022
- GitHub Check: phpunit / PHP 8.5-ubuntu-latest
- GitHub Check: phpunit / PHP 8.1-ubuntu-latest
- GitHub Check: phpunit / PHP 8.4-windows-2022
- GitHub Check: phpunit / PHP 8.2-windows-2022
- GitHub Check: phpunit / PHP 8.3-ubuntu-latest
- GitHub Check: linter / Super Linter
- GitHub Check: linter / Super Linter
🔇 Additional comments (1)
src/HasValue.php (1)
24-47: Reconsider accepting boolean values for thevalueattribute — it renders as a boolean attribute, which is semantically incorrect for a content attribute.The test data confirms that
truerenders as a valueless attribute (value) andfalseremoves the attribute entirely. While this behavior is intentional (handled by the downstream attribute rendering), it's semantically wrong for thevalueattribute, which is a content attribute meant to hold actual values (strings, numbers, etc.), not a boolean flag likedisabledorchecked.Either remove
boolfrom the type signature, or add explicit documentation in the docblock explaining that boolean values render as HTML boolean attributes (e.g.,true→value,false→ attribute removed).
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
Pull Request