feat: AuditDiff and AuditDiffCollection typed value objects#317
Closed
DamienHarper wants to merge 2 commits intomasterfrom
Closed
feat: AuditDiff and AuditDiffCollection typed value objects#317DamienHarper wants to merge 2 commits intomasterfrom
DamienHarper wants to merge 2 commits intomasterfrom
Conversation
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Entry::getDiffs()now returns a typedAuditDiffCollectioninstead of a plainarray, providing IDE completion and domain-level filtering helpersAuditDiffimmutable value object exposesgetField(),getOldValue(),getNewValue(),wasAdded(),wasRemoved(),isRelation()AuditDiffCollectionimplementsIteratorAggregate + CountablewithgetField(),added(),removed(),changed()sub-collection filtersEntry::getDiffsAsArray()added as an explicit escape hatch for Twig templates and serialization (preserves previousgetDiffs()array behaviour)getDiffSource()/getDiffTarget()for the relation descriptorsBC impact
Entry::getDiffs()return type changes fromarraytoAuditDiffCollection. Callers expectingarraymust migrate togetDiffsAsArray()or iterate the collection directly.Test plan
composer agent-testpasses (88 tests, 182 assertions)composer agent-phpstanclean at level maxAuditDiffTest— 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 entriesEntryTest— getDiffs() returns AuditDiffCollection for all schema versions, getDiffsAsArray() for all schema versions including ASSOCIATE/DISSOCIATE full envelope