Honor private and protected properties in equals and hashCode.#23
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request updates the value-object engine so equals() and hashCode() honor non-public (private/protected) instance properties by extracting properties via reflection (while excluding static properties), and expands the unit test suite to cover the new behavior.
Changes:
- Replace
get_object_vars()with a reflection-based property extractor for hashing and equality. - Add new test fixtures and extend behavior tests to cover private properties, mixed visibility, and static-property exclusion.
- Update PHPStan ignores and bump a couple of dev tool dependencies.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/ValueObjectBehaviorHashCodeTest.php | Adds/reshapes scenarios validating hashing across visibility, arrays, enums, nulls, and static-property exclusion. |
| tests/Unit/ValueObjectBehaviorEqualsTest.php | Adds/reshapes scenarios validating equality across visibility, arrays, enums, and nested structures. |
| tests/Models/Rating.php | New fixture to ensure static properties are excluded from hashing/equality. |
| tests/Models/PrivateMoney.php | New fixture to validate private promoted properties participate in hashing/equality. |
| tests/Models/MixedVisibilityProfile.php | New fixture to validate mixed public/private properties participate in hashing/equality. |
| src/Internal/ValueObjectHash.php | Switches hashing to use reflection-based property extraction. |
| src/Internal/ValueObjectEquality.php | Switches equality to use reflection-based property extraction. |
| src/Internal/ObjectProperties.php | Introduces reflection-based instance-property extractor (excluding static properties). |
| src/Internal/ArrayHash.php | Refactors sprintf usage to follow the project’s “template variable” rule. |
| src/Internal/ArrayEquality.php | Tightens callback typing for array structural equality. |
| phpstan.neon.dist | Adds ignores for reflection-driven property reads and untyped internal arrays. |
| composer.json | Bumps ergebnis/composer-normalize and infection/infection dev versions. |
| .claude/rules/php-library-testing.md | Clarifies allowed non-test methods in PHPUnit classes and references member-ordering rule. |
| .claude/rules/php-library-code-style.md | Updates member-ordering rules and clarifies PHPDoc expectations (including for Internal/). |
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
What this pull request does.
Related issue
Closes #...
Checklist
composer reviewpasses.composer testspasses.