Skip to content

Remove stdClass support, enable pure entity trees#22

Merged
alganet merged 1 commit intoRespect:masterfrom
alganet:pk-track
Mar 25, 2026
Merged

Remove stdClass support, enable pure entity trees#22
alganet merged 1 commit intoRespect:masterfrom
alganet:pk-track

Conversation

@alganet
Copy link
Copy Markdown
Member

@alganet alganet commented Mar 25, 2026

Drop stdClass as entity fallback — EntityFactory now throws DomainException for unknown classes. Remove dynamic property fallbacks from set/get/extractProperties, eliminate persistableCache and reflectPersistable().

Add EntityFactory::extractColumns() to derive FK values from entity object properties (e.g. $author -> author_id).

Rewrite wireRelationships to use collection-tree parent matching instead of FK property scanning. Update resolveEntityName to accept object|array for Nested hydrator compatibility.

Entity stubs use pure entity trees: relation properties ($post, $author) replace FK scalars ($post_id, $author_id). Remove redundant tests, add extractColumns unit coverage.

@alganet alganet requested a review from Copilot March 25, 2026 22:30
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.45%. Comparing base (169cf0b) to head (b3cff76).

Additional details and impacted files
@@             Coverage Diff              @@
##             master      #22      +/-   ##
============================================
+ Coverage     97.58%   98.45%   +0.86%     
+ Complexity      206      204       -2     
============================================
  Files            16       16              
  Lines           456      453       -3     
============================================
+ Hits            445      446       +1     
+ Misses           11        7       -4     

☔ 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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes stdClass as a fallback entity type and shifts hydration/persistence toward “pure entity trees” where relationships are represented by object properties (e.g. $post->author) and persisted via derived FK columns (e.g. author_id).

Changes:

  • Make EntityFactory::createByName() throw for unknown entity classes (no stdClass fallback) and remove dynamic property set/get behavior.
  • Add EntityFactory::extractColumns() to convert relation-object properties into FK columns for persistence.
  • Update hydrators/collections/tests to support array-based typed discrimination and collection-tree-based relationship wiring.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Stubs/Post.php Adds Post stub for pure entity-tree relationship modeling.
tests/Stubs/Issue.php Adds Issue stub for typed entity hydration tests.
tests/Stubs/Foo.php Adds Foo stub used as a generic entity in tests (replacing stdClass).
tests/Stubs/Comment.php Adds Comment stub using relation property (post) instead of FK scalar.
tests/Stubs/Category.php Adds Category stub for test fixtures.
tests/Stubs/Bug.php Adds Bug stub for typed discriminator hydration tests.
tests/Stubs/Author.php Adds Author stub for relationship and persistence tests.
tests/InMemoryMapper.php Switches persistence extraction from properties to derived columns (extractColumns).
tests/Hydrators/NestedTest.php Updates Nested hydrator tests to use stub namespace + typed entities without stdClass.
tests/Hydrators/FlatTest.php Updates Flat hydrator typed-entity test to use stubs instead of stdClass.
tests/EntityFactoryTest.php Updates expectations for unknown entities (exception) and adds extractColumns unit coverage.
tests/Collections/TypedTest.php Updates typed discriminator tests to use array rows (no stdClass).
tests/Collections/CollectionTest.php Replaces stdClass usage with stub entity instances.
tests/AbstractMapperTest.php Reworks relationship wiring assertions for pure entity trees and updates mapper setup to use stubs.
src/Hydrators/Nested.php Passes raw array into resolveEntityName() for Nested hydration compatibility.
src/Hydrators/Base.php Replaces FK-scanning wiring with collection-tree parent matching.
src/EntityFactory.php Removes stdClass fallback + dynamic props, adds extractColumns(), updates extraction/hydration logic.
src/Collections/Typed.php Allows resolveEntityName() to accept `object
src/Collections/Collection.php Updates resolveEntityName() signature to accept `object

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Drop stdClass as entity fallback — EntityFactory now throws
DomainException for unknown classes. Remove dynamic property
fallbacks from set/get/extractProperties, eliminate
persistableCache and reflectPersistable().

Add EntityFactory::extractColumns() to derive FK values from
entity object properties (e.g. $author -> author_id).

Rewrite wireRelationships to use collection-tree parent matching
instead of FK property scanning. Update resolveEntityName to
accept object|array for Nested hydrator compatibility.

Entity stubs use pure entity trees: relation properties ($post,
$author) replace FK scalars ($post_id, $author_id). Remove
redundant tests, add extractColumns unit coverage.
@alganet alganet marked this pull request as ready for review March 25, 2026 22:46
@alganet alganet merged commit 48a4ff2 into Respect:master Mar 25, 2026
3 checks passed
@alganet alganet deleted the pk-track branch March 25, 2026 22:54
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.

3 participants