Skip to content

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
feature/develop
Apr 21, 2026
Merged

Distinguish missing key from explicit null in ObjectBuilder, guard non-named types in CasterHandler, and speed up enum casting via tryFrom.#25
gustavofreze merged 1 commit intomainfrom
feature/develop

Conversation

@gustavofreze
Copy link
Copy Markdown
Member

No description provided.

…rd non-named types in CasterHandler, and speed up enum casting via tryFrom.
Copilot AI review requested due to automatic review settings April 20, 2026 22:01
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 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 ObjectBuilder to treat “missing key” differently from “explicit null”, preserving null while 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 .claude rule 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.

Comment thread src/Internal/Mappers/Object/Casters/EnumCaster.php
Comment thread tests/ObjectMappingTest.php
Comment thread tests/ObjectMappingTest.php
Comment thread infection.json.dist
Comment thread tests/ObjectMappingTest.php
Comment thread tests/ObjectMappingTest.php
Comment thread tests/EnumMappingTest.php
Comment thread .gitattributes
@gustavofreze gustavofreze merged commit cce9081 into main Apr 21, 2026
10 checks passed
@gustavofreze gustavofreze deleted the feature/develop branch April 21, 2026 11:30
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