Skip to content

fix: make HasAttributes::attributes() update existing attributes and add replaceAttributes() for full replacement.#61

Merged
terabytesoftw merged 2 commits intomainfrom
fix-mini-19
Apr 30, 2026
Merged

fix: make HasAttributes::attributes() update existing attributes and add replaceAttributes() for full replacement.#61
terabytesoftw merged 2 commits intomainfrom
fix-mini-19

Conversation

@terabytesoftw
Copy link
Copy Markdown
Contributor

Pull Request

Q A
Is bugfix? ✔️
New feature?
Breaks BC? ✔️

…d add `replaceAttributes()` for full replacement.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@terabytesoftw has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 51 minutes and 42 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0c7d2f7c-d5c3-4567-9821-e2e4a2f7f643

📥 Commits

Reviewing files that changed from the base of the PR and between 813e123 and 48df2ea.

📒 Files selected for processing (1)
  • tests/HasAttributesTest.php
📝 Walkthrough

Walkthrough

The pull request changes HasAttributes::attributes() from replacing all attributes to merging new attributes with existing ones. A new replaceAttributes() method is introduced to provide full replacement semantics. Documentation and tests are updated to reflect this behavioral change.

Changes

Cohort / File(s) Summary
Documentation Updates
CHANGELOG.md, UPGRADE.md
Version 0.5.1 documentation added explaining the behavioral change in attributes() (now merges instead of replaces) and the new replaceAttributes() API.
Core Implementation
src/HasAttributes.php
attributes() now uses AttributeBag::setMany for merge semantics instead of replace semantics; new public method replaceAttributes() added for full attribute replacement; docblocks updated accordingly.
Test Coverage
tests/HasAttributesTest.php
Tests updated to verify merge behavior: removed replacement-validation test, added merge and replaceAttributes() tests; existing prefixed attribute and immutability tests adjusted to match new semantics.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

bug

Poem

🐰 Attributes now blend instead of disappear,
Merge semantics make the intent crystal clear!
replaceAttributes() stands ready when replacement's desired,
A gentler approach to what traits have inspired! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: making HasAttributes::attributes() update existing attributes and adding replaceAttributes() for full replacement.
Description check ✅ Passed The description is related to the changeset by indicating this is a bugfix with breaking changes, though it lacks implementation details about the specific modifications made.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-mini-19

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.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 51 minutes and 42 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6df17a8) to head (48df2ea).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

@coderabbitai coderabbitai Bot added the bug Something isn't working label Apr 30, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a 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

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7e9328c and 813e123.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • UPGRADE.md
  • src/HasAttributes.php
  • tests/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.md
  • src/HasAttributes.php
  • tests/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 via setMany(), while replaceAttributes() 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

Comment thread tests/HasAttributesTest.php
@terabytesoftw
Copy link
Copy Markdown
Contributor Author

@coderabbitai approve

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

✅ Actions performed

Comments resolved and changes approved.

@terabytesoftw terabytesoftw merged commit 6b92ef1 into main Apr 30, 2026
41 checks passed
@terabytesoftw terabytesoftw deleted the fix-mini-19 branch April 30, 2026 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant