Skip to content

Commit

Permalink
Replace getOperator with Operator::NAME constant
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Nov 28, 2024
1 parent 1074e23 commit c83e779
Show file tree
Hide file tree
Showing 278 changed files with 292 additions and 1,368 deletions.
3 changes: 2 additions & 1 deletion generator/config/expression/case.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name: $case
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/'
type:
- switchBranch
encode: flat_object
encode: object
noName: true
description: |
Represents a single case in a $switch expression
arguments:
Expand Down
6 changes: 5 additions & 1 deletion generator/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"enum": [
"array",
"object",
"flat_object",
"dollar_object",
"single",
"group"
Expand All @@ -70,6 +69,11 @@
"$comment": "The description of the argument from MongoDB's documentation.",
"type": "string"
},
"noName": {
"$comment": "Don't wrap the properties in an object with the operator name",
"type": "boolean",
"default": false
},
"arguments": {
"$comment": "An optional list of arguments for the operator.",
"type": "array",
Expand Down
2 changes: 1 addition & 1 deletion generator/src/Definition/OperatorDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public function __construct(
/** @var list<string> */
public array $type,
public string|null $description = null,
public bool $noName = false,
array $arguments = [],
array $tests = [],
) {
$this->encode = match ($encode) {
'single' => Encode::Single,
'array' => Encode::Array,
'object' => Encode::Object,
'flat_object' => Encode::FlatObject,
'dollar_object' => Encode::DollarObject,
'group' => Encode::Group,
default => throw new UnexpectedValueException(sprintf('Unexpected "encode" value for operator "%s". Got "%s"', $name, $encode)),
Expand Down
5 changes: 1 addition & 4 deletions generator/src/OperatorClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
$class->addComment('@see ' . $operator->link);
$namespace->addUse(Encode::class);
$class->addConstant('ENCODE', new Literal('Encode::' . $operator->encode->name));
$class->addConstant('NAME', $operator->noName ? null : $operator->name);

$constuctor = $class->addMethod('__construct');
foreach ($operator->arguments as $argument) {
Expand Down Expand Up @@ -170,10 +171,6 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
$constuctor->addBody('$this->' . $argument->name . ' = $' . $argument->name . ';');
}

$class->addMethod('getOperator')
->setReturnType('string')
->setBody('return ' . var_export($operator->name, true) . ';');

return $namespace;
}

Expand Down
6 changes: 1 addition & 5 deletions src/Builder/Accumulator/AccumulatorAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/AddToSetAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/AvgAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/BottomAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/BottomNAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/CountAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/CovariancePopAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/CovarianceSampAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/DenseRankAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/DerivativeAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/DocumentNumberAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/ExpMovingAvgAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/FirstAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/FirstNAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/IntegralAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/LastAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/LastNAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/LinearFillAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/Builder/Accumulator/LocfAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c83e779

Please sign in to comment.