Skip to content

Commit

Permalink
Use BSON\Type and BSON\Javascript classes, remove duplicate resolveToInt
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Oct 16, 2023
1 parent fee0df6 commit ad48be4
Show file tree
Hide file tree
Showing 128 changed files with 1,077 additions and 1,741 deletions.
11 changes: 4 additions & 7 deletions generator/config/expressions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
use MongoDB\Model\BSONArray;
use stdClass;

use function array_merge;
use function array_unique;
use function array_values;
use function ucfirst;

$bsonTypes = [
Expand All @@ -30,18 +27,18 @@
'date' => [BSON\UTCDateTime::class],
'null' => ['null'],
'regex' => [BSON\Regex::class],
'javascript' => ['string'],
'javascript' => ['string', BSON\Javascript::class],
'int' => ['int'],
'timestamp' => ['int', BSON\Timestamp::class],
'long' => ['int', BSON\Int64::class, ResolvesToInt::class],
'long' => ['int', BSON\Int64::class],
'decimal' => ['int', BSON\Int64::class, 'float', BSON\Decimal128::class],
];

// "any" accepts all the BSON types. No generic "object" or "mixed"
$bsonTypes['any'] = array_unique(array_merge(...array_values($bsonTypes)));
$bsonTypes['any'] = ['bool', 'int', 'float', 'string', 'array', 'null', stdClass::class, BSON\Type::class];

// "number" accepts all the numeric types
$bsonTypes['number'] = array_unique(array_merge($bsonTypes['int'], $bsonTypes['double'], $bsonTypes['long'], $bsonTypes['decimal']));
$bsonTypes['number'] = ['int', 'float', BSON\Int64::class, BSON\Decimal128::class];

$expressions = [];
$resolvesToInterfaces = [];
Expand Down
12 changes: 10 additions & 2 deletions generator/src/ExpressionClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Throwable;

use function array_map;
use function ucfirst;
use function var_export;

/**
Expand Down Expand Up @@ -64,8 +65,15 @@ public function createClassOrInterface(ExpressionDefinition $definition): PhpNam
$constructor->addParameter('name')->setType($propertyType);
$constructor->addBody('$this->name = $name;');
} elseif ($definition->generate === PhpObject::PhpInterface) {
$class = $namespace->addInterface($className);
$class->setExtends($definition->implements);
$interface = $namespace->addInterface($className);
$interface->setExtends($definition->implements);
} elseif ($definition->generate === PhpObject::PhpEnum) {
$enum = $namespace->addEnum($className);
$enum->setType('string');
array_map(
fn (string $case) => $enum->addCase(ucfirst($case), $case),
$definition->values,
);
} else {
throw new LogicException('Unknown generate type: ' . var_export($definition->generate, true));
}
Expand Down
6 changes: 6 additions & 0 deletions src/Builder/Accumulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
use MongoDB\Builder\Type\WindowInterface;
use stdClass;

/**
* Factories for Aggregation Pipeline Accumulator and Window Operators
*
* @see https://www.mongodb.com/docs/v3.4/reference/operator/aggregation-group/
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/
*/
enum Accumulator
{
use Accumulator\FactoryTrait;
Expand Down
24 changes: 6 additions & 18 deletions src/Builder/Accumulator/AddToSetAccumulator.php

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

9 changes: 4 additions & 5 deletions src/Builder/Accumulator/AvgAccumulator.php

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

19 changes: 5 additions & 14 deletions src/Builder/Accumulator/BottomAccumulator.php

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

18 changes: 5 additions & 13 deletions src/Builder/Accumulator/BottomNAccumulator.php

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

17 changes: 8 additions & 9 deletions src/Builder/Accumulator/CovariancePopAccumulator.php

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

17 changes: 8 additions & 9 deletions src/Builder/Accumulator/CovarianceSampAccumulator.php

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

9 changes: 4 additions & 5 deletions src/Builder/Accumulator/DerivativeAccumulator.php

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

9 changes: 4 additions & 5 deletions src/Builder/Accumulator/ExpMovingAvgAccumulator.php

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

Loading

0 comments on commit ad48be4

Please sign in to comment.