Skip to content

Add default() to Path for fallback values (#7) - #12

Merged
1blankz7 merged 1 commit into
masterfrom
fix/php-object-query-7-default-values
Aug 21, 2026
Merged

Add default() to Path for fallback values (#7)#12
1blankz7 merged 1 commit into
masterfrom
fix/php-object-query-7-default-values

Conversation

@1blankz7

Copy link
Copy Markdown
Collaborator

Closes #7.

Path::optional() (from #8) omits the key entirely when a value can't be resolved along the chain. This adds Path::default($value), which instead returns a fallback value and keeps the key present in the result set. default() takes precedence over optional() if both are chained.

$resolver = new QueryResolver(
    new Query('pilotName', (new Path())->get('pilot')->get('name')->default('Unknown pilot'))
);

$resolver->resolve($someShipWithoutAPilot);
// ['pilotName' => 'Unknown pilot']
  • Added Path::default() with unit + functional tests
  • Documented in README

Path::optional() omits the key entirely when a value can't be resolved.
Sometimes you want the key to always be present with a fallback value
instead. Path::default($value) does that, and takes precedence over
optional() if both are set.
@1blankz7
1blankz7 merged commit 6623d4d into master Aug 21, 2026
1 check passed
@1blankz7
1blankz7 deleted the fix/php-object-query-7-default-values branch August 21, 2026 23:29
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.

Add default values for not present data in Path

1 participant