Skip to content

PHPLIB-1624 Generate typed value classes for nested operator arguments#1886

Draft
GromNaN wants to merge 3 commits intomongodb:v2.xfrom
GromNaN:generator-nested-types
Draft

PHPLIB-1624 Generate typed value classes for nested operator arguments#1886
GromNaN wants to merge 3 commits intomongodb:v2.xfrom
GromNaN:generator-nested-types

Conversation

@GromNaN
Copy link
Copy Markdown
Member

@GromNaN GromNaN commented Apr 29, 2026

Depends on mongodb/mql-specifications#33

Generates dedicated final type classes in MongoDB\Builder\Type\ for operator arguments with nested sub-fields (YAML arguments: key), replacing ad-hoc array|stdClass parameters with properly-typed value objects (e.g. RankFusionInput, RankFusionCombination, ScoreFusionInput, ScoreFusionCombination).

  • Each type class implements TypeInterface (new marker interface) and exposes a PROPERTIES constant
  • Added TypeEncoder registered in BuilderEncoder to serialize these objects, skipping Optional::Undefined properties
  • Operator constructors auto-convert plain arrays to the type class via named-argument spread (new RankFusionInput(...$input)) for ergonomic API usage
  • Refactored buildPropertyAndParam() in OperatorClassGenerator to handle all argument patterns (non-variadic, variadic:object map, variadic:array list), eliminating the duplicated logic between createClass() and createArgumentTypeClass()

GromNaN added 3 commits April 29, 2026 14:59
Generate dedicated final type classes in MongoDB\Builder\Type\ for operator
arguments with sub-fields (e.g., RankFusionInput, RankFusionCombination,
ScoreFusionInput, ScoreFusionCombination).

- Each type class implements TypeInterface and carries a PROPERTIES constant
- TypeEncoder (registered in BuilderEncoder) handles serialization, skipping
  Optional::Undefined properties
- Operator constructors auto-convert plain arrays to the type class via spread
  (e.g., new RankFusionInput(...$input)) for ergonomic usage
- buildPropertyAndParam() helper in OperatorClassGenerator now handles all
  argument patterns (non-variadic, variadic:object, variadic:array), eliminating
  duplication between createClass() and createArgumentTypeClass()
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 50.66667% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.33%. Comparing base (12e5646) to head (f7eb903).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/Builder/Type/ObjectShape.php 0.00% 20 Missing ⚠️
src/Builder/Encoder/TypeEncoder.php 75.00% 4 Missing ⚠️
src/Builder/Type/RankFusionInput.php 0.00% 4 Missing ⚠️
src/Builder/Stage/FluentFactoryTrait.php 0.00% 3 Missing ⚠️
src/Builder/Stage/RankFusionStage.php 75.00% 2 Missing ⚠️
src/Builder/Type/RankFusionCombination.php 0.00% 2 Missing ⚠️
src/Builder/Expression/SigmoidOperator.php 75.00% 1 Missing ⚠️
src/Builder/Type/ScoreFusionInput.php 80.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               v2.x    #1886      +/-   ##
============================================
- Coverage     87.75%   87.33%   -0.42%     
- Complexity     3308     3342      +34     
============================================
  Files           447      455       +8     
  Lines          6607     6682      +75     
============================================
+ Hits           5798     5836      +38     
- Misses          809      846      +37     
Flag Coverage Δ
6.0-replica_set 86.18% <50.66%> (-0.41%) ⬇️
6.0-server 82.25% <50.66%> (-0.36%) ⬇️
6.0-sharded_cluster 85.97% <50.66%> (-0.41%) ⬇️
8.0-replica_set 87.20% <50.66%> (-0.42%) ⬇️
8.0-server 82.98% <50.66%> (-0.37%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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