Skip to content

Commit 373bbc4

Browse files
authored
Replace OperatorInterface::getOperator() with OperatorInterface::NAME constant (#1541)
1 parent 9fc0d42 commit 373bbc4

File tree

279 files changed

+325
-1369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

279 files changed

+325
-1369
lines changed

generator/config/expression/case.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ name: $case
33
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/'
44
type:
55
- switchBranch
6-
encode: flat_object
6+
encode: object
7+
wrapObject: false
78
description: |
89
Represents a single case in a $switch expression
910
arguments:

generator/config/schema.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,18 @@
6060
"enum": [
6161
"array",
6262
"object",
63-
"flat_object",
6463
"single"
6564
]
6665
},
6766
"description": {
6867
"$comment": "The description of the argument from MongoDB's documentation.",
6968
"type": "string"
7069
},
70+
"wrapObject": {
71+
"$comment": "Wrap the properties in an object with the operator name",
72+
"type": "boolean",
73+
"default": true
74+
},
7175
"arguments": {
7276
"$comment": "An optional list of arguments for the operator.",
7377
"type": "array",

generator/src/Definition/OperatorDefinition.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,21 @@ public function __construct(
3232
/** @var list<string> */
3333
public array $type,
3434
public string|null $description = null,
35+
public bool $wrapObject = true,
3536
array $arguments = [],
3637
array $tests = [],
3738
) {
3839
$this->encode = match ($encode) {
3940
'single' => Encode::Single,
4041
'array' => Encode::Array,
4142
'object' => Encode::Object,
42-
'flat_object' => Encode::FlatObject,
4343
default => throw new UnexpectedValueException(sprintf('Unexpected "encode" value for operator "%s". Got "%s"', $name, $encode)),
4444
};
4545

46+
if (! $wrapObject && $this->encode !== Encode::Object) {
47+
throw new UnexpectedValueException(sprintf('Operator "%s" cannot have wrapObject set to false when encode is not "object"', $name));
48+
}
49+
4650
// Convert arguments to ArgumentDefinition objects
4751
// Optional arguments must be after required arguments
4852
$requiredArgs = $optionalArgs = [];

generator/src/OperatorClassGenerator.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use function interface_exists;
2323
use function rtrim;
2424
use function sprintf;
25-
use function var_export;
2625

2726
/**
2827
* Generates a value object class for stages and operators.
@@ -62,6 +61,7 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
6261
$class->addComment('@internal');
6362
$namespace->addUse(Encode::class);
6463
$class->addConstant('ENCODE', new Literal('Encode::' . $operator->encode->name));
64+
$class->addConstant('NAME', $operator->wrapObject ? $operator->name : null);
6565

6666
$encodeNames = [];
6767
$constructor = $class->addMethod('__construct');
@@ -179,10 +179,6 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
179179
$class->addConstant('PROPERTIES', $encodeNames);
180180
}
181181

182-
$class->addMethod('getOperator')
183-
->setReturnType('string')
184-
->setBody('return ' . var_export($operator->name, true) . ';');
185-
186182
return $namespace;
187183
}
188184

psalm-baseline.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,26 @@
172172
<code><![CDATA[stdClass]]></code>
173173
</TooManyTemplateParams>
174174
</file>
175+
<file src="src/Builder/Type/CombinedFieldQuery.php">
176+
<MixedArgument>
177+
<code><![CDATA[$operator]]></code>
178+
<code><![CDATA[$operator]]></code>
179+
</MixedArgument>
180+
<MixedArrayOffset>
181+
<code><![CDATA[$seenOperators[$operator]]]></code>
182+
</MixedArrayOffset>
183+
<MixedAssignment>
184+
<code><![CDATA[$operator]]></code>
185+
</MixedAssignment>
186+
</file>
175187
<file src="src/Builder/Type/QueryObject.php">
188+
<MixedArgument>
189+
<code><![CDATA[$query::NAME]]></code>
190+
</MixedArgument>
191+
<MixedArrayOffset>
192+
<code><![CDATA[$seenQueryOperators[$query::NAME]]]></code>
193+
<code><![CDATA[$seenQueryOperators[$query::NAME]]]></code>
194+
</MixedArrayOffset>
176195
<MixedAssignment>
177196
<code><![CDATA[$queries[$fieldPath]]]></code>
178197
<code><![CDATA[$query]]></code>
@@ -183,6 +202,11 @@
183202
is_array($queriesOrArrayOfQueries[0]) &&
184203
count($queriesOrArrayOfQueries[0]) > 0]]></code>
185204
</RedundantConditionGivenDocblockType>
205+
<UndefinedConstant>
206+
<code><![CDATA[$query::NAME]]></code>
207+
<code><![CDATA[$query::NAME]]></code>
208+
<code><![CDATA[$query::NAME]]></code>
209+
</UndefinedConstant>
186210
</file>
187211
<file src="src/ChangeStream.php">
188212
<DeprecatedConstant>

src/Builder/Accumulator/AccumulatorAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/AddToSetAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/AvgAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/BottomAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/BottomNAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/CountAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/CovariancePopAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/CovarianceSampAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/DenseRankAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/DerivativeAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/DocumentNumberAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/ExpMovingAvgAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/FirstAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/FirstNAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/IntegralAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Accumulator/LastAccumulator.php

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)