Skip to content

fix: detects nested objects with colliding keys.#761

Open
jorgerobles wants to merge 6 commits intoCuyZ:masterfrom
jorgerobles:feature/nested-keys
Open

fix: detects nested objects with colliding keys.#761
jorgerobles wants to merge 6 commits intoCuyZ:masterfrom
jorgerobles:feature/nested-keys

Conversation

@jorgerobles
Copy link
Copy Markdown

Problem Solved

Previously, nested objects using some constructor properties with the same signature thrown errors.

Example of the problem:

class Order {
    public function __construct(public Id $id) {}
}

class Id {
    public function __construct(
        public string $id,        // collision with parent property name
        public string $type
    ) {}
}

// This would fail:
$data = [
    "id" => "123",
    "type" => "item",
];

Changes

  • ShapedArrayNodeBuilder.php: Added ClassDefinitionRepository dependency and resolveFlatToNestedValue() method to detect and handle nested mapping patterns
  • Container.php: Inject ClassDefinitionRepository into ShapedArrayNodeBuilder
  • FlatToNestedMappingTest.php: Comprehensive test suite with tests covering various scenarios validating:
    • Name collision scenarios
    • No name collision scenarios
    • Multiple parameters (3+)
    • Optional parameters
    • Custom constructors with #[Constructor] attribute
    • Already nested data (backward compatibility)
    • Multiple properties with nested objects
    • Recursion

jorgerobles and others added 6 commits November 27, 2025 16:58
Add array_key_exists check when extracting nested object parameters
to avoid accessing undefined keys for optional parameters that aren't
present in the source data.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add check to ensure at least one parameter is present in parent value
- Add test for optional parameters with additional parent properties
- Prevents false positives in nested keys detection

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test for LogicalAnd mutation (line 153) - KILLED ✅
- Add test for property key not in consumed_keys
- Add test for all-optional params with none provided
- Add test for early return when value is already array

Improved MSI from 79.59% to 81.63%

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

1 participant