Distinguish missing key from explicit null in ObjectBuilder, guard non-named types in CasterHandler, and speed up enum casting via tryFrom.#25
Merged
gustavofreze merged 1 commit intomainfrom Apr 21, 2026
Conversation
…rd non-named types in CasterHandler, and speed up enum casting via tryFrom.
There was a problem hiding this comment.
Pull request overview
This PR improves object and enum hydration behavior by distinguishing missing keys vs explicit null, guarding against non-named reflection types during casting, and optimizing backed-enum casting using tryFrom().
Changes:
- Update
ObjectBuilderto treat “missing key” differently from “explicit null”, preservingnullwhile still applying defaults when keys are absent. - Replace enum casting via reflection with
BackedEnum::tryFrom()for backed enums and::cases()name matching for pure enums. - Add new test fixtures and PHPUnit coverage for union-typed parameters, explicit-null vs missing-key defaults, and pure-enum case-name hydration; plus repo/tooling housekeeping (composer normalize, editorconfig, gitattributes, CI action bumps, new
.clauderule docs).
Reviewed changes
Copilot reviewed 25 out of 26 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/ObjectMappingTest.php | Adds coverage for union-typed params and explicit-null vs missing-key handling. |
| tests/Models/HybridValue.php | Test fixture for union-typed constructor parameter. |
| tests/Models/NullableName.php | Test fixture for default value + nullable parameter behavior. |
| tests/Models/Pair.php | Test fixture to ensure argument-building continues after null. |
| tests/EnumMappingTest.php | Adds pure-enum hydration tests (case-name mapping + invalid case). |
| tests/Models/Severity.php | New pure enum fixture for hydration. |
| tests/Models/Alert.php | Fixture using Severity enum for enum mapping tests. |
| src/Internal/Builders/ObjectBuilder.php | Implements missing-key vs explicit-null distinction; renames caster usage. |
| src/Internal/Mappers/Object/Casters/CasterResolver.php | Renames/adjusts caster resolution; guards non-ReflectionNamedType types. |
| src/Internal/Mappers/Object/Casters/EnumCaster.php | Optimizes backed-enum casting using tryFrom() and supports pure enums by case name. |
| src/Internal/Extractors/ReflectionExtractor.php | Minor refactor and null-check style change. |
| infection.json.dist | Disables an additional mutator (ProtectedVisibility). |
| composer.json | Metadata + dev dependency updates; adds composer-normalize plugin and reorders scripts/config. |
| README.md | Updates overview wording to be more descriptive of capabilities. |
| Makefile | Adds composer normalize to configure; adds show-outdated; adjusts help text. |
| .gitignore | Changes ignore patterns for vendor and report. |
| .github/workflows/ci.yml | Updates artifact action versions. |
| .github/copilot-instructions.md | Adds Copilot instruction file pointing to .claude rules. |
| .gitattributes | Adds LF normalization, diff drivers, export-ignore list (needs path fixes). |
| .editorconfig | Adds editor config for consistent formatting. |
| .claude/CLAUDE.md | Adds project guidance and post-change validation checklist. |
| .claude/rules/*.md | Introduces detailed rules for testing, code style, modeling, docs, and workflows. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
No description provided.