Skip to content

feat: AuditDiff and AuditDiffCollection typed value objects#317

Closed
DamienHarper wants to merge 2 commits intomasterfrom
feature/audit-diff-value-object
Closed

feat: AuditDiff and AuditDiffCollection typed value objects#317
DamienHarper wants to merge 2 commits intomasterfrom
feature/audit-diff-value-object

Conversation

@DamienHarper
Copy link
Copy Markdown
Owner

Summary

  • Entry::getDiffs() now returns a typed AuditDiffCollection instead of a plain array, providing IDE completion and domain-level filtering helpers
  • New AuditDiff immutable value object exposes getField(), getOldValue(), getNewValue(), wasAdded(), wasRemoved(), isRelation()
  • New AuditDiffCollection implements IteratorAggregate + Countable with getField(), added(), removed(), changed() sub-collection filters
  • Entry::getDiffsAsArray() added as an explicit escape hatch for Twig templates and serialization (preserves previous getDiffs() array behaviour)
  • ASSOCIATE/DISSOCIATE entries yield an empty collection; callers use getDiffSource() / getDiffTarget() for the relation descriptors

BC impact

Entry::getDiffs() return type changes from array to AuditDiffCollection. Callers expecting array must migrate to getDiffsAsArray() or iterate the collection directly.

Test plan

  • composer agent-test passes (88 tests, 182 assertions)
  • composer agent-phpstan clean at level max
  • AuditDiffTest — field access, wasAdded/wasRemoved, isRelation (both sides, one side, null/null)
  • AuditDiffCollectionTest — count, iteration, getField, added/removed/changed filters, null/null exclusion from changed(), legacy REMOVE flat shape, mixed skipped entries
  • EntryTest — getDiffs() returns AuditDiffCollection for all schema versions, getDiffsAsArray() for all schema versions including ASSOCIATE/DISSOCIATE full envelope

Entry::getDiffs() now returns a typed AuditDiffCollection instead of a
plain array, providing IDE completion, iteration, and filtering helpers
(added/removed/changed) on top of the unified schema v2 diffs format.

AuditDiff exposes getField(), getOldValue(), getNewValue(), wasAdded(),
wasRemoved(), and isRelation() for ergonomic per-field access.
AuditDiffCollection implements IteratorAggregate and Countable.

ASSOCIATE/DISSOCIATE entries (schema v2, no 'changes' key) yield an empty
collection; callers should use getDiffSource() / getDiffTarget() instead.
Legacy REMOVE entries (schema v1 flat shape) also yield an empty collection.

The previous array-returning behaviour is preserved via getDiffsAsArray()
as an explicit escape hatch for Twig templates and serialization.
- AuditDiffCollection::changed() now requires both old and new to be
  non-null, correctly excluding null/null diffs (no-op field entries)
- Entry::getDiffs() and getDiffsAsArray() throw UnexpectedValueException
  when the 'changes' key exists but is not an array (data integrity guard)
- Improve Entry::getDiffs() docblock with actionable guidance for legacy
  REMOVE entries and ASSOCIATE/DISSOCIATE cases
- Add tests: null/null state in AuditDiff, both-sides relation descriptor,
  changed() excludes null/null, mixed skipped/valid entries, getDiffsAsArray()
  full-envelope for ASSOCIATE/DISSOCIATE
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 87.34177% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.77%. Comparing base (1147e9d) to head (b8b4f6c).

Files with missing lines Patch % Lines
src/Model/Entry.php 54.54% 10 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (1147e9d) and HEAD (b8b4f6c). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (1147e9d) HEAD (b8b4f6c)
5 1
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #317       +/-   ##
===========================================
- Coverage   93.28%   72.77%   -20.51%     
===========================================
  Files          18       20        +2     
  Lines         506      382      -124     
===========================================
- Hits          472      278      -194     
- Misses         34      104       +70     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DamienHarper
Copy link
Copy Markdown
Owner Author

Closing: the value of this abstraction is significantly reduced since item #18 (unified schema v2 diffs format) already provides a clean, uniform array structure with explicit old/new keys. The breaking change cost outweighs the ergonomic gain. Deprioritised.

@DamienHarper DamienHarper deleted the feature/audit-diff-value-object branch April 1, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant