Skip to content

Honor private and protected properties in equals and hashCode.#23

Merged
gustavofreze merged 1 commit into
mainfrom
fix/equality
May 23, 2026
Merged

Honor private and protected properties in equals and hashCode.#23
gustavofreze merged 1 commit into
mainfrom
fix/equality

Conversation

@gustavofreze
Copy link
Copy Markdown
Member

@gustavofreze gustavofreze commented May 23, 2026

Please follow the contributing guidelines.

Summary

What this pull request does.

Related issue

Closes #...

Checklist

  • Tests added or updated.
  • Documentation updated when applicable.
  • composer review passes.
  • composer tests passes.

Copilot AI review requested due to automatic review settings May 23, 2026 21:00
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 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/).

Comment thread src/Internal/ObjectProperties.php
Comment thread tests/Unit/ValueObjectBehaviorHashCodeTest.php
Comment thread tests/Models/Rating.php
Comment thread composer.json
@gustavofreze gustavofreze merged commit fb43610 into main May 23, 2026
8 checks passed
@gustavofreze gustavofreze deleted the fix/equality branch May 23, 2026 21:06
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.

2 participants