Improve identity map merging, error handling, and type safety#25
Merged
alganet merged 1 commit intoRespect:masterfrom Apr 1, 2026
Merged
Improve identity map merging, error handling, and type safety#25alganet merged 1 commit intoRespect:masterfrom
alganet merged 1 commit intoRespect:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #25 +/- ##
============================================
+ Coverage 98.11% 98.39% +0.27%
- Complexity 283 294 +11
============================================
Files 16 17 +1
Lines 583 622 +39
============================================
+ Hits 572 612 +40
+ Misses 11 10 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR refines identity map behavior during persist() by merging entities instead of swapping object instances, improves PK lookup consistency via ID normalization, and introduces clearer error handling when collections are used without a bound mapper.
Changes:
- Replace identity-map entity replacement with per-property merge behavior (in-place updates for mutable entities; merged instance for readonly entities only when needed).
- Normalize primary key values (numeric strings → ints) for consistent identity map indexing and lookups.
- Improve error handling/type-safety by adding
CollectionNotBoundand tightening/refining phpstan annotations/ignores.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/AbstractMapperTest.php | Updates expectations to reflect merge-in-place vs merged-instance behavior and new persist() return semantics. |
| src/AbstractMapper.php | Implements identity-map merge logic and ID normalization in identity map interactions. |
| src/EntityFactory.php | Adds mergeEntities() and strengthens type annotations for cached reflections. |
| src/Collections/Collection.php | Returns mapper persist() result and throws CollectionNotBound when no mapper is attached. |
| src/CollectionNotBound.php | New dedicated exception type/message for unbound collections. |
| src/Hydrators/Flat.php | Clarifies phpstan ignore rationale for entity instance typing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace identity map entity swapping with per-property merging: mutable entities are updated in-place, readonly entities produce a new merged instance only when properties actually differ. Normalize PK types (numeric strings cast to int) for consistent identity map lookups. Add CollectionNotBound exception, cycle-safe persist return values, and class-string annotations removing phpstan-ignore.
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.
Replace identity map entity swapping with per-property merging: mutable entities are updated in-place, readonly entities produce a new merged instance only when properties actually differ. Normalize PK types (numeric strings cast to int) for consistent identity map lookups. Add CollectionNotBound exception, cycle-safe persist return values, and class-string annotations removing phpstan-ignore.