fix: make HasAttributes::attributes() update existing attributes and add replaceAttributes() for full replacement.#61
Conversation
…d add `replaceAttributes()` for full replacement.
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe pull request changes Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
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)
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. Review rate limit: 0/1 reviews remaining, refill in 51 minutes and 42 seconds.Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 57 58 +1
===========================================
Files 8 8
Lines 172 176 +4
===========================================
+ Hits 172 176 +4 ☔ View full report in Codecov by Sentry. |
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 `@tests/HasAttributesTest.php`:
- Around line 103-120: The test testAttributesMergeExistingValues on the
anonymous class using HasAttributes currently verifies additive merges but not
overwriting; call the attributes() method again with a changed value for an
existing key (e.g., attributes(['class' => 'new-class'])) and add an assertion
using getAttributes() to confirm the 'class' value was updated (overwritten)
rather than duplicated or left unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 68dacb91-6d31-4f0c-b35e-06b17dbedf48
📒 Files selected for processing (4)
CHANGELOG.mdUPGRADE.mdsrc/HasAttributes.phptests/HasAttributesTest.php
📜 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). (11)
- GitHub Check: phpunit / PHP 8.3-ubuntu-latest
- GitHub Check: phpunit / PHP 8.5-windows-2022
- GitHub Check: phpunit / PHP 8.4-windows-2022
- GitHub Check: phpunit / PHP 8.3-windows-2022
- GitHub Check: phpunit / PHP 8.5-ubuntu-latest
- GitHub Check: phpunit / PHP 8.4-ubuntu-latest
- 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.4-windows-2022
- GitHub Check: linter / Super Linter
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: terabytesoftw
Repo: ui-awesome/html-mixin PR: 59
File: src/HasAttributes.php:35-38
Timestamp: 2026-04-27T22:31:34.763Z
Learning: In `ui-awesome/html-mixin` (`src/HasAttributes.php`), `addAttribute(string|UnitEnum $key, mixed $value): static` is the intentional public single-attribute API. Setting `$value` to `null` is documented as removing the attribute, mirroring the package-wide attribute convention. `setAttribute()` is kept `private` as an internal helper because it additionally supports a `$prefix` parameter used by internal fluent setters; it is not part of the public API. Do not suggest renaming or restructuring this distinction.
Learnt from: terabytesoftw
Repo: ui-awesome/html-mixin PR: 59
File: CHANGELOG.md:6-6
Timestamp: 2026-04-27T22:30:59.331Z
Learning: In the `ui-awesome/html-mixin` repository, the maintainer (terabytesoftw) does not want "BC break" or "breaking changes" language in `CHANGELOG.md` entries for `0.x` pre-stable releases. API changes during this phase are considered expected and do not need explicit BC-break callouts in the changelog.
📚 Learning: 2026-04-27T22:27:32.815Z
Learnt from: terabytesoftw
Repo: ui-awesome/html-mixin PR: 59
File: composer.json:14-15
Timestamp: 2026-04-27T22:27:32.815Z
Learning: In the `ui-awesome/html-mixin` repository (`composer.json`), the production dependency `ui-awesome/html-helper` intentionally uses a `dev` stability flag (e.g., `^0.8dev`) during pre-stable development phases before a stable tagged release is available. This is expected and should not be flagged as an issue while the package is in active pre-release development (branch alias `0.5.x-dev`).
Applied to files:
CHANGELOG.md
📚 Learning: 2026-04-27T22:30:59.331Z
Learnt from: terabytesoftw
Repo: ui-awesome/html-mixin PR: 59
File: CHANGELOG.md:6-6
Timestamp: 2026-04-27T22:30:59.331Z
Learning: In the `ui-awesome/html-mixin` repository, the maintainer (terabytesoftw) does not want "BC break" or "breaking changes" language in `CHANGELOG.md` entries for `0.x` pre-stable releases. API changes during this phase are considered expected and do not need explicit BC-break callouts in the changelog.
Applied to files:
CHANGELOG.md
📚 Learning: 2026-04-27T22:31:34.763Z
Learnt from: terabytesoftw
Repo: ui-awesome/html-mixin PR: 59
File: src/HasAttributes.php:35-38
Timestamp: 2026-04-27T22:31:34.763Z
Learning: In `ui-awesome/html-mixin` (`src/HasAttributes.php`), `addAttribute(string|UnitEnum $key, mixed $value): static` is the intentional public single-attribute API. Setting `$value` to `null` is documented as removing the attribute, mirroring the package-wide attribute convention. `setAttribute()` is kept `private` as an internal helper because it additionally supports a `$prefix` parameter used by internal fluent setters; it is not part of the public API. Do not suggest renaming or restructuring this distinction.
Applied to files:
CHANGELOG.mdsrc/HasAttributes.phptests/HasAttributesTest.php
🪛 PHPMD (2.15.0)
src/HasAttributes.php
[error] 100-100: Avoid using static access to class '\UIAwesome\Html\Helper\AttributeBag' in method 'replaceAttributes'. (undefined)
(StaticAccess)
[error] 135-135: Avoid using static access to class '\UIAwesome\Html\Helper\AttributeBag' in method 'setAttributes'. (undefined)
(StaticAccess)
🔇 Additional comments (4)
src/HasAttributes.php (1)
45-48: Clean semantic split between merge and replace APIs.
attributes()now clearly maps to merge/update semantics viasetMany(), whilereplaceAttributes()provides explicit full replacement with preserved immutability. This matches the PR objective and keeps the trait API predictable.Also applies to: 96-103, 131-136
UPGRADE.md (1)
7-8: Upgrade guidance is clear and actionable.The migration note correctly explains the behavior change and points users to
replaceAttributes()for prior replacement semantics.CHANGELOG.md (1)
9-9: Changelog entry is concise and aligned with the code change.The note captures both the behavioral adjustment and the new explicit replacement API.
tests/HasAttributesTest.php (1)
249-268: Great coverage for explicit replacement + immutability.The new replacement test and the extra new-instance assertion close the behavioral gap introduced by
replaceAttributes().Also applies to: 292-296
|
@coderabbitai approve |
✅ Actions performedComments resolved and changes approved. |
Pull Request