PHPLIB-1624 Generate typed value classes for nested operator arguments#1886
Draft
GromNaN wants to merge 7 commits into
Draft
PHPLIB-1624 Generate typed value classes for nested operator arguments#1886GromNaN wants to merge 7 commits into
GromNaN wants to merge 7 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v2.x #1886 +/- ##
============================================
- Coverage 87.74% 87.46% -0.28%
- Complexity 3319 3350 +31
============================================
Files 451 457 +6
Lines 6632 6692 +60
============================================
+ Hits 5819 5853 +34
- Misses 813 839 +26
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
1 task
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()
- Add TypeClassPrinter to allow single-line method docblocks when content fits on one line (fixes MultiLineDocComment for single-param constructors) - Sort `null` last in union types to comply with NullTypeHintOnLastPosition - Align @param annotations in type class constructors to fix SpacingAfterParamType/SpacingAfterParamName CS errors - Regenerate all affected builder files
f7eb903 to
9a10497
Compare
There was a problem hiding this comment.
Psalm found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
Type classes for nested arguments are now generated in a Type sub-namespace of their operator's namespace (e.g. MongoDB\Builder\Stage\Type instead of the shared MongoDB\Builder\Type namespace).
43e0932 to
9032f52
Compare
Each generated class now declares a @psalm-type {ClassName}Shape annotation
that describes all valid array/stdClass representations of the operator:
- Encode::Object → array{prop: type, prop?: type}|object{...}&stdClass|ClassName
- Encode::Single (variadic:array) → non-empty-list<type>|ClassName
- Encode::Single (variadic:object) → non-empty-array<string, type>|stdClass|ClassName
- Encode::Single (scalar) → type|ClassName
- Encode::Array → list{type, type}|ClassName
Field names that are Psalm parser keywords (e.g. "as") are single-quoted.
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.
Depends on mongodb/mql-specifications#33
Generates dedicated
finaltype classes inMongoDB\Builder\Type\for operator arguments with nested sub-fields (YAMLarguments:key), replacing ad-hocarray|stdClassparameters with properly-typed value objects (e.g.RankFusionInput,RankFusionCombination,ScoreFusionInput,ScoreFusionCombination).TypeInterface(new marker interface) and exposes aPROPERTIESconstantTypeEncoderregistered inBuilderEncoderto serialize these objects, skippingOptional::Undefinedpropertiesnew RankFusionInput(...$input)) for ergonomic API usagebuildPropertyAndParam()inOperatorClassGeneratorto handle all argument patterns (non-variadic, variadic:object map, variadic:array list), eliminating the duplicated logic betweencreateClass()andcreateArgumentTypeClass()