diff --git a/generator/config/expressions.php b/generator/config/expressions.php index 45e4c7ace..f77b45e79 100644 --- a/generator/config/expressions.php +++ b/generator/config/expressions.php @@ -13,7 +13,6 @@ use MongoDB\Model\BSONArray; use stdClass; -use function in_array; use function ucfirst; $bsonTypes = [ @@ -46,11 +45,6 @@ $expressions = []; $resolvesToInterfaces = []; foreach ($bsonTypes as $name => $acceptedTypes) { - // an expression can be a string with a $-prefixed field name - if (! in_array('string', $acceptedTypes)) { - $acceptedTypes[] = 'string'; - } - $expressions[$name] = ['acceptedTypes' => $acceptedTypes]; $resolvesTo = 'resolvesTo' . ucfirst($name); diff --git a/generator/src/OperatorClassGenerator.php b/generator/src/OperatorClassGenerator.php index 7f8667751..c0ab405c8 100644 --- a/generator/src/OperatorClassGenerator.php +++ b/generator/src/OperatorClassGenerator.php @@ -169,6 +169,18 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition PHP); } + + if ($type->dollarPrefixedString) { + $namespace->addUseFunction('is_string'); + $namespace->addUseFunction('str_starts_with'); + $namespace->addUse(InvalidArgumentException::class); + $constructor->addBody(<<propertyName}) && ! str_starts_with(\${$argument->propertyName}, '$')) { + throw new InvalidArgumentException('Argument \${$argument->propertyName} can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + + PHP); + } } // Set property from constructor argument diff --git a/generator/src/OperatorGenerator.php b/generator/src/OperatorGenerator.php index 0b9c60748..ffe0bb369 100644 --- a/generator/src/OperatorGenerator.php +++ b/generator/src/OperatorGenerator.php @@ -26,6 +26,7 @@ use function ltrim; use function sort; use function sprintf; +use function str_starts_with; use function ucfirst; use function usort; @@ -71,13 +72,19 @@ final protected function getType(string $type): ExpressionDefinition * Expression types can contain class names, interface, native types or "list". * PHPDoc types are more precise than native types, so we use them systematically even if redundant. * - * @return object{native:string,doc:string,use:list,list:bool,query:bool,javascript:bool} + * @return object{native:string,doc:string,use:list,list:bool,query:bool,javascript:bool,dollarPrefixedString:bool} */ final protected function getAcceptedTypes(ArgumentDefinition $arg): stdClass { $nativeTypes = []; + $dollarPrefixedString = false; + foreach ($arg->type as $type) { + if (str_starts_with($type, 'resolvesTo')) { + $dollarPrefixedString = true; + } + $type = $this->getType($type); $nativeTypes = array_merge($nativeTypes, $type->acceptedTypes); @@ -91,6 +98,14 @@ final protected function getAcceptedTypes(ArgumentDefinition $arg): stdClass $nativeTypes[] = Optional::class; } + // If the argument accepts an expression, a $-prefixed string is accepted (field path or variable) + // Checked only if the argument does not already accept a string + if (in_array('string', $nativeTypes, true)) { + $dollarPrefixedString = false; + } elseif ($dollarPrefixedString) { + $nativeTypes[] = 'string'; + } + $docTypes = $nativeTypes = array_unique($nativeTypes); $use = []; @@ -131,6 +146,7 @@ final protected function getAcceptedTypes(ArgumentDefinition $arg): stdClass 'list' => $listCheck, 'query' => $isQuery, 'javascript' => $isJavascript, + 'dollarPrefixedString' => $dollarPrefixedString, ]; } diff --git a/src/Builder/Accumulator/AccumulatorAccumulator.php b/src/Builder/Accumulator/AccumulatorAccumulator.php index e35737cbc..94c503996 100644 --- a/src/Builder/Accumulator/AccumulatorAccumulator.php +++ b/src/Builder/Accumulator/AccumulatorAccumulator.php @@ -21,6 +21,7 @@ use function array_is_list; use function is_array; use function is_string; +use function str_starts_with; /** * Defines a custom accumulator function. @@ -97,6 +98,10 @@ public function __construct( throw new InvalidArgumentException('Expected $accumulateArgs argument to be a list, got an associative array.'); } + if (is_string($accumulateArgs) && ! str_starts_with($accumulateArgs, '$')) { + throw new InvalidArgumentException('Argument $accumulateArgs can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->accumulateArgs = $accumulateArgs; if (is_string($merge)) { $merge = new Javascript($merge); @@ -108,6 +113,10 @@ public function __construct( throw new InvalidArgumentException('Expected $initArgs argument to be a list, got an associative array.'); } + if (is_string($initArgs) && ! str_starts_with($initArgs, '$')) { + throw new InvalidArgumentException('Argument $initArgs can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->initArgs = $initArgs; if (is_string($finalize)) { $finalize = new Javascript($finalize); diff --git a/src/Builder/Accumulator/AvgAccumulator.php b/src/Builder/Accumulator/AvgAccumulator.php index c8400e74c..afbb1747b 100644 --- a/src/Builder/Accumulator/AvgAccumulator.php +++ b/src/Builder/Accumulator/AvgAccumulator.php @@ -15,6 +15,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\WindowInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns an average of numerical values. Ignores non-numeric values. @@ -37,6 +41,10 @@ final class AvgAccumulator implements AccumulatorInterface, WindowInterface, Ope */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Accumulator/BottomNAccumulator.php b/src/Builder/Accumulator/BottomNAccumulator.php index c8dfa5635..3733889de 100644 --- a/src/Builder/Accumulator/BottomNAccumulator.php +++ b/src/Builder/Accumulator/BottomNAccumulator.php @@ -17,8 +17,12 @@ use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\WindowInterface; +use MongoDB\Exception\InvalidArgumentException; use stdClass; +use function is_string; +use function str_starts_with; + /** * Returns an aggregation of the bottom n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $bottomN returns all elements in the group. * New in MongoDB 5.2. @@ -52,6 +56,10 @@ public function __construct( Document|Serializable|stdClass|array $sortBy, Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, ) { + if (is_string($n) && ! str_starts_with($n, '$')) { + throw new InvalidArgumentException('Argument $n can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->n = $n; $this->sortBy = $sortBy; $this->output = $output; diff --git a/src/Builder/Accumulator/CovariancePopAccumulator.php b/src/Builder/Accumulator/CovariancePopAccumulator.php index 71d417c06..d845320a2 100644 --- a/src/Builder/Accumulator/CovariancePopAccumulator.php +++ b/src/Builder/Accumulator/CovariancePopAccumulator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\WindowInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the population covariance of two numeric expressions. @@ -42,7 +46,15 @@ public function __construct( Decimal128|Int64|ResolvesToNumber|float|int|string $expression1, Decimal128|Int64|ResolvesToNumber|float|int|string $expression2, ) { + if (is_string($expression1) && ! str_starts_with($expression1, '$')) { + throw new InvalidArgumentException('Argument $expression1 can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression1 = $expression1; + if (is_string($expression2) && ! str_starts_with($expression2, '$')) { + throw new InvalidArgumentException('Argument $expression2 can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Accumulator/CovarianceSampAccumulator.php b/src/Builder/Accumulator/CovarianceSampAccumulator.php index 660289d93..eacd66315 100644 --- a/src/Builder/Accumulator/CovarianceSampAccumulator.php +++ b/src/Builder/Accumulator/CovarianceSampAccumulator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\WindowInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the sample covariance of two numeric expressions. @@ -42,7 +46,15 @@ public function __construct( Decimal128|Int64|ResolvesToNumber|float|int|string $expression1, Decimal128|Int64|ResolvesToNumber|float|int|string $expression2, ) { + if (is_string($expression1) && ! str_starts_with($expression1, '$')) { + throw new InvalidArgumentException('Argument $expression1 can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression1 = $expression1; + if (is_string($expression2) && ! str_starts_with($expression2, '$')) { + throw new InvalidArgumentException('Argument $expression2 can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Accumulator/DerivativeAccumulator.php b/src/Builder/Accumulator/DerivativeAccumulator.php index 52287121a..7db64533f 100644 --- a/src/Builder/Accumulator/DerivativeAccumulator.php +++ b/src/Builder/Accumulator/DerivativeAccumulator.php @@ -19,6 +19,10 @@ use MongoDB\Builder\Type\Optional; use MongoDB\Builder\Type\TimeUnit; use MongoDB\Builder\Type\WindowInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the average rate of change within the specified window. @@ -51,6 +55,10 @@ public function __construct( Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input, Optional|ResolvesToString|TimeUnit|string $unit = Optional::Undefined, ) { + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; $this->unit = $unit; } diff --git a/src/Builder/Accumulator/ExpMovingAvgAccumulator.php b/src/Builder/Accumulator/ExpMovingAvgAccumulator.php index a80cacdb8..8df134bbc 100644 --- a/src/Builder/Accumulator/ExpMovingAvgAccumulator.php +++ b/src/Builder/Accumulator/ExpMovingAvgAccumulator.php @@ -15,6 +15,10 @@ use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; use MongoDB\Builder\Type\WindowInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the exponential moving average for the numeric expression. @@ -33,31 +37,35 @@ final class ExpMovingAvgAccumulator implements WindowInterface, OperatorInterfac public readonly Decimal128|Int64|ResolvesToNumber|float|int|string $input; /** - * @var Optional|int|string $N An integer that specifies the number of historical documents that have a significant mathematical weight in the exponential moving average calculation, with the most recent documents contributing the most weight. + * @var Optional|int $N An integer that specifies the number of historical documents that have a significant mathematical weight in the exponential moving average calculation, with the most recent documents contributing the most weight. * You must specify either N or alpha. You cannot specify both. * The N value is used in this formula to calculate the current result based on the expression value from the current document being read and the previous result of the calculation: */ - public readonly Optional|int|string $N; + public readonly Optional|int $N; /** - * @var Optional|Int64|float|int|string $alpha A double that specifies the exponential decay value to use in the exponential moving average calculation. A higher alpha value assigns a lower mathematical significance to previous results from the calculation. + * @var Optional|Int64|float|int $alpha A double that specifies the exponential decay value to use in the exponential moving average calculation. A higher alpha value assigns a lower mathematical significance to previous results from the calculation. * You must specify either N or alpha. You cannot specify both. */ - public readonly Optional|Int64|float|int|string $alpha; + public readonly Optional|Int64|float|int $alpha; /** * @param Decimal128|Int64|ResolvesToNumber|float|int|string $input - * @param Optional|int|string $N An integer that specifies the number of historical documents that have a significant mathematical weight in the exponential moving average calculation, with the most recent documents contributing the most weight. + * @param Optional|int $N An integer that specifies the number of historical documents that have a significant mathematical weight in the exponential moving average calculation, with the most recent documents contributing the most weight. * You must specify either N or alpha. You cannot specify both. * The N value is used in this formula to calculate the current result based on the expression value from the current document being read and the previous result of the calculation: - * @param Optional|Int64|float|int|string $alpha A double that specifies the exponential decay value to use in the exponential moving average calculation. A higher alpha value assigns a lower mathematical significance to previous results from the calculation. + * @param Optional|Int64|float|int $alpha A double that specifies the exponential decay value to use in the exponential moving average calculation. A higher alpha value assigns a lower mathematical significance to previous results from the calculation. * You must specify either N or alpha. You cannot specify both. */ public function __construct( Decimal128|Int64|ResolvesToNumber|float|int|string $input, - Optional|int|string $N = Optional::Undefined, - Optional|Int64|float|int|string $alpha = Optional::Undefined, + Optional|int $N = Optional::Undefined, + Optional|Int64|float|int $alpha = Optional::Undefined, ) { + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; $this->N = $N; $this->alpha = $alpha; diff --git a/src/Builder/Accumulator/FactoryTrait.php b/src/Builder/Accumulator/FactoryTrait.php index 0293a346c..512ff17bf 100644 --- a/src/Builder/Accumulator/FactoryTrait.php +++ b/src/Builder/Accumulator/FactoryTrait.php @@ -202,16 +202,16 @@ public static function documentNumber(): DocumentNumberAccumulator * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/ * @param Decimal128|Int64|ResolvesToNumber|float|int|string $input - * @param Optional|int|string $N An integer that specifies the number of historical documents that have a significant mathematical weight in the exponential moving average calculation, with the most recent documents contributing the most weight. + * @param Optional|int $N An integer that specifies the number of historical documents that have a significant mathematical weight in the exponential moving average calculation, with the most recent documents contributing the most weight. * You must specify either N or alpha. You cannot specify both. * The N value is used in this formula to calculate the current result based on the expression value from the current document being read and the previous result of the calculation: - * @param Optional|Int64|float|int|string $alpha A double that specifies the exponential decay value to use in the exponential moving average calculation. A higher alpha value assigns a lower mathematical significance to previous results from the calculation. + * @param Optional|Int64|float|int $alpha A double that specifies the exponential decay value to use in the exponential moving average calculation. A higher alpha value assigns a lower mathematical significance to previous results from the calculation. * You must specify either N or alpha. You cannot specify both. */ public static function expMovingAvg( Decimal128|Int64|ResolvesToNumber|float|int|string $input, - Optional|int|string $N = Optional::Undefined, - Optional|Int64|float|int|string $alpha = Optional::Undefined, + Optional|int $N = Optional::Undefined, + Optional|Int64|float|int $alpha = Optional::Undefined, ): ExpMovingAvgAccumulator { return new ExpMovingAvgAccumulator($input, $N, $alpha); } @@ -458,7 +458,7 @@ public static function rank(): RankAccumulator * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/ * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Specifies an expression to evaluate and return in the output. - * @param int|string $by Specifies an integer with a numeric document position relative to the current document in the output. + * @param int $by Specifies an integer with a numeric document position relative to the current document in the output. * For example: * 1 specifies the document position after the current document. * -1 specifies the document position before the current document. @@ -469,7 +469,7 @@ public static function rank(): RankAccumulator */ public static function shift( Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, - int|string $by, + int $by, Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default, ): ShiftAccumulator { return new ShiftAccumulator($output, $by, $default); diff --git a/src/Builder/Accumulator/FirstNAccumulator.php b/src/Builder/Accumulator/FirstNAccumulator.php index 77de95d20..55c2809d7 100644 --- a/src/Builder/Accumulator/FirstNAccumulator.php +++ b/src/Builder/Accumulator/FirstNAccumulator.php @@ -15,8 +15,12 @@ use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\WindowInterface; +use MongoDB\Exception\InvalidArgumentException; use stdClass; +use function is_string; +use function str_starts_with; + /** * Returns an aggregation of the first n elements within a group. * The elements returned are meaningful only if in a specified sort order. @@ -46,6 +50,10 @@ public function __construct( ResolvesToInt|int|string $n, ) { $this->input = $input; + if (is_string($n) && ! str_starts_with($n, '$')) { + throw new InvalidArgumentException('Argument $n can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->n = $n; } } diff --git a/src/Builder/Accumulator/IntegralAccumulator.php b/src/Builder/Accumulator/IntegralAccumulator.php index 72aaa9f94..a55a91062 100644 --- a/src/Builder/Accumulator/IntegralAccumulator.php +++ b/src/Builder/Accumulator/IntegralAccumulator.php @@ -19,6 +19,10 @@ use MongoDB\Builder\Type\Optional; use MongoDB\Builder\Type\TimeUnit; use MongoDB\Builder\Type\WindowInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the approximation of the area under a curve. @@ -51,6 +55,10 @@ public function __construct( Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $input, Optional|ResolvesToString|TimeUnit|string $unit = Optional::Undefined, ) { + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; $this->unit = $unit; } diff --git a/src/Builder/Accumulator/LastNAccumulator.php b/src/Builder/Accumulator/LastNAccumulator.php index 965a4ea89..67e1b0b0a 100644 --- a/src/Builder/Accumulator/LastNAccumulator.php +++ b/src/Builder/Accumulator/LastNAccumulator.php @@ -20,6 +20,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns an aggregation of the last n elements within a group. @@ -53,7 +55,15 @@ public function __construct( throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; + if (is_string($n) && ! str_starts_with($n, '$')) { + throw new InvalidArgumentException('Argument $n can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->n = $n; } } diff --git a/src/Builder/Accumulator/LinearFillAccumulator.php b/src/Builder/Accumulator/LinearFillAccumulator.php index aeda38df7..19126adbc 100644 --- a/src/Builder/Accumulator/LinearFillAccumulator.php +++ b/src/Builder/Accumulator/LinearFillAccumulator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\WindowInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Fills null and missing fields in a window using linear interpolation based on surrounding field values. @@ -37,6 +41,10 @@ final class LinearFillAccumulator implements WindowInterface, OperatorInterface */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Accumulator/MaxNAccumulator.php b/src/Builder/Accumulator/MaxNAccumulator.php index 3ac67bc48..e44e8953f 100644 --- a/src/Builder/Accumulator/MaxNAccumulator.php +++ b/src/Builder/Accumulator/MaxNAccumulator.php @@ -20,6 +20,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns the n largest values in an array. Distinct from the $maxN accumulator. @@ -51,7 +53,15 @@ public function __construct( throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; + if (is_string($n) && ! str_starts_with($n, '$')) { + throw new InvalidArgumentException('Argument $n can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->n = $n; } } diff --git a/src/Builder/Accumulator/MedianAccumulator.php b/src/Builder/Accumulator/MedianAccumulator.php index 01017e20a..cfdd05e8a 100644 --- a/src/Builder/Accumulator/MedianAccumulator.php +++ b/src/Builder/Accumulator/MedianAccumulator.php @@ -15,6 +15,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\WindowInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns an approximation of the median, the 50th percentile, as a scalar value. @@ -45,6 +49,10 @@ final class MedianAccumulator implements AccumulatorInterface, WindowInterface, */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $input, string $method) { + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; $this->method = $method; } diff --git a/src/Builder/Accumulator/MergeObjectsAccumulator.php b/src/Builder/Accumulator/MergeObjectsAccumulator.php index db8ee615e..0a567b771 100644 --- a/src/Builder/Accumulator/MergeObjectsAccumulator.php +++ b/src/Builder/Accumulator/MergeObjectsAccumulator.php @@ -14,8 +14,12 @@ use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; use stdClass; +use function is_string; +use function str_starts_with; + /** * Combines multiple documents into a single document. * @@ -36,6 +40,10 @@ final class MergeObjectsAccumulator implements AccumulatorInterface, OperatorInt */ public function __construct(Document|Serializable|ResolvesToObject|stdClass|array|string $document) { + if (is_string($document) && ! str_starts_with($document, '$')) { + throw new InvalidArgumentException('Argument $document can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->document = $document; } } diff --git a/src/Builder/Accumulator/MinNAccumulator.php b/src/Builder/Accumulator/MinNAccumulator.php index fb1a6ecc1..fc088a831 100644 --- a/src/Builder/Accumulator/MinNAccumulator.php +++ b/src/Builder/Accumulator/MinNAccumulator.php @@ -20,6 +20,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns the n smallest values in an array. Distinct from the $minN accumulator. @@ -51,7 +53,15 @@ public function __construct( throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; + if (is_string($n) && ! str_starts_with($n, '$')) { + throw new InvalidArgumentException('Argument $n can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->n = $n; } } diff --git a/src/Builder/Accumulator/PercentileAccumulator.php b/src/Builder/Accumulator/PercentileAccumulator.php index b3175a88c..7e6b4af67 100644 --- a/src/Builder/Accumulator/PercentileAccumulator.php +++ b/src/Builder/Accumulator/PercentileAccumulator.php @@ -22,6 +22,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns an array of scalar values that correspond to specified percentile values. @@ -66,11 +68,19 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $p, string $method, ) { + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; if (is_array($p) && ! array_is_list($p)) { throw new InvalidArgumentException('Expected $p argument to be a list, got an associative array.'); } + if (is_string($p) && ! str_starts_with($p, '$')) { + throw new InvalidArgumentException('Argument $p can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->p = $p; $this->method = $method; } diff --git a/src/Builder/Accumulator/ShiftAccumulator.php b/src/Builder/Accumulator/ShiftAccumulator.php index 8c24afab1..5f4200307 100644 --- a/src/Builder/Accumulator/ShiftAccumulator.php +++ b/src/Builder/Accumulator/ShiftAccumulator.php @@ -32,13 +32,13 @@ final class ShiftAccumulator implements WindowInterface, OperatorInterface public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output; /** - * @var int|string $by Specifies an integer with a numeric document position relative to the current document in the output. + * @var int $by Specifies an integer with a numeric document position relative to the current document in the output. * For example: * 1 specifies the document position after the current document. * -1 specifies the document position before the current document. * -2 specifies the document position that is two positions before the current document. */ - public readonly int|string $by; + public readonly int $by; /** * @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default Specifies an optional default expression to evaluate if the document position is outside of the implicit $setWindowFields stage window. The implicit window contains all the documents in the partition. @@ -49,7 +49,7 @@ final class ShiftAccumulator implements WindowInterface, OperatorInterface /** * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Specifies an expression to evaluate and return in the output. - * @param int|string $by Specifies an integer with a numeric document position relative to the current document in the output. + * @param int $by Specifies an integer with a numeric document position relative to the current document in the output. * For example: * 1 specifies the document position after the current document. * -1 specifies the document position before the current document. @@ -60,7 +60,7 @@ final class ShiftAccumulator implements WindowInterface, OperatorInterface */ public function __construct( Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, - int|string $by, + int $by, Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default, ) { $this->output = $output; diff --git a/src/Builder/Accumulator/StdDevPopAccumulator.php b/src/Builder/Accumulator/StdDevPopAccumulator.php index 5f6969fa9..dd234dab1 100644 --- a/src/Builder/Accumulator/StdDevPopAccumulator.php +++ b/src/Builder/Accumulator/StdDevPopAccumulator.php @@ -15,6 +15,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\WindowInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Calculates the population standard deviation of the input values. Use if the values encompass the entire population of data you want to represent and do not wish to generalize about a larger population. $stdDevPop ignores non-numeric values. @@ -38,6 +42,10 @@ final class StdDevPopAccumulator implements AccumulatorInterface, WindowInterfac */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Accumulator/StdDevSampAccumulator.php b/src/Builder/Accumulator/StdDevSampAccumulator.php index b081c7c03..897e08563 100644 --- a/src/Builder/Accumulator/StdDevSampAccumulator.php +++ b/src/Builder/Accumulator/StdDevSampAccumulator.php @@ -15,6 +15,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\WindowInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Calculates the sample standard deviation of the input values. Use if the values encompass a sample of a population of data from which to generalize about the population. $stdDevSamp ignores non-numeric values. @@ -38,6 +42,10 @@ final class StdDevSampAccumulator implements AccumulatorInterface, WindowInterfa */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Accumulator/SumAccumulator.php b/src/Builder/Accumulator/SumAccumulator.php index 2fa5b0b8f..fa8cdb642 100644 --- a/src/Builder/Accumulator/SumAccumulator.php +++ b/src/Builder/Accumulator/SumAccumulator.php @@ -15,6 +15,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\WindowInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns a sum of numerical values. Ignores non-numeric values. @@ -37,6 +41,10 @@ final class SumAccumulator implements AccumulatorInterface, WindowInterface, Ope */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Accumulator/TopNAccumulator.php b/src/Builder/Accumulator/TopNAccumulator.php index d506afd87..58e29fcaf 100644 --- a/src/Builder/Accumulator/TopNAccumulator.php +++ b/src/Builder/Accumulator/TopNAccumulator.php @@ -16,8 +16,12 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; use stdClass; +use function is_string; +use function str_starts_with; + /** * Returns an aggregation of the top n fields within a group, according to the specified sort order. * New in MongoDB 5.2. @@ -52,6 +56,10 @@ public function __construct( Document|Serializable|stdClass|array $sortBy, Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output, ) { + if (is_string($n) && ! str_starts_with($n, '$')) { + throw new InvalidArgumentException('Argument $n can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->n = $n; $this->sortBy = $sortBy; $this->output = $output; diff --git a/src/Builder/Expression/AbsOperator.php b/src/Builder/Expression/AbsOperator.php index 7905edfdb..817683be6 100644 --- a/src/Builder/Expression/AbsOperator.php +++ b/src/Builder/Expression/AbsOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the absolute value of a number. @@ -33,6 +37,10 @@ final class AbsOperator implements ResolvesToNumber, OperatorInterface */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $value) { + if (is_string($value) && ! str_starts_with($value, '$')) { + throw new InvalidArgumentException('Argument $value can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->value = $value; } } diff --git a/src/Builder/Expression/AcosOperator.php b/src/Builder/Expression/AcosOperator.php index 9bd357ed7..4b5017ec1 100644 --- a/src/Builder/Expression/AcosOperator.php +++ b/src/Builder/Expression/AcosOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the inverse cosine (arc cosine) of a value in radians. @@ -39,6 +43,10 @@ final class AcosOperator implements ResolvesToDouble, ResolvesToDecimal, Operato */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/AcoshOperator.php b/src/Builder/Expression/AcoshOperator.php index 30c8ac89f..1da690261 100644 --- a/src/Builder/Expression/AcoshOperator.php +++ b/src/Builder/Expression/AcoshOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the inverse hyperbolic cosine (hyperbolic arc cosine) of a value in radians. @@ -39,6 +43,10 @@ final class AcoshOperator implements ResolvesToDouble, ResolvesToDecimal, Operat */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/AllElementsTrueOperator.php b/src/Builder/Expression/AllElementsTrueOperator.php index ec170e888..4dd9c5b4b 100644 --- a/src/Builder/Expression/AllElementsTrueOperator.php +++ b/src/Builder/Expression/AllElementsTrueOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns true if no element of a set evaluates to false, otherwise, returns false. Accepts a single argument expression. @@ -41,6 +43,10 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $ throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); } + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/AnyElementTrueOperator.php b/src/Builder/Expression/AnyElementTrueOperator.php index 1ed6f1dd9..a37315e9d 100644 --- a/src/Builder/Expression/AnyElementTrueOperator.php +++ b/src/Builder/Expression/AnyElementTrueOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns true if any elements of a set evaluate to true; otherwise, returns false. Accepts a single argument expression. @@ -41,6 +43,10 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $ throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); } + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/ArrayElemAtOperator.php b/src/Builder/Expression/ArrayElemAtOperator.php index d7687eee3..0f492ce0b 100644 --- a/src/Builder/Expression/ArrayElemAtOperator.php +++ b/src/Builder/Expression/ArrayElemAtOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns the element at the specified array index. @@ -47,7 +49,15 @@ public function __construct( throw new InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); } + if (is_string($array) && ! str_starts_with($array, '$')) { + throw new InvalidArgumentException('Argument $array can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->array = $array; + if (is_string($idx) && ! str_starts_with($idx, '$')) { + throw new InvalidArgumentException('Argument $idx can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->idx = $idx; } } diff --git a/src/Builder/Expression/ArrayToObjectOperator.php b/src/Builder/Expression/ArrayToObjectOperator.php index 6a97594e3..77382c984 100644 --- a/src/Builder/Expression/ArrayToObjectOperator.php +++ b/src/Builder/Expression/ArrayToObjectOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Converts an array of key value pairs to a document. @@ -41,6 +43,10 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $ throw new InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); } + if (is_string($array) && ! str_starts_with($array, '$')) { + throw new InvalidArgumentException('Argument $array can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->array = $array; } } diff --git a/src/Builder/Expression/AsinOperator.php b/src/Builder/Expression/AsinOperator.php index 1cdd56910..d814f6cf1 100644 --- a/src/Builder/Expression/AsinOperator.php +++ b/src/Builder/Expression/AsinOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the inverse sin (arc sine) of a value in radians. @@ -39,6 +43,10 @@ final class AsinOperator implements ResolvesToDouble, ResolvesToDecimal, Operato */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/AsinhOperator.php b/src/Builder/Expression/AsinhOperator.php index 91d16061d..edc2f2062 100644 --- a/src/Builder/Expression/AsinhOperator.php +++ b/src/Builder/Expression/AsinhOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the inverse hyperbolic sine (hyperbolic arc sine) of a value in radians. @@ -39,6 +43,10 @@ final class AsinhOperator implements ResolvesToDouble, ResolvesToDecimal, Operat */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/Atan2Operator.php b/src/Builder/Expression/Atan2Operator.php index ba0dfe54f..f0af1fc97 100644 --- a/src/Builder/Expression/Atan2Operator.php +++ b/src/Builder/Expression/Atan2Operator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the inverse tangent (arc tangent) of y / x in radians, where y and x are the first and second values passed to the expression respectively. @@ -45,7 +49,15 @@ public function __construct( Decimal128|Int64|ResolvesToNumber|float|int|string $y, Decimal128|Int64|ResolvesToNumber|float|int|string $x, ) { + if (is_string($y) && ! str_starts_with($y, '$')) { + throw new InvalidArgumentException('Argument $y can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->y = $y; + if (is_string($x) && ! str_starts_with($x, '$')) { + throw new InvalidArgumentException('Argument $x can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->x = $x; } } diff --git a/src/Builder/Expression/AtanOperator.php b/src/Builder/Expression/AtanOperator.php index faa81825b..938a9b007 100644 --- a/src/Builder/Expression/AtanOperator.php +++ b/src/Builder/Expression/AtanOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the inverse tangent (arc tangent) of a value in radians. @@ -39,6 +43,10 @@ final class AtanOperator implements ResolvesToDouble, ResolvesToDecimal, Operato */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/AtanhOperator.php b/src/Builder/Expression/AtanhOperator.php index 6e19862e5..fde1dae12 100644 --- a/src/Builder/Expression/AtanhOperator.php +++ b/src/Builder/Expression/AtanhOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the inverse hyperbolic tangent (hyperbolic arc tangent) of a value in radians. @@ -39,6 +43,10 @@ final class AtanhOperator implements ResolvesToDouble, ResolvesToDecimal, Operat */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/BitNotOperator.php b/src/Builder/Expression/BitNotOperator.php index 4d9f623fa..adac4fc66 100644 --- a/src/Builder/Expression/BitNotOperator.php +++ b/src/Builder/Expression/BitNotOperator.php @@ -11,6 +11,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the result of a bitwise not operation on a single argument or an array that contains a single int or long value. @@ -33,6 +37,10 @@ final class BitNotOperator implements ResolvesToInt, ResolvesToLong, OperatorInt */ public function __construct(Int64|ResolvesToInt|ResolvesToLong|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/BsonSizeOperator.php b/src/Builder/Expression/BsonSizeOperator.php index 88c73fd80..37626d0d9 100644 --- a/src/Builder/Expression/BsonSizeOperator.php +++ b/src/Builder/Expression/BsonSizeOperator.php @@ -12,8 +12,12 @@ use MongoDB\BSON\Serializable; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; use stdClass; +use function is_string; +use function str_starts_with; + /** * Returns the size in bytes of a given document (i.e. BSON type Object) when encoded as BSON. * @@ -35,6 +39,10 @@ final class BsonSizeOperator implements ResolvesToInt, OperatorInterface public function __construct( Document|Serializable|ResolvesToNull|ResolvesToObject|stdClass|array|null|string $object, ) { + if (is_string($object) && ! str_starts_with($object, '$')) { + throw new InvalidArgumentException('Argument $object can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->object = $object; } } diff --git a/src/Builder/Expression/CaseOperator.php b/src/Builder/Expression/CaseOperator.php index a87c6d110..8680befdf 100644 --- a/src/Builder/Expression/CaseOperator.php +++ b/src/Builder/Expression/CaseOperator.php @@ -13,8 +13,12 @@ use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\SwitchBranchInterface; +use MongoDB\Exception\InvalidArgumentException; use stdClass; +use function is_string; +use function str_starts_with; + /** * Represents a single case in a $switch expression * @@ -41,6 +45,10 @@ public function __construct( ResolvesToBool|bool|string $case, Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then, ) { + if (is_string($case) && ! str_starts_with($case, '$')) { + throw new InvalidArgumentException('Argument $case can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->case = $case; $this->then = $then; } diff --git a/src/Builder/Expression/CeilOperator.php b/src/Builder/Expression/CeilOperator.php index 24feba8c4..9f318c454 100644 --- a/src/Builder/Expression/CeilOperator.php +++ b/src/Builder/Expression/CeilOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the smallest integer greater than or equal to the specified number. @@ -33,6 +37,10 @@ final class CeilOperator implements ResolvesToInt, OperatorInterface */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/CondOperator.php b/src/Builder/Expression/CondOperator.php index 6239dc73c..7c71f3396 100644 --- a/src/Builder/Expression/CondOperator.php +++ b/src/Builder/Expression/CondOperator.php @@ -12,8 +12,12 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; use stdClass; +use function is_string; +use function str_starts_with; + /** * A ternary operator that evaluates one expression, and depending on the result, returns the value of one of the other two expressions. Accepts either three expressions in an ordered list or three named parameters. * @@ -45,6 +49,10 @@ public function __construct( Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $then, Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $else, ) { + if (is_string($if) && ! str_starts_with($if, '$')) { + throw new InvalidArgumentException('Argument $if can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->if = $if; $this->then = $then; $this->else = $else; diff --git a/src/Builder/Expression/CosOperator.php b/src/Builder/Expression/CosOperator.php index 05d1b05b1..fdc5fe5f0 100644 --- a/src/Builder/Expression/CosOperator.php +++ b/src/Builder/Expression/CosOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the cosine of a value that is measured in radians. @@ -37,6 +41,10 @@ final class CosOperator implements ResolvesToDouble, ResolvesToDecimal, Operator */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/CoshOperator.php b/src/Builder/Expression/CoshOperator.php index 9f1d4cf9e..3133153a7 100644 --- a/src/Builder/Expression/CoshOperator.php +++ b/src/Builder/Expression/CoshOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the hyperbolic cosine of a value that is measured in radians. @@ -37,6 +41,10 @@ final class CoshOperator implements ResolvesToDouble, ResolvesToDecimal, Operato */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/DateAddOperator.php b/src/Builder/Expression/DateAddOperator.php index 00fc01492..1c23c4a26 100644 --- a/src/Builder/Expression/DateAddOperator.php +++ b/src/Builder/Expression/DateAddOperator.php @@ -16,6 +16,10 @@ use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; use MongoDB\Builder\Type\TimeUnit; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Adds a number of time units to a date object. @@ -53,8 +57,16 @@ public function __construct( Int64|ResolvesToInt|ResolvesToLong|int|string $amount, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($startDate) && ! str_starts_with($startDate, '$')) { + throw new InvalidArgumentException('Argument $startDate can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->startDate = $startDate; $this->unit = $unit; + if (is_string($amount) && ! str_starts_with($amount, '$')) { + throw new InvalidArgumentException('Argument $amount can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->amount = $amount; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/DateDiffOperator.php b/src/Builder/Expression/DateDiffOperator.php index c120e00a7..24b8fb50f 100644 --- a/src/Builder/Expression/DateDiffOperator.php +++ b/src/Builder/Expression/DateDiffOperator.php @@ -15,6 +15,10 @@ use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; use MongoDB\Builder\Type\TimeUnit; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the difference between two dates. @@ -64,7 +68,15 @@ public function __construct( Optional|ResolvesToString|string $timezone = Optional::Undefined, Optional|ResolvesToString|string $startOfWeek = Optional::Undefined, ) { + if (is_string($startDate) && ! str_starts_with($startDate, '$')) { + throw new InvalidArgumentException('Argument $startDate can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->startDate = $startDate; + if (is_string($endDate) && ! str_starts_with($endDate, '$')) { + throw new InvalidArgumentException('Argument $endDate can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->endDate = $endDate; $this->unit = $unit; $this->timezone = $timezone; diff --git a/src/Builder/Expression/DateFromPartsOperator.php b/src/Builder/Expression/DateFromPartsOperator.php index 216c5ae7a..c2d32c290 100644 --- a/src/Builder/Expression/DateFromPartsOperator.php +++ b/src/Builder/Expression/DateFromPartsOperator.php @@ -13,6 +13,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Constructs a BSON Date object given the date's constituent parts. @@ -98,15 +102,55 @@ public function __construct( Optional|Decimal128|Int64|ResolvesToNumber|float|int|string $millisecond = Optional::Undefined, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($year) && ! str_starts_with($year, '$')) { + throw new InvalidArgumentException('Argument $year can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->year = $year; + if (is_string($isoWeekYear) && ! str_starts_with($isoWeekYear, '$')) { + throw new InvalidArgumentException('Argument $isoWeekYear can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->isoWeekYear = $isoWeekYear; + if (is_string($month) && ! str_starts_with($month, '$')) { + throw new InvalidArgumentException('Argument $month can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->month = $month; + if (is_string($isoWeek) && ! str_starts_with($isoWeek, '$')) { + throw new InvalidArgumentException('Argument $isoWeek can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->isoWeek = $isoWeek; + if (is_string($day) && ! str_starts_with($day, '$')) { + throw new InvalidArgumentException('Argument $day can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->day = $day; + if (is_string($isoDayOfWeek) && ! str_starts_with($isoDayOfWeek, '$')) { + throw new InvalidArgumentException('Argument $isoDayOfWeek can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->isoDayOfWeek = $isoDayOfWeek; + if (is_string($hour) && ! str_starts_with($hour, '$')) { + throw new InvalidArgumentException('Argument $hour can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->hour = $hour; + if (is_string($minute) && ! str_starts_with($minute, '$')) { + throw new InvalidArgumentException('Argument $minute can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->minute = $minute; + if (is_string($second) && ! str_starts_with($second, '$')) { + throw new InvalidArgumentException('Argument $second can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->second = $second; + if (is_string($millisecond) && ! str_starts_with($millisecond, '$')) { + throw new InvalidArgumentException('Argument $millisecond can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->millisecond = $millisecond; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/DateSubtractOperator.php b/src/Builder/Expression/DateSubtractOperator.php index 9e9ec7212..3deda4b37 100644 --- a/src/Builder/Expression/DateSubtractOperator.php +++ b/src/Builder/Expression/DateSubtractOperator.php @@ -16,6 +16,10 @@ use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; use MongoDB\Builder\Type\TimeUnit; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Subtracts a number of time units from a date object. @@ -53,8 +57,16 @@ public function __construct( Int64|ResolvesToInt|ResolvesToLong|int|string $amount, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($startDate) && ! str_starts_with($startDate, '$')) { + throw new InvalidArgumentException('Argument $startDate can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->startDate = $startDate; $this->unit = $unit; + if (is_string($amount) && ! str_starts_with($amount, '$')) { + throw new InvalidArgumentException('Argument $amount can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->amount = $amount; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/DateToPartsOperator.php b/src/Builder/Expression/DateToPartsOperator.php index 811797b3d..14771858f 100644 --- a/src/Builder/Expression/DateToPartsOperator.php +++ b/src/Builder/Expression/DateToPartsOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns a document containing the constituent parts of a date. @@ -33,19 +37,23 @@ final class DateToPartsOperator implements ResolvesToObject, OperatorInterface /** @var Optional|ResolvesToString|string $timezone The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. */ public readonly Optional|ResolvesToString|string $timezone; - /** @var Optional|bool|string $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. */ - public readonly Optional|bool|string $iso8601; + /** @var Optional|bool $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. */ + public readonly Optional|bool $iso8601; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. - * @param Optional|bool|string $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. + * @param Optional|bool $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, - Optional|bool|string $iso8601 = Optional::Undefined, + Optional|bool $iso8601 = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; $this->iso8601 = $iso8601; diff --git a/src/Builder/Expression/DateToStringOperator.php b/src/Builder/Expression/DateToStringOperator.php index 6b9b39178..7861f6990 100644 --- a/src/Builder/Expression/DateToStringOperator.php +++ b/src/Builder/Expression/DateToStringOperator.php @@ -16,8 +16,12 @@ use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; use stdClass; +use function is_string; +use function str_starts_with; + /** * Returns the date as a formatted string. * @@ -62,6 +66,10 @@ public function __construct( Optional|ResolvesToString|string $timezone = Optional::Undefined, Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->format = $format; $this->timezone = $timezone; diff --git a/src/Builder/Expression/DateTruncOperator.php b/src/Builder/Expression/DateTruncOperator.php index 4570d4980..9e84976dd 100644 --- a/src/Builder/Expression/DateTruncOperator.php +++ b/src/Builder/Expression/DateTruncOperator.php @@ -17,6 +17,10 @@ use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; use MongoDB\Builder\Type\TimeUnit; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Truncates a date. @@ -78,8 +82,16 @@ public function __construct( Optional|ResolvesToString|string $timezone = Optional::Undefined, Optional|string $startOfWeek = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->unit = $unit; + if (is_string($binSize) && ! str_starts_with($binSize, '$')) { + throw new InvalidArgumentException('Argument $binSize can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->binSize = $binSize; $this->timezone = $timezone; $this->startOfWeek = $startOfWeek; diff --git a/src/Builder/Expression/DayOfMonthOperator.php b/src/Builder/Expression/DayOfMonthOperator.php index 9c20e556d..041680cae 100644 --- a/src/Builder/Expression/DayOfMonthOperator.php +++ b/src/Builder/Expression/DayOfMonthOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the day of the month for a date as a number between 1 and 31. @@ -41,6 +45,10 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/DayOfWeekOperator.php b/src/Builder/Expression/DayOfWeekOperator.php index 166b674f8..ac3a2ec6d 100644 --- a/src/Builder/Expression/DayOfWeekOperator.php +++ b/src/Builder/Expression/DayOfWeekOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday). @@ -41,6 +45,10 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/DayOfYearOperator.php b/src/Builder/Expression/DayOfYearOperator.php index 09150ab85..dff335adb 100644 --- a/src/Builder/Expression/DayOfYearOperator.php +++ b/src/Builder/Expression/DayOfYearOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the day of the year for a date as a number between 1 and 366 (leap year). @@ -41,6 +45,10 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/DegreesToRadiansOperator.php b/src/Builder/Expression/DegreesToRadiansOperator.php index 27d300211..45482c733 100644 --- a/src/Builder/Expression/DegreesToRadiansOperator.php +++ b/src/Builder/Expression/DegreesToRadiansOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Converts a value from degrees to radians. @@ -37,6 +41,10 @@ final class DegreesToRadiansOperator implements ResolvesToDouble, ResolvesToDeci */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/DivideOperator.php b/src/Builder/Expression/DivideOperator.php index 6911e5d44..55ba88b21 100644 --- a/src/Builder/Expression/DivideOperator.php +++ b/src/Builder/Expression/DivideOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the result of dividing the first number by the second. Accepts two argument expressions. @@ -39,7 +43,15 @@ public function __construct( Decimal128|Int64|ResolvesToNumber|float|int|string $dividend, Decimal128|Int64|ResolvesToNumber|float|int|string $divisor, ) { + if (is_string($dividend) && ! str_starts_with($dividend, '$')) { + throw new InvalidArgumentException('Argument $dividend can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->dividend = $dividend; + if (is_string($divisor) && ! str_starts_with($divisor, '$')) { + throw new InvalidArgumentException('Argument $divisor can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->divisor = $divisor; } } diff --git a/src/Builder/Expression/ExpOperator.php b/src/Builder/Expression/ExpOperator.php index a7a8e886f..5aab19c1e 100644 --- a/src/Builder/Expression/ExpOperator.php +++ b/src/Builder/Expression/ExpOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Raises e to the specified exponent. @@ -33,6 +37,10 @@ final class ExpOperator implements ResolvesToDouble, OperatorInterface */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $exponent) { + if (is_string($exponent) && ! str_starts_with($exponent, '$')) { + throw new InvalidArgumentException('Argument $exponent can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->exponent = $exponent; } } diff --git a/src/Builder/Expression/FactoryTrait.php b/src/Builder/Expression/FactoryTrait.php index 26117454c..cb6ed577d 100644 --- a/src/Builder/Expression/FactoryTrait.php +++ b/src/Builder/Expression/FactoryTrait.php @@ -543,12 +543,12 @@ public static function dateSubtract( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToParts/ * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int|string $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|string $timezone The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. - * @param Optional|bool|string $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. + * @param Optional|bool $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. */ public static function dateToParts( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, - Optional|bool|string $iso8601 = Optional::Undefined, + Optional|bool $iso8601 = Optional::Undefined, ): DateToPartsOperator { return new DateToPartsOperator($date, $timezone, $iso8601); } @@ -752,12 +752,12 @@ public static function floor(Decimal128|Int64|ResolvesToNumber|float|int|string * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/ * @param Javascript|string $body The function definition. You can specify the function definition as either BSON\JavaScript or string. * function(arg1, arg2, ...) { ... } - * @param BSONArray|PackedArray|array|string $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. + * @param BSONArray|PackedArray|array $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. * @param string $lang */ public static function function( Javascript|string $body, - PackedArray|BSONArray|array|string $args = [], + PackedArray|BSONArray|array $args = [], string $lang = 'js', ): FunctionOperator { return new FunctionOperator($body, $args, $lang); @@ -1013,12 +1013,12 @@ public static function lastN( * Accepts any number of argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/ - * @param Document|Serializable|array|stdClass|string $vars Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value. + * @param Document|Serializable|array|stdClass $vars Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value. * The variable assignments have no meaning outside the in expression, not even within the vars block itself. * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in The expression to evaluate. */ public static function let( - Document|Serializable|stdClass|array|string $vars, + Document|Serializable|stdClass|array $vars, Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, ): LetOperator { return new LetOperator($vars, $in); @@ -1741,11 +1741,11 @@ public static function slice( * @param BSONArray|PackedArray|ResolvesToArray|array|string $input The array to be sorted. * The result is null if the expression: is missing, evaluates to null, or evaluates to undefined * If the expression evaluates to any other non-array value, the document returns an error. - * @param Document|Serializable|Sort|array|int|stdClass|string $sortBy The document specifies a sort ordering. + * @param Document|Serializable|Sort|array|int|stdClass $sortBy The document specifies a sort ordering. */ public static function sortArray( PackedArray|ResolvesToArray|BSONArray|array|string $input, - Document|Serializable|Sort|stdClass|array|int|string $sortBy, + Document|Serializable|Sort|stdClass|array|int $sortBy, ): SortArrayOperator { return new SortArrayOperator($input, $sortBy); } @@ -1918,7 +1918,7 @@ public static function sum( * Evaluates a series of case expressions. When it finds an expression which evaluates to true, $switch executes a specified expression and breaks out of the control flow. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/ - * @param BSONArray|PackedArray|array|string $branches An array of control branch documents. Each branch is a document with the following fields: + * @param BSONArray|PackedArray|array $branches An array of control branch documents. Each branch is a document with the following fields: * - case Can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value. More information about how MongoDB evaluates expressions as either true or false can be found here. * - then Can be any valid expression. * The branches array must contain at least one branch document. @@ -1926,7 +1926,7 @@ public static function sum( * Although optional, if default is unspecified and no branch case evaluates to true, $switch returns an error. */ public static function switch( - PackedArray|BSONArray|array|string $branches, + PackedArray|BSONArray|array $branches, Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, ): SwitchOperator { return new SwitchOperator($branches, $default); @@ -2212,16 +2212,16 @@ public static function year( * @param BSONArray|PackedArray|ResolvesToArray|array|string $inputs An array of expressions that resolve to arrays. The elements of these input arrays combine to form the arrays of the output array. * If any of the inputs arrays resolves to a value of null or refers to a missing field, $zip returns null. * If any of the inputs arrays does not resolve to an array or null nor refers to a missing field, $zip returns an error. - * @param Optional|bool|string $useLongestLength A boolean which specifies whether the length of the longest array determines the number of arrays in the output array. + * @param Optional|bool $useLongestLength A boolean which specifies whether the length of the longest array determines the number of arrays in the output array. * The default value is false: the shortest array length determines the number of arrays in the output array. - * @param Optional|BSONArray|PackedArray|array|string $defaults An array of default element values to use if the input arrays have different lengths. You must specify useLongestLength: true along with this field, or else $zip will return an error. + * @param Optional|BSONArray|PackedArray|array $defaults An array of default element values to use if the input arrays have different lengths. You must specify useLongestLength: true along with this field, or else $zip will return an error. * If useLongestLength: true but defaults is empty or not specified, $zip uses null as the default value. * If specifying a non-empty defaults, you must specify a default for each input array or else $zip will return an error. */ public static function zip( PackedArray|ResolvesToArray|BSONArray|array|string $inputs, - Optional|bool|string $useLongestLength = Optional::Undefined, - Optional|PackedArray|BSONArray|array|string $defaults = Optional::Undefined, + Optional|bool $useLongestLength = Optional::Undefined, + Optional|PackedArray|BSONArray|array $defaults = Optional::Undefined, ): ZipOperator { return new ZipOperator($inputs, $useLongestLength, $defaults); } diff --git a/src/Builder/Expression/FilterOperator.php b/src/Builder/Expression/FilterOperator.php index ad8e2798b..62f3b8c6c 100644 --- a/src/Builder/Expression/FilterOperator.php +++ b/src/Builder/Expression/FilterOperator.php @@ -17,6 +17,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Selects a subset of the array to return an array with only the elements that match the filter condition. @@ -62,9 +64,21 @@ public function __construct( throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; + if (is_string($cond) && ! str_starts_with($cond, '$')) { + throw new InvalidArgumentException('Argument $cond can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->cond = $cond; $this->as = $as; + if (is_string($limit) && ! str_starts_with($limit, '$')) { + throw new InvalidArgumentException('Argument $limit can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->limit = $limit; } } diff --git a/src/Builder/Expression/FirstNOperator.php b/src/Builder/Expression/FirstNOperator.php index 718d49243..19f90488a 100644 --- a/src/Builder/Expression/FirstNOperator.php +++ b/src/Builder/Expression/FirstNOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns a specified number of elements from the beginning of an array. @@ -43,11 +45,19 @@ public function __construct( ResolvesToInt|int|string $n, PackedArray|ResolvesToArray|BSONArray|array|string $input, ) { + if (is_string($n) && ! str_starts_with($n, '$')) { + throw new InvalidArgumentException('Argument $n can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->n = $n; if (is_array($input) && ! array_is_list($input)) { throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; } } diff --git a/src/Builder/Expression/FirstOperator.php b/src/Builder/Expression/FirstOperator.php index a8ddd4d58..db7f547fc 100644 --- a/src/Builder/Expression/FirstOperator.php +++ b/src/Builder/Expression/FirstOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns the result of an expression for the first document in an array. @@ -41,6 +43,10 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $ throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); } + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/FloorOperator.php b/src/Builder/Expression/FloorOperator.php index 6697c5394..b81d5e05f 100644 --- a/src/Builder/Expression/FloorOperator.php +++ b/src/Builder/Expression/FloorOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the largest integer less than or equal to the specified number. @@ -33,6 +37,10 @@ final class FloorOperator implements ResolvesToInt, OperatorInterface */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/FunctionOperator.php b/src/Builder/Expression/FunctionOperator.php index 8f25666d8..516729e3a 100644 --- a/src/Builder/Expression/FunctionOperator.php +++ b/src/Builder/Expression/FunctionOperator.php @@ -38,8 +38,8 @@ final class FunctionOperator implements ResolvesToAny, OperatorInterface */ public readonly Javascript|string $body; - /** @var BSONArray|PackedArray|array|string $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. */ - public readonly PackedArray|BSONArray|array|string $args; + /** @var BSONArray|PackedArray|array $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. */ + public readonly PackedArray|BSONArray|array $args; /** @var string $lang */ public readonly string $lang; @@ -47,14 +47,11 @@ final class FunctionOperator implements ResolvesToAny, OperatorInterface /** * @param Javascript|string $body The function definition. You can specify the function definition as either BSON\JavaScript or string. * function(arg1, arg2, ...) { ... } - * @param BSONArray|PackedArray|array|string $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. + * @param BSONArray|PackedArray|array $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. * @param string $lang */ - public function __construct( - Javascript|string $body, - PackedArray|BSONArray|array|string $args = [], - string $lang = 'js', - ) { + public function __construct(Javascript|string $body, PackedArray|BSONArray|array $args = [], string $lang = 'js') + { if (is_string($body)) { $body = new Javascript($body); } diff --git a/src/Builder/Expression/HourOperator.php b/src/Builder/Expression/HourOperator.php index 89ad6a84c..8110c09c4 100644 --- a/src/Builder/Expression/HourOperator.php +++ b/src/Builder/Expression/HourOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the hour for a date as a number between 0 and 23. @@ -41,6 +45,10 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/InOperator.php b/src/Builder/Expression/InOperator.php index c63e1b509..bddbe6e29 100644 --- a/src/Builder/Expression/InOperator.php +++ b/src/Builder/Expression/InOperator.php @@ -19,6 +19,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns a boolean indicating whether a specified value is in an array. @@ -51,6 +53,10 @@ public function __construct( throw new InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); } + if (is_string($array) && ! str_starts_with($array, '$')) { + throw new InvalidArgumentException('Argument $array can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->array = $array; } } diff --git a/src/Builder/Expression/IndexOfArrayOperator.php b/src/Builder/Expression/IndexOfArrayOperator.php index 915732f52..29c0dad41 100644 --- a/src/Builder/Expression/IndexOfArrayOperator.php +++ b/src/Builder/Expression/IndexOfArrayOperator.php @@ -20,6 +20,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Searches an array for an occurrence of a specified value and returns the array index of the first occurrence. Array indexes start at zero. @@ -75,9 +77,21 @@ public function __construct( throw new InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); } + if (is_string($array) && ! str_starts_with($array, '$')) { + throw new InvalidArgumentException('Argument $array can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->array = $array; $this->search = $search; + if (is_string($start) && ! str_starts_with($start, '$')) { + throw new InvalidArgumentException('Argument $start can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->start = $start; + if (is_string($end) && ! str_starts_with($end, '$')) { + throw new InvalidArgumentException('Argument $end can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->end = $end; } } diff --git a/src/Builder/Expression/IndexOfBytesOperator.php b/src/Builder/Expression/IndexOfBytesOperator.php index 2ffe996a8..e2f2a1cae 100644 --- a/src/Builder/Expression/IndexOfBytesOperator.php +++ b/src/Builder/Expression/IndexOfBytesOperator.php @@ -11,6 +11,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Searches a string for an occurrence of a substring and returns the UTF-8 byte index of the first occurrence. If the substring is not found, returns -1. @@ -64,7 +68,15 @@ public function __construct( ) { $this->string = $string; $this->substring = $substring; + if (is_string($start) && ! str_starts_with($start, '$')) { + throw new InvalidArgumentException('Argument $start can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->start = $start; + if (is_string($end) && ! str_starts_with($end, '$')) { + throw new InvalidArgumentException('Argument $end can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->end = $end; } } diff --git a/src/Builder/Expression/IndexOfCPOperator.php b/src/Builder/Expression/IndexOfCPOperator.php index 32161814f..67b0c33ea 100644 --- a/src/Builder/Expression/IndexOfCPOperator.php +++ b/src/Builder/Expression/IndexOfCPOperator.php @@ -11,6 +11,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Searches a string for an occurrence of a substring and returns the UTF-8 code point index of the first occurrence. If the substring is not found, returns -1 @@ -64,7 +68,15 @@ public function __construct( ) { $this->string = $string; $this->substring = $substring; + if (is_string($start) && ! str_starts_with($start, '$')) { + throw new InvalidArgumentException('Argument $start can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->start = $start; + if (is_string($end) && ! str_starts_with($end, '$')) { + throw new InvalidArgumentException('Argument $end can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->end = $end; } } diff --git a/src/Builder/Expression/IsoDayOfWeekOperator.php b/src/Builder/Expression/IsoDayOfWeekOperator.php index 3cf6098ae..7ae8e19f1 100644 --- a/src/Builder/Expression/IsoDayOfWeekOperator.php +++ b/src/Builder/Expression/IsoDayOfWeekOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the weekday number in ISO 8601 format, ranging from 1 (for Monday) to 7 (for Sunday). @@ -41,6 +45,10 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/IsoWeekOperator.php b/src/Builder/Expression/IsoWeekOperator.php index a66e2fe60..7a500f174 100644 --- a/src/Builder/Expression/IsoWeekOperator.php +++ b/src/Builder/Expression/IsoWeekOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the week number in ISO 8601 format, ranging from 1 to 53. Week numbers start at 1 with the week (Monday through Sunday) that contains the year's first Thursday. @@ -41,6 +45,10 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/IsoWeekYearOperator.php b/src/Builder/Expression/IsoWeekYearOperator.php index 25ec81582..b558a38c0 100644 --- a/src/Builder/Expression/IsoWeekYearOperator.php +++ b/src/Builder/Expression/IsoWeekYearOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the year number in ISO 8601 format. The year starts with the Monday of week 1 (ISO 8601) and ends with the Sunday of the last week (ISO 8601). @@ -41,6 +45,10 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/LastNOperator.php b/src/Builder/Expression/LastNOperator.php index cd74971c3..930fe1196 100644 --- a/src/Builder/Expression/LastNOperator.php +++ b/src/Builder/Expression/LastNOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns a specified number of elements from the end of an array. @@ -43,11 +45,19 @@ public function __construct( ResolvesToInt|int|string $n, PackedArray|ResolvesToArray|BSONArray|array|string $input, ) { + if (is_string($n) && ! str_starts_with($n, '$')) { + throw new InvalidArgumentException('Argument $n can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->n = $n; if (is_array($input) && ! array_is_list($input)) { throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; } } diff --git a/src/Builder/Expression/LastOperator.php b/src/Builder/Expression/LastOperator.php index 48313100e..e4104948a 100644 --- a/src/Builder/Expression/LastOperator.php +++ b/src/Builder/Expression/LastOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns the result of an expression for the last document in an array. @@ -41,6 +43,10 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $ throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); } + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/LetOperator.php b/src/Builder/Expression/LetOperator.php index ed29e21b2..3f0fde195 100644 --- a/src/Builder/Expression/LetOperator.php +++ b/src/Builder/Expression/LetOperator.php @@ -30,21 +30,21 @@ final class LetOperator implements ResolvesToAny, OperatorInterface public const PROPERTIES = ['vars' => 'vars', 'in' => 'in']; /** - * @var Document|Serializable|array|stdClass|string $vars Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value. + * @var Document|Serializable|array|stdClass $vars Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value. * The variable assignments have no meaning outside the in expression, not even within the vars block itself. */ - public readonly Document|Serializable|stdClass|array|string $vars; + public readonly Document|Serializable|stdClass|array $vars; /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in The expression to evaluate. */ public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in; /** - * @param Document|Serializable|array|stdClass|string $vars Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value. + * @param Document|Serializable|array|stdClass $vars Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value. * The variable assignments have no meaning outside the in expression, not even within the vars block itself. * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $in The expression to evaluate. */ public function __construct( - Document|Serializable|stdClass|array|string $vars, + Document|Serializable|stdClass|array $vars, Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, ) { $this->vars = $vars; diff --git a/src/Builder/Expression/LnOperator.php b/src/Builder/Expression/LnOperator.php index 31e55bdc9..1848fbec6 100644 --- a/src/Builder/Expression/LnOperator.php +++ b/src/Builder/Expression/LnOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Calculates the natural log of a number. @@ -34,6 +38,10 @@ final class LnOperator implements ResolvesToDouble, OperatorInterface */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $number) { + if (is_string($number) && ! str_starts_with($number, '$')) { + throw new InvalidArgumentException('Argument $number can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->number = $number; } } diff --git a/src/Builder/Expression/Log10Operator.php b/src/Builder/Expression/Log10Operator.php index 408fde884..24ea9824d 100644 --- a/src/Builder/Expression/Log10Operator.php +++ b/src/Builder/Expression/Log10Operator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Calculates the log base 10 of a number. @@ -33,6 +37,10 @@ final class Log10Operator implements ResolvesToDouble, OperatorInterface */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $number) { + if (is_string($number) && ! str_starts_with($number, '$')) { + throw new InvalidArgumentException('Argument $number can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->number = $number; } } diff --git a/src/Builder/Expression/LogOperator.php b/src/Builder/Expression/LogOperator.php index 43d9b0b8b..b61fa3bef 100644 --- a/src/Builder/Expression/LogOperator.php +++ b/src/Builder/Expression/LogOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Calculates the log of a number in the specified base. @@ -39,7 +43,15 @@ public function __construct( Decimal128|Int64|ResolvesToNumber|float|int|string $number, Decimal128|Int64|ResolvesToNumber|float|int|string $base, ) { + if (is_string($number) && ! str_starts_with($number, '$')) { + throw new InvalidArgumentException('Argument $number can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->number = $number; + if (is_string($base) && ! str_starts_with($base, '$')) { + throw new InvalidArgumentException('Argument $base can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->base = $base; } } diff --git a/src/Builder/Expression/MapOperator.php b/src/Builder/Expression/MapOperator.php index 83317b08d..eecdc1fd0 100644 --- a/src/Builder/Expression/MapOperator.php +++ b/src/Builder/Expression/MapOperator.php @@ -20,6 +20,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Applies a subexpression to each element of an array and returns the array of resulting values in order. Accepts named parameters. @@ -56,6 +58,10 @@ public function __construct( throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; $this->in = $in; $this->as = $as; diff --git a/src/Builder/Expression/MaxNOperator.php b/src/Builder/Expression/MaxNOperator.php index 51c2240a3..76f9f6ea9 100644 --- a/src/Builder/Expression/MaxNOperator.php +++ b/src/Builder/Expression/MaxNOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns the n largest values in an array. Distinct from the $maxN accumulator. @@ -47,7 +49,15 @@ public function __construct( throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; + if (is_string($n) && ! str_starts_with($n, '$')) { + throw new InvalidArgumentException('Argument $n can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->n = $n; } } diff --git a/src/Builder/Expression/MedianOperator.php b/src/Builder/Expression/MedianOperator.php index 94aa08a2d..ee1547f50 100644 --- a/src/Builder/Expression/MedianOperator.php +++ b/src/Builder/Expression/MedianOperator.php @@ -18,6 +18,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns an approximation of the median, the 50th percentile, as a scalar value. @@ -54,6 +56,10 @@ public function __construct( throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; $this->method = $method; } diff --git a/src/Builder/Expression/MillisecondOperator.php b/src/Builder/Expression/MillisecondOperator.php index a7565420d..c7bc41dfd 100644 --- a/src/Builder/Expression/MillisecondOperator.php +++ b/src/Builder/Expression/MillisecondOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the milliseconds of a date as a number between 0 and 999. @@ -41,6 +45,10 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/MinNOperator.php b/src/Builder/Expression/MinNOperator.php index 9badbbb84..031b03179 100644 --- a/src/Builder/Expression/MinNOperator.php +++ b/src/Builder/Expression/MinNOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns the n smallest values in an array. Distinct from the $minN accumulator. @@ -47,7 +49,15 @@ public function __construct( throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; + if (is_string($n) && ! str_starts_with($n, '$')) { + throw new InvalidArgumentException('Argument $n can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->n = $n; } } diff --git a/src/Builder/Expression/MinuteOperator.php b/src/Builder/Expression/MinuteOperator.php index 0b76cc739..23b1ad12d 100644 --- a/src/Builder/Expression/MinuteOperator.php +++ b/src/Builder/Expression/MinuteOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the minute for a date as a number between 0 and 59. @@ -41,6 +45,10 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/ModOperator.php b/src/Builder/Expression/ModOperator.php index 40e56e041..0e7a44df8 100644 --- a/src/Builder/Expression/ModOperator.php +++ b/src/Builder/Expression/ModOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the remainder of the first number divided by the second. Accepts two argument expressions. @@ -39,7 +43,15 @@ public function __construct( Decimal128|Int64|ResolvesToNumber|float|int|string $dividend, Decimal128|Int64|ResolvesToNumber|float|int|string $divisor, ) { + if (is_string($dividend) && ! str_starts_with($dividend, '$')) { + throw new InvalidArgumentException('Argument $dividend can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->dividend = $dividend; + if (is_string($divisor) && ! str_starts_with($divisor, '$')) { + throw new InvalidArgumentException('Argument $divisor can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->divisor = $divisor; } } diff --git a/src/Builder/Expression/MonthOperator.php b/src/Builder/Expression/MonthOperator.php index 7670c71e3..e6351e1a8 100644 --- a/src/Builder/Expression/MonthOperator.php +++ b/src/Builder/Expression/MonthOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the month for a date as a number between 1 (January) and 12 (December). @@ -41,6 +45,10 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/ObjectToArrayOperator.php b/src/Builder/Expression/ObjectToArrayOperator.php index a3de6eeb9..c8a260970 100644 --- a/src/Builder/Expression/ObjectToArrayOperator.php +++ b/src/Builder/Expression/ObjectToArrayOperator.php @@ -12,8 +12,12 @@ use MongoDB\BSON\Serializable; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; use stdClass; +use function is_string; +use function str_starts_with; + /** * Converts a document to an array of documents representing key-value pairs. * @@ -34,6 +38,10 @@ final class ObjectToArrayOperator implements ResolvesToArray, OperatorInterface */ public function __construct(Document|Serializable|ResolvesToObject|stdClass|array|string $object) { + if (is_string($object) && ! str_starts_with($object, '$')) { + throw new InvalidArgumentException('Argument $object can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->object = $object; } } diff --git a/src/Builder/Expression/PercentileOperator.php b/src/Builder/Expression/PercentileOperator.php index db6101b95..133a04f7b 100644 --- a/src/Builder/Expression/PercentileOperator.php +++ b/src/Builder/Expression/PercentileOperator.php @@ -18,6 +18,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns an array of scalar values that correspond to specified percentile values. @@ -66,11 +68,19 @@ public function __construct( throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; if (is_array($p) && ! array_is_list($p)) { throw new InvalidArgumentException('Expected $p argument to be a list, got an associative array.'); } + if (is_string($p) && ! str_starts_with($p, '$')) { + throw new InvalidArgumentException('Argument $p can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->p = $p; $this->method = $method; } diff --git a/src/Builder/Expression/PowOperator.php b/src/Builder/Expression/PowOperator.php index 2397dc57e..bf132280f 100644 --- a/src/Builder/Expression/PowOperator.php +++ b/src/Builder/Expression/PowOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Raises a number to the specified exponent. @@ -39,7 +43,15 @@ public function __construct( Decimal128|Int64|ResolvesToNumber|float|int|string $number, Decimal128|Int64|ResolvesToNumber|float|int|string $exponent, ) { + if (is_string($number) && ! str_starts_with($number, '$')) { + throw new InvalidArgumentException('Argument $number can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->number = $number; + if (is_string($exponent) && ! str_starts_with($exponent, '$')) { + throw new InvalidArgumentException('Argument $exponent can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->exponent = $exponent; } } diff --git a/src/Builder/Expression/RadiansToDegreesOperator.php b/src/Builder/Expression/RadiansToDegreesOperator.php index d27ad314d..c8e4d5292 100644 --- a/src/Builder/Expression/RadiansToDegreesOperator.php +++ b/src/Builder/Expression/RadiansToDegreesOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Converts a value from radians to degrees. @@ -33,6 +37,10 @@ final class RadiansToDegreesOperator implements ResolvesToDouble, ResolvesToDeci */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/RangeOperator.php b/src/Builder/Expression/RangeOperator.php index e5e067bc3..1b96eb826 100644 --- a/src/Builder/Expression/RangeOperator.php +++ b/src/Builder/Expression/RangeOperator.php @@ -11,6 +11,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Outputs an array containing a sequence of integers according to user-defined inputs. @@ -43,8 +47,20 @@ public function __construct( ResolvesToInt|int|string $end, Optional|ResolvesToInt|int|string $step = Optional::Undefined, ) { + if (is_string($start) && ! str_starts_with($start, '$')) { + throw new InvalidArgumentException('Argument $start can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->start = $start; + if (is_string($end) && ! str_starts_with($end, '$')) { + throw new InvalidArgumentException('Argument $end can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->end = $end; + if (is_string($step) && ! str_starts_with($step, '$')) { + throw new InvalidArgumentException('Argument $step can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->step = $step; } } diff --git a/src/Builder/Expression/ReduceOperator.php b/src/Builder/Expression/ReduceOperator.php index 2b894b2e2..89e3b9f85 100644 --- a/src/Builder/Expression/ReduceOperator.php +++ b/src/Builder/Expression/ReduceOperator.php @@ -19,6 +19,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Applies an expression to each element in an array and combines them into a single value. @@ -69,6 +71,10 @@ public function __construct( throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; $this->initialValue = $initialValue; $this->in = $in; diff --git a/src/Builder/Expression/ReverseArrayOperator.php b/src/Builder/Expression/ReverseArrayOperator.php index 16c7c0c03..6c8a14424 100644 --- a/src/Builder/Expression/ReverseArrayOperator.php +++ b/src/Builder/Expression/ReverseArrayOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns an array with the elements in reverse order. @@ -41,6 +43,10 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $ throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); } + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/RoundOperator.php b/src/Builder/Expression/RoundOperator.php index 15756ad88..0deb81104 100644 --- a/src/Builder/Expression/RoundOperator.php +++ b/src/Builder/Expression/RoundOperator.php @@ -13,6 +13,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Rounds a number to a whole integer or to a specified decimal place. @@ -44,7 +48,15 @@ public function __construct( Decimal128|Int64|ResolvesToNumber|float|int|string $number, Optional|ResolvesToInt|int|string $place = Optional::Undefined, ) { + if (is_string($number) && ! str_starts_with($number, '$')) { + throw new InvalidArgumentException('Argument $number can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->number = $number; + if (is_string($place) && ! str_starts_with($place, '$')) { + throw new InvalidArgumentException('Argument $place can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->place = $place; } } diff --git a/src/Builder/Expression/SecondOperator.php b/src/Builder/Expression/SecondOperator.php index 9995b3951..dc65f410e 100644 --- a/src/Builder/Expression/SecondOperator.php +++ b/src/Builder/Expression/SecondOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the seconds for a date as a number between 0 and 60 (leap seconds). @@ -41,6 +45,10 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/SetDifferenceOperator.php b/src/Builder/Expression/SetDifferenceOperator.php index 678828850..783e3baa5 100644 --- a/src/Builder/Expression/SetDifferenceOperator.php +++ b/src/Builder/Expression/SetDifferenceOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns a set with elements that appear in the first set but not in the second set; i.e. performs a relative complement of the second set relative to the first. Accepts exactly two argument expressions. @@ -47,11 +49,19 @@ public function __construct( throw new InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); } + if (is_string($expression1) && ! str_starts_with($expression1, '$')) { + throw new InvalidArgumentException('Argument $expression1 can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression1 = $expression1; if (is_array($expression2) && ! array_is_list($expression2)) { throw new InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); } + if (is_string($expression2) && ! str_starts_with($expression2, '$')) { + throw new InvalidArgumentException('Argument $expression2 can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Expression/SetFieldOperator.php b/src/Builder/Expression/SetFieldOperator.php index e01bae4fa..96e86ee60 100644 --- a/src/Builder/Expression/SetFieldOperator.php +++ b/src/Builder/Expression/SetFieldOperator.php @@ -14,8 +14,12 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; use stdClass; +use function is_string; +use function str_starts_with; + /** * Adds, updates, or removes a specified field in a document. You can use $setField to add, update, or remove fields with names that contain periods (.) or start with dollar signs ($). * New in MongoDB 5.0. @@ -53,6 +57,10 @@ public function __construct( Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value, ) { $this->field = $field; + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; $this->value = $value; } diff --git a/src/Builder/Expression/SetIsSubsetOperator.php b/src/Builder/Expression/SetIsSubsetOperator.php index 2a4e25055..b4215d58d 100644 --- a/src/Builder/Expression/SetIsSubsetOperator.php +++ b/src/Builder/Expression/SetIsSubsetOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns true if all elements of the first set appear in the second set, including when the first set equals the second set; i.e. not a strict subset. Accepts exactly two argument expressions. @@ -47,11 +49,19 @@ public function __construct( throw new InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); } + if (is_string($expression1) && ! str_starts_with($expression1, '$')) { + throw new InvalidArgumentException('Argument $expression1 can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression1 = $expression1; if (is_array($expression2) && ! array_is_list($expression2)) { throw new InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); } + if (is_string($expression2) && ! str_starts_with($expression2, '$')) { + throw new InvalidArgumentException('Argument $expression2 can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Expression/SinOperator.php b/src/Builder/Expression/SinOperator.php index a0ed5cca4..cc8f82357 100644 --- a/src/Builder/Expression/SinOperator.php +++ b/src/Builder/Expression/SinOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the sine of a value that is measured in radians. @@ -37,6 +41,10 @@ final class SinOperator implements ResolvesToDouble, ResolvesToDecimal, Operator */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/SinhOperator.php b/src/Builder/Expression/SinhOperator.php index 795c282d6..763d2f94f 100644 --- a/src/Builder/Expression/SinhOperator.php +++ b/src/Builder/Expression/SinhOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the hyperbolic sine of a value that is measured in radians. @@ -37,6 +41,10 @@ final class SinhOperator implements ResolvesToDouble, ResolvesToDecimal, Operato */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/SizeOperator.php b/src/Builder/Expression/SizeOperator.php index 707af0b42..7157e4d50 100644 --- a/src/Builder/Expression/SizeOperator.php +++ b/src/Builder/Expression/SizeOperator.php @@ -16,6 +16,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns the number of elements in the array. Accepts a single expression as argument. @@ -41,6 +43,10 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $ throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); } + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/SliceOperator.php b/src/Builder/Expression/SliceOperator.php index 55d6fe697..4dbccfbb3 100644 --- a/src/Builder/Expression/SliceOperator.php +++ b/src/Builder/Expression/SliceOperator.php @@ -17,6 +17,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns a subset of an array. @@ -65,8 +67,20 @@ public function __construct( throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); } + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; + if (is_string($n) && ! str_starts_with($n, '$')) { + throw new InvalidArgumentException('Argument $n can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->n = $n; + if (is_string($position) && ! str_starts_with($position, '$')) { + throw new InvalidArgumentException('Argument $position can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->position = $position; } } diff --git a/src/Builder/Expression/SortArrayOperator.php b/src/Builder/Expression/SortArrayOperator.php index 04ee9109c..bfb93198e 100644 --- a/src/Builder/Expression/SortArrayOperator.php +++ b/src/Builder/Expression/SortArrayOperator.php @@ -20,6 +20,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Sorts the elements of an array. @@ -40,23 +42,27 @@ final class SortArrayOperator implements ResolvesToArray, OperatorInterface */ public readonly PackedArray|ResolvesToArray|BSONArray|array|string $input; - /** @var Document|Serializable|Sort|array|int|stdClass|string $sortBy The document specifies a sort ordering. */ - public readonly Document|Serializable|Sort|stdClass|array|int|string $sortBy; + /** @var Document|Serializable|Sort|array|int|stdClass $sortBy The document specifies a sort ordering. */ + public readonly Document|Serializable|Sort|stdClass|array|int $sortBy; /** * @param BSONArray|PackedArray|ResolvesToArray|array|string $input The array to be sorted. * The result is null if the expression: is missing, evaluates to null, or evaluates to undefined * If the expression evaluates to any other non-array value, the document returns an error. - * @param Document|Serializable|Sort|array|int|stdClass|string $sortBy The document specifies a sort ordering. + * @param Document|Serializable|Sort|array|int|stdClass $sortBy The document specifies a sort ordering. */ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $input, - Document|Serializable|Sort|stdClass|array|int|string $sortBy, + Document|Serializable|Sort|stdClass|array|int $sortBy, ) { if (is_array($input) && ! array_is_list($input)) { throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; $this->sortBy = $sortBy; } diff --git a/src/Builder/Expression/SqrtOperator.php b/src/Builder/Expression/SqrtOperator.php index ca1ebeb86..9453fb77b 100644 --- a/src/Builder/Expression/SqrtOperator.php +++ b/src/Builder/Expression/SqrtOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Calculates the square root. @@ -33,6 +37,10 @@ final class SqrtOperator implements ResolvesToDouble, OperatorInterface */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $number) { + if (is_string($number) && ! str_starts_with($number, '$')) { + throw new InvalidArgumentException('Argument $number can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->number = $number; } } diff --git a/src/Builder/Expression/SubstrBytesOperator.php b/src/Builder/Expression/SubstrBytesOperator.php index d30d12fa5..ff11d234b 100644 --- a/src/Builder/Expression/SubstrBytesOperator.php +++ b/src/Builder/Expression/SubstrBytesOperator.php @@ -10,6 +10,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the substring of a string. Starts with the character at the specified UTF-8 byte index (zero-based) in the string and continues for the specified number of bytes. @@ -43,7 +47,15 @@ public function __construct( ResolvesToInt|int|string $length, ) { $this->string = $string; + if (is_string($start) && ! str_starts_with($start, '$')) { + throw new InvalidArgumentException('Argument $start can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->start = $start; + if (is_string($length) && ! str_starts_with($length, '$')) { + throw new InvalidArgumentException('Argument $length can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->length = $length; } } diff --git a/src/Builder/Expression/SubstrCPOperator.php b/src/Builder/Expression/SubstrCPOperator.php index b878bf0fb..e2c7e89e0 100644 --- a/src/Builder/Expression/SubstrCPOperator.php +++ b/src/Builder/Expression/SubstrCPOperator.php @@ -10,6 +10,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the substring of a string. Starts with the character at the specified UTF-8 code point (CP) index (zero-based) in the string and continues for the number of code points specified. @@ -43,7 +47,15 @@ public function __construct( ResolvesToInt|int|string $length, ) { $this->string = $string; + if (is_string($start) && ! str_starts_with($start, '$')) { + throw new InvalidArgumentException('Argument $start can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->start = $start; + if (is_string($length) && ! str_starts_with($length, '$')) { + throw new InvalidArgumentException('Argument $length can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->length = $length; } } diff --git a/src/Builder/Expression/SubstrOperator.php b/src/Builder/Expression/SubstrOperator.php index e491c5f02..3547f5331 100644 --- a/src/Builder/Expression/SubstrOperator.php +++ b/src/Builder/Expression/SubstrOperator.php @@ -10,6 +10,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Deprecated. Use $substrBytes or $substrCP. @@ -43,7 +47,15 @@ public function __construct( ResolvesToInt|int|string $length, ) { $this->string = $string; + if (is_string($start) && ! str_starts_with($start, '$')) { + throw new InvalidArgumentException('Argument $start can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->start = $start; + if (is_string($length) && ! str_starts_with($length, '$')) { + throw new InvalidArgumentException('Argument $length can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->length = $length; } } diff --git a/src/Builder/Expression/SubtractOperator.php b/src/Builder/Expression/SubtractOperator.php index 462f170be..86e396ef0 100644 --- a/src/Builder/Expression/SubtractOperator.php +++ b/src/Builder/Expression/SubtractOperator.php @@ -13,6 +13,10 @@ use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the result of subtracting the second value from the first. If the two values are numbers, return the difference. If the two values are dates, return the difference in milliseconds. If the two values are a date and a number in milliseconds, return the resulting date. Accepts two argument expressions. If the two values are a date and a number, specify the date argument first as it is not meaningful to subtract a date from a number. @@ -40,7 +44,15 @@ public function __construct( Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression1, Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int|string $expression2, ) { + if (is_string($expression1) && ! str_starts_with($expression1, '$')) { + throw new InvalidArgumentException('Argument $expression1 can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression1 = $expression1; + if (is_string($expression2) && ! str_starts_with($expression2, '$')) { + throw new InvalidArgumentException('Argument $expression2 can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Expression/SwitchOperator.php b/src/Builder/Expression/SwitchOperator.php index 46b6242ce..4179a5d52 100644 --- a/src/Builder/Expression/SwitchOperator.php +++ b/src/Builder/Expression/SwitchOperator.php @@ -34,12 +34,12 @@ final class SwitchOperator implements ResolvesToAny, OperatorInterface public const PROPERTIES = ['branches' => 'branches', 'default' => 'default']; /** - * @var BSONArray|PackedArray|array|string $branches An array of control branch documents. Each branch is a document with the following fields: + * @var BSONArray|PackedArray|array $branches An array of control branch documents. Each branch is a document with the following fields: * - case Can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value. More information about how MongoDB evaluates expressions as either true or false can be found here. * - then Can be any valid expression. * The branches array must contain at least one branch document. */ - public readonly PackedArray|BSONArray|array|string $branches; + public readonly PackedArray|BSONArray|array $branches; /** * @var Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default The path to take if no branch case expression evaluates to true. @@ -48,7 +48,7 @@ final class SwitchOperator implements ResolvesToAny, OperatorInterface public readonly Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default; /** - * @param BSONArray|PackedArray|array|string $branches An array of control branch documents. Each branch is a document with the following fields: + * @param BSONArray|PackedArray|array $branches An array of control branch documents. Each branch is a document with the following fields: * - case Can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value. More information about how MongoDB evaluates expressions as either true or false can be found here. * - then Can be any valid expression. * The branches array must contain at least one branch document. @@ -56,7 +56,7 @@ final class SwitchOperator implements ResolvesToAny, OperatorInterface * Although optional, if default is unspecified and no branch case evaluates to true, $switch returns an error. */ public function __construct( - PackedArray|BSONArray|array|string $branches, + PackedArray|BSONArray|array $branches, Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, ) { if (is_array($branches) && ! array_is_list($branches)) { diff --git a/src/Builder/Expression/TanOperator.php b/src/Builder/Expression/TanOperator.php index 2e4ddd7b0..c783b0392 100644 --- a/src/Builder/Expression/TanOperator.php +++ b/src/Builder/Expression/TanOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the tangent of a value that is measured in radians. @@ -37,6 +41,10 @@ final class TanOperator implements ResolvesToDouble, ResolvesToDecimal, Operator */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/TanhOperator.php b/src/Builder/Expression/TanhOperator.php index 3e565a26c..e6f8bb619 100644 --- a/src/Builder/Expression/TanhOperator.php +++ b/src/Builder/Expression/TanhOperator.php @@ -12,6 +12,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the hyperbolic tangent of a value that is measured in radians. @@ -37,6 +41,10 @@ final class TanhOperator implements ResolvesToDouble, ResolvesToDecimal, Operato */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/TruncOperator.php b/src/Builder/Expression/TruncOperator.php index 27a231b8d..b8e98c562 100644 --- a/src/Builder/Expression/TruncOperator.php +++ b/src/Builder/Expression/TruncOperator.php @@ -13,6 +13,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Truncates a number to a whole integer or to a specified decimal place. @@ -44,7 +48,15 @@ public function __construct( Decimal128|Int64|ResolvesToNumber|float|int|string $number, Optional|ResolvesToInt|int|string $place = Optional::Undefined, ) { + if (is_string($number) && ! str_starts_with($number, '$')) { + throw new InvalidArgumentException('Argument $number can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->number = $number; + if (is_string($place) && ! str_starts_with($place, '$')) { + throw new InvalidArgumentException('Argument $place can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->place = $place; } } diff --git a/src/Builder/Expression/TsIncrementOperator.php b/src/Builder/Expression/TsIncrementOperator.php index 32d8ff8d3..3e1e404c1 100644 --- a/src/Builder/Expression/TsIncrementOperator.php +++ b/src/Builder/Expression/TsIncrementOperator.php @@ -11,6 +11,10 @@ use MongoDB\BSON\Timestamp; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the incrementing ordinal from a timestamp as a long. @@ -33,6 +37,10 @@ final class TsIncrementOperator implements ResolvesToLong, OperatorInterface */ public function __construct(Timestamp|ResolvesToTimestamp|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/TsSecondOperator.php b/src/Builder/Expression/TsSecondOperator.php index eff32f6a0..bea14d9e1 100644 --- a/src/Builder/Expression/TsSecondOperator.php +++ b/src/Builder/Expression/TsSecondOperator.php @@ -11,6 +11,10 @@ use MongoDB\BSON\Timestamp; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the seconds from a timestamp as a long. @@ -33,6 +37,10 @@ final class TsSecondOperator implements ResolvesToLong, OperatorInterface */ public function __construct(Timestamp|ResolvesToTimestamp|int|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/UnsetFieldOperator.php b/src/Builder/Expression/UnsetFieldOperator.php index a420fbf4e..1d0fcf9d2 100644 --- a/src/Builder/Expression/UnsetFieldOperator.php +++ b/src/Builder/Expression/UnsetFieldOperator.php @@ -12,8 +12,12 @@ use MongoDB\BSON\Serializable; use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; +use MongoDB\Exception\InvalidArgumentException; use stdClass; +use function is_string; +use function str_starts_with; + /** * You can use $unsetField to remove fields with names that contain periods (.) or that start with dollar signs ($). * $unsetField is an alias for $setField using $$REMOVE to remove fields. @@ -42,6 +46,10 @@ public function __construct( Document|Serializable|ResolvesToObject|stdClass|array|string $input, ) { $this->field = $field; + if (is_string($input) && ! str_starts_with($input, '$')) { + throw new InvalidArgumentException('Argument $input can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->input = $input; } } diff --git a/src/Builder/Expression/WeekOperator.php b/src/Builder/Expression/WeekOperator.php index eace09a39..3cca670fa 100644 --- a/src/Builder/Expression/WeekOperator.php +++ b/src/Builder/Expression/WeekOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the week number for a date as a number between 0 (the partial week that precedes the first Sunday of the year) and 53 (leap year). @@ -41,6 +45,10 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/YearOperator.php b/src/Builder/Expression/YearOperator.php index b35a6c0c0..2c1c649bf 100644 --- a/src/Builder/Expression/YearOperator.php +++ b/src/Builder/Expression/YearOperator.php @@ -14,6 +14,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\Optional; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Returns the year for a date as a number (e.g. 2014). @@ -41,6 +45,10 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int|string $date, Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { + if (is_string($date) && ! str_starts_with($date, '$')) { + throw new InvalidArgumentException('Argument $date can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->date = $date; $this->timezone = $timezone; } diff --git a/src/Builder/Expression/ZipOperator.php b/src/Builder/Expression/ZipOperator.php index 76521dd97..af647b541 100644 --- a/src/Builder/Expression/ZipOperator.php +++ b/src/Builder/Expression/ZipOperator.php @@ -17,6 +17,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Merge two arrays together. @@ -38,37 +40,41 @@ final class ZipOperator implements ResolvesToArray, OperatorInterface public readonly PackedArray|ResolvesToArray|BSONArray|array|string $inputs; /** - * @var Optional|bool|string $useLongestLength A boolean which specifies whether the length of the longest array determines the number of arrays in the output array. + * @var Optional|bool $useLongestLength A boolean which specifies whether the length of the longest array determines the number of arrays in the output array. * The default value is false: the shortest array length determines the number of arrays in the output array. */ - public readonly Optional|bool|string $useLongestLength; + public readonly Optional|bool $useLongestLength; /** - * @var Optional|BSONArray|PackedArray|array|string $defaults An array of default element values to use if the input arrays have different lengths. You must specify useLongestLength: true along with this field, or else $zip will return an error. + * @var Optional|BSONArray|PackedArray|array $defaults An array of default element values to use if the input arrays have different lengths. You must specify useLongestLength: true along with this field, or else $zip will return an error. * If useLongestLength: true but defaults is empty or not specified, $zip uses null as the default value. * If specifying a non-empty defaults, you must specify a default for each input array or else $zip will return an error. */ - public readonly Optional|PackedArray|BSONArray|array|string $defaults; + public readonly Optional|PackedArray|BSONArray|array $defaults; /** * @param BSONArray|PackedArray|ResolvesToArray|array|string $inputs An array of expressions that resolve to arrays. The elements of these input arrays combine to form the arrays of the output array. * If any of the inputs arrays resolves to a value of null or refers to a missing field, $zip returns null. * If any of the inputs arrays does not resolve to an array or null nor refers to a missing field, $zip returns an error. - * @param Optional|bool|string $useLongestLength A boolean which specifies whether the length of the longest array determines the number of arrays in the output array. + * @param Optional|bool $useLongestLength A boolean which specifies whether the length of the longest array determines the number of arrays in the output array. * The default value is false: the shortest array length determines the number of arrays in the output array. - * @param Optional|BSONArray|PackedArray|array|string $defaults An array of default element values to use if the input arrays have different lengths. You must specify useLongestLength: true along with this field, or else $zip will return an error. + * @param Optional|BSONArray|PackedArray|array $defaults An array of default element values to use if the input arrays have different lengths. You must specify useLongestLength: true along with this field, or else $zip will return an error. * If useLongestLength: true but defaults is empty or not specified, $zip uses null as the default value. * If specifying a non-empty defaults, you must specify a default for each input array or else $zip will return an error. */ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $inputs, - Optional|bool|string $useLongestLength = Optional::Undefined, - Optional|PackedArray|BSONArray|array|string $defaults = Optional::Undefined, + Optional|bool $useLongestLength = Optional::Undefined, + Optional|PackedArray|BSONArray|array $defaults = Optional::Undefined, ) { if (is_array($inputs) && ! array_is_list($inputs)) { throw new InvalidArgumentException('Expected $inputs argument to be a list, got an associative array.'); } + if (is_string($inputs) && ! str_starts_with($inputs, '$')) { + throw new InvalidArgumentException('Argument $inputs can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->inputs = $inputs; $this->useLongestLength = $useLongestLength; if (is_array($defaults) && ! array_is_list($defaults)) { diff --git a/src/Builder/Query/BoxOperator.php b/src/Builder/Query/BoxOperator.php index cae925244..cce9cf8d8 100644 --- a/src/Builder/Query/BoxOperator.php +++ b/src/Builder/Query/BoxOperator.php @@ -30,13 +30,13 @@ final class BoxOperator implements GeometryInterface, OperatorInterface public const NAME = '$box'; public const PROPERTIES = ['value' => 'value']; - /** @var BSONArray|PackedArray|array|string $value */ - public readonly PackedArray|BSONArray|array|string $value; + /** @var BSONArray|PackedArray|array $value */ + public readonly PackedArray|BSONArray|array $value; /** - * @param BSONArray|PackedArray|array|string $value + * @param BSONArray|PackedArray|array $value */ - public function __construct(PackedArray|BSONArray|array|string $value) + public function __construct(PackedArray|BSONArray|array $value) { if (is_array($value) && ! array_is_list($value)) { throw new InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); diff --git a/src/Builder/Query/CenterOperator.php b/src/Builder/Query/CenterOperator.php index b8a17e0a5..f3a0b890a 100644 --- a/src/Builder/Query/CenterOperator.php +++ b/src/Builder/Query/CenterOperator.php @@ -30,13 +30,13 @@ final class CenterOperator implements GeometryInterface, OperatorInterface public const NAME = '$center'; public const PROPERTIES = ['value' => 'value']; - /** @var BSONArray|PackedArray|array|string $value */ - public readonly PackedArray|BSONArray|array|string $value; + /** @var BSONArray|PackedArray|array $value */ + public readonly PackedArray|BSONArray|array $value; /** - * @param BSONArray|PackedArray|array|string $value + * @param BSONArray|PackedArray|array $value */ - public function __construct(PackedArray|BSONArray|array|string $value) + public function __construct(PackedArray|BSONArray|array $value) { if (is_array($value) && ! array_is_list($value)) { throw new InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); diff --git a/src/Builder/Query/CenterSphereOperator.php b/src/Builder/Query/CenterSphereOperator.php index 7439ba7f2..350f535f0 100644 --- a/src/Builder/Query/CenterSphereOperator.php +++ b/src/Builder/Query/CenterSphereOperator.php @@ -30,13 +30,13 @@ final class CenterSphereOperator implements GeometryInterface, OperatorInterface public const NAME = '$centerSphere'; public const PROPERTIES = ['value' => 'value']; - /** @var BSONArray|PackedArray|array|string $value */ - public readonly PackedArray|BSONArray|array|string $value; + /** @var BSONArray|PackedArray|array $value */ + public readonly PackedArray|BSONArray|array $value; /** - * @param BSONArray|PackedArray|array|string $value + * @param BSONArray|PackedArray|array $value */ - public function __construct(PackedArray|BSONArray|array|string $value) + public function __construct(PackedArray|BSONArray|array $value) { if (is_array($value) && ! array_is_list($value)) { throw new InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); diff --git a/src/Builder/Query/ExistsOperator.php b/src/Builder/Query/ExistsOperator.php index 911270026..1d0b0a292 100644 --- a/src/Builder/Query/ExistsOperator.php +++ b/src/Builder/Query/ExistsOperator.php @@ -24,13 +24,13 @@ final class ExistsOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$exists'; public const PROPERTIES = ['exists' => 'exists']; - /** @var bool|string $exists */ - public readonly bool|string $exists; + /** @var bool $exists */ + public readonly bool $exists; /** - * @param bool|string $exists + * @param bool $exists */ - public function __construct(bool|string $exists = true) + public function __construct(bool $exists = true) { $this->exists = $exists; } diff --git a/src/Builder/Query/FactoryTrait.php b/src/Builder/Query/FactoryTrait.php index 9b8164467..e9900f935 100644 --- a/src/Builder/Query/FactoryTrait.php +++ b/src/Builder/Query/FactoryTrait.php @@ -104,9 +104,9 @@ public static function bitsAnySet(Binary|PackedArray|BSONArray|array|int|string * Specifies a rectangular box using legacy coordinate pairs for $geoWithin queries. The 2d index supports $box. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/box/ - * @param BSONArray|PackedArray|array|string $value + * @param BSONArray|PackedArray|array $value */ - public static function box(PackedArray|BSONArray|array|string $value): BoxOperator + public static function box(PackedArray|BSONArray|array $value): BoxOperator { return new BoxOperator($value); } @@ -115,9 +115,9 @@ public static function box(PackedArray|BSONArray|array|string $value): BoxOperat * Specifies a circle using legacy coordinate pairs to $geoWithin queries when using planar geometry. The 2d index supports $center. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/center/ - * @param BSONArray|PackedArray|array|string $value + * @param BSONArray|PackedArray|array $value */ - public static function center(PackedArray|BSONArray|array|string $value): CenterOperator + public static function center(PackedArray|BSONArray|array $value): CenterOperator { return new CenterOperator($value); } @@ -126,9 +126,9 @@ public static function center(PackedArray|BSONArray|array|string $value): Center * Specifies a circle using either legacy coordinate pairs or GeoJSON format for $geoWithin queries when using spherical geometry. The 2dsphere and 2d indexes support $centerSphere. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/ - * @param BSONArray|PackedArray|array|string $value + * @param BSONArray|PackedArray|array $value */ - public static function centerSphere(PackedArray|BSONArray|array|string $value): CenterSphereOperator + public static function centerSphere(PackedArray|BSONArray|array $value): CenterSphereOperator { return new CenterSphereOperator($value); } @@ -171,9 +171,9 @@ public static function eq(Type|stdClass|array|bool|float|int|null|string $value) * Matches documents that have the specified field. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/exists/ - * @param bool|string $exists + * @param bool $exists */ - public static function exists(bool|string $exists = true): ExistsOperator + public static function exists(bool $exists = true): ExistsOperator { return new ExistsOperator($exists); } @@ -207,13 +207,13 @@ public static function geoIntersects( * * @see https://www.mongodb.com/docs/manual/reference/operator/query/geometry/ * @param string $type - * @param BSONArray|PackedArray|array|string $coordinates - * @param Optional|Document|Serializable|array|stdClass|string $crs + * @param BSONArray|PackedArray|array $coordinates + * @param Optional|Document|Serializable|array|stdClass $crs */ public static function geometry( string $type, - PackedArray|BSONArray|array|string $coordinates, - Optional|Document|Serializable|stdClass|array|string $crs = Optional::Undefined, + PackedArray|BSONArray|array $coordinates, + Optional|Document|Serializable|stdClass|array $crs = Optional::Undefined, ): GeometryOperator { return new GeometryOperator($type, $coordinates, $crs); } @@ -256,9 +256,9 @@ public static function gte(Type|stdClass|array|bool|float|int|null|string $value * Matches any of the values specified in an array. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/in/ - * @param BSONArray|PackedArray|array|string $value + * @param BSONArray|PackedArray|array $value */ - public static function in(PackedArray|BSONArray|array|string $value): InOperator + public static function in(PackedArray|BSONArray|array $value): InOperator { return new InOperator($value); } @@ -267,9 +267,9 @@ public static function in(PackedArray|BSONArray|array|string $value): InOperator * Validate documents against the given JSON Schema. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/jsonSchema/ - * @param Document|Serializable|array|stdClass|string $schema + * @param Document|Serializable|array|stdClass $schema */ - public static function jsonSchema(Document|Serializable|stdClass|array|string $schema): JsonSchemaOperator + public static function jsonSchema(Document|Serializable|stdClass|array $schema): JsonSchemaOperator { return new JsonSchemaOperator($schema); } @@ -300,9 +300,9 @@ public static function lte(Type|stdClass|array|bool|float|int|null|string $value * Specifies a maximum distance to limit the results of $near and $nearSphere queries. The 2dsphere and 2d indexes support $maxDistance. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/maxDistance/ - * @param Decimal128|Int64|float|int|string $value + * @param Decimal128|Int64|float|int $value */ - public static function maxDistance(Decimal128|Int64|float|int|string $value): MaxDistanceOperator + public static function maxDistance(Decimal128|Int64|float|int $value): MaxDistanceOperator { return new MaxDistanceOperator($value); } @@ -311,9 +311,9 @@ public static function maxDistance(Decimal128|Int64|float|int|string $value): Ma * Specifies a minimum distance to limit the results of $near and $nearSphere queries. For use with 2dsphere index only. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/minDistance/ - * @param Int64|float|int|string $value + * @param Int64|float|int $value */ - public static function minDistance(Int64|float|int|string $value): MinDistanceOperator + public static function minDistance(Int64|float|int $value): MinDistanceOperator { return new MinDistanceOperator($value); } @@ -322,12 +322,12 @@ public static function minDistance(Int64|float|int|string $value): MinDistanceOp * Performs a modulo operation on the value of a field and selects documents with a specified result. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/mod/ - * @param Decimal128|Int64|float|int|string $divisor - * @param Decimal128|Int64|float|int|string $remainder + * @param Decimal128|Int64|float|int $divisor + * @param Decimal128|Int64|float|int $remainder */ public static function mod( - Decimal128|Int64|float|int|string $divisor, - Decimal128|Int64|float|int|string $remainder, + Decimal128|Int64|float|int $divisor, + Decimal128|Int64|float|int $remainder, ): ModOperator { return new ModOperator($divisor, $remainder); } @@ -348,13 +348,13 @@ public static function ne(Type|stdClass|array|bool|float|int|null|string $value) * * @see https://www.mongodb.com/docs/manual/reference/operator/query/near/ * @param Document|GeometryInterface|Serializable|array|stdClass $geometry - * @param Optional|Decimal128|Int64|float|int|string $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. - * @param Optional|Decimal128|Int64|float|int|string $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. + * @param Optional|Decimal128|Int64|float|int $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. + * @param Optional|Decimal128|Int64|float|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ public static function near( Document|Serializable|GeometryInterface|stdClass|array $geometry, - Optional|Decimal128|Int64|float|int|string $maxDistance = Optional::Undefined, - Optional|Decimal128|Int64|float|int|string $minDistance = Optional::Undefined, + Optional|Decimal128|Int64|float|int $maxDistance = Optional::Undefined, + Optional|Decimal128|Int64|float|int $minDistance = Optional::Undefined, ): NearOperator { return new NearOperator($geometry, $maxDistance, $minDistance); } @@ -364,13 +364,13 @@ public static function near( * * @see https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/ * @param Document|GeometryInterface|Serializable|array|stdClass $geometry - * @param Optional|Decimal128|Int64|float|int|string $maxDistance Distance in meters. - * @param Optional|Decimal128|Int64|float|int|string $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. + * @param Optional|Decimal128|Int64|float|int $maxDistance Distance in meters. + * @param Optional|Decimal128|Int64|float|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ public static function nearSphere( Document|Serializable|GeometryInterface|stdClass|array $geometry, - Optional|Decimal128|Int64|float|int|string $maxDistance = Optional::Undefined, - Optional|Decimal128|Int64|float|int|string $minDistance = Optional::Undefined, + Optional|Decimal128|Int64|float|int $maxDistance = Optional::Undefined, + Optional|Decimal128|Int64|float|int $minDistance = Optional::Undefined, ): NearSphereOperator { return new NearSphereOperator($geometry, $maxDistance, $minDistance); } @@ -379,9 +379,9 @@ public static function nearSphere( * Matches none of the values specified in an array. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/nin/ - * @param BSONArray|PackedArray|array|string $value + * @param BSONArray|PackedArray|array $value */ - public static function nin(PackedArray|BSONArray|array|string $value): NinOperator + public static function nin(PackedArray|BSONArray|array $value): NinOperator { return new NinOperator($value); } @@ -426,9 +426,9 @@ public static function or(QueryInterface|array ...$queries): OrOperator * Specifies a polygon to using legacy coordinate pairs for $geoWithin queries. The 2d index supports $center. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/polygon/ - * @param BSONArray|PackedArray|array|string $points + * @param BSONArray|PackedArray|array $points */ - public static function polygon(PackedArray|BSONArray|array|string $points): PolygonOperator + public static function polygon(PackedArray|BSONArray|array $points): PolygonOperator { return new PolygonOperator($points); } @@ -447,9 +447,9 @@ public static function rand(): RandOperator * Selects documents where values match a specified regular expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/regex/ - * @param Regex|string $regex + * @param Regex $regex */ - public static function regex(Regex|string $regex): RegexOperator + public static function regex(Regex $regex): RegexOperator { return new RegexOperator($regex); } @@ -470,9 +470,9 @@ public static function sampleRate(Int64|ResolvesToDouble|float|int|string $rate) * Selects documents if the array field is a specified size. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/size/ - * @param int|string $value + * @param int $value */ - public static function size(int|string $value): SizeOperator + public static function size(int $value): SizeOperator { return new SizeOperator($value); } @@ -484,15 +484,15 @@ public static function size(int|string $value): SizeOperator * @param string $search A string of terms that MongoDB parses and uses to query the text index. MongoDB performs a logical OR search of the terms unless specified as a phrase. * @param Optional|string $language The language that determines the list of stop words for the search and the rules for the stemmer and tokenizer. If not specified, the search uses the default language of the index. * If you specify a default_language value of none, then the text index parses through each word in the field, including stop words, and ignores suffix stemming. - * @param Optional|bool|string $caseSensitive A boolean flag to enable or disable case sensitive search. Defaults to false; i.e. the search defers to the case insensitivity of the text index. - * @param Optional|bool|string $diacriticSensitive A boolean flag to enable or disable diacritic sensitive search against version 3 text indexes. Defaults to false; i.e. the search defers to the diacritic insensitivity of the text index. + * @param Optional|bool $caseSensitive A boolean flag to enable or disable case sensitive search. Defaults to false; i.e. the search defers to the case insensitivity of the text index. + * @param Optional|bool $diacriticSensitive A boolean flag to enable or disable diacritic sensitive search against version 3 text indexes. Defaults to false; i.e. the search defers to the diacritic insensitivity of the text index. * Text searches against earlier versions of the text index are inherently diacritic sensitive and cannot be diacritic insensitive. As such, the $diacriticSensitive option has no effect with earlier versions of the text index. */ public static function text( string $search, Optional|string $language = Optional::Undefined, - Optional|bool|string $caseSensitive = Optional::Undefined, - Optional|bool|string $diacriticSensitive = Optional::Undefined, + Optional|bool $caseSensitive = Optional::Undefined, + Optional|bool $diacriticSensitive = Optional::Undefined, ): TextOperator { return new TextOperator($search, $language, $caseSensitive, $diacriticSensitive); } diff --git a/src/Builder/Query/GeometryOperator.php b/src/Builder/Query/GeometryOperator.php index cfcf8302c..fe52be973 100644 --- a/src/Builder/Query/GeometryOperator.php +++ b/src/Builder/Query/GeometryOperator.php @@ -37,21 +37,21 @@ final class GeometryOperator implements GeometryInterface, OperatorInterface /** @var string $type */ public readonly string $type; - /** @var BSONArray|PackedArray|array|string $coordinates */ - public readonly PackedArray|BSONArray|array|string $coordinates; + /** @var BSONArray|PackedArray|array $coordinates */ + public readonly PackedArray|BSONArray|array $coordinates; - /** @var Optional|Document|Serializable|array|stdClass|string $crs */ - public readonly Optional|Document|Serializable|stdClass|array|string $crs; + /** @var Optional|Document|Serializable|array|stdClass $crs */ + public readonly Optional|Document|Serializable|stdClass|array $crs; /** * @param string $type - * @param BSONArray|PackedArray|array|string $coordinates - * @param Optional|Document|Serializable|array|stdClass|string $crs + * @param BSONArray|PackedArray|array $coordinates + * @param Optional|Document|Serializable|array|stdClass $crs */ public function __construct( string $type, - PackedArray|BSONArray|array|string $coordinates, - Optional|Document|Serializable|stdClass|array|string $crs = Optional::Undefined, + PackedArray|BSONArray|array $coordinates, + Optional|Document|Serializable|stdClass|array $crs = Optional::Undefined, ) { $this->type = $type; if (is_array($coordinates) && ! array_is_list($coordinates)) { diff --git a/src/Builder/Query/InOperator.php b/src/Builder/Query/InOperator.php index 177c52f81..e6f1456a4 100644 --- a/src/Builder/Query/InOperator.php +++ b/src/Builder/Query/InOperator.php @@ -30,13 +30,13 @@ final class InOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$in'; public const PROPERTIES = ['value' => 'value']; - /** @var BSONArray|PackedArray|array|string $value */ - public readonly PackedArray|BSONArray|array|string $value; + /** @var BSONArray|PackedArray|array $value */ + public readonly PackedArray|BSONArray|array $value; /** - * @param BSONArray|PackedArray|array|string $value + * @param BSONArray|PackedArray|array $value */ - public function __construct(PackedArray|BSONArray|array|string $value) + public function __construct(PackedArray|BSONArray|array $value) { if (is_array($value) && ! array_is_list($value)) { throw new InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); diff --git a/src/Builder/Query/JsonSchemaOperator.php b/src/Builder/Query/JsonSchemaOperator.php index bfd6d5d41..3dc8b918e 100644 --- a/src/Builder/Query/JsonSchemaOperator.php +++ b/src/Builder/Query/JsonSchemaOperator.php @@ -27,13 +27,13 @@ final class JsonSchemaOperator implements QueryInterface, OperatorInterface public const NAME = '$jsonSchema'; public const PROPERTIES = ['schema' => 'schema']; - /** @var Document|Serializable|array|stdClass|string $schema */ - public readonly Document|Serializable|stdClass|array|string $schema; + /** @var Document|Serializable|array|stdClass $schema */ + public readonly Document|Serializable|stdClass|array $schema; /** - * @param Document|Serializable|array|stdClass|string $schema + * @param Document|Serializable|array|stdClass $schema */ - public function __construct(Document|Serializable|stdClass|array|string $schema) + public function __construct(Document|Serializable|stdClass|array $schema) { $this->schema = $schema; } diff --git a/src/Builder/Query/MaxDistanceOperator.php b/src/Builder/Query/MaxDistanceOperator.php index 4dd2b4516..2aea7d4c8 100644 --- a/src/Builder/Query/MaxDistanceOperator.php +++ b/src/Builder/Query/MaxDistanceOperator.php @@ -26,13 +26,13 @@ final class MaxDistanceOperator implements FieldQueryInterface, OperatorInterfac public const NAME = '$maxDistance'; public const PROPERTIES = ['value' => 'value']; - /** @var Decimal128|Int64|float|int|string $value */ - public readonly Decimal128|Int64|float|int|string $value; + /** @var Decimal128|Int64|float|int $value */ + public readonly Decimal128|Int64|float|int $value; /** - * @param Decimal128|Int64|float|int|string $value + * @param Decimal128|Int64|float|int $value */ - public function __construct(Decimal128|Int64|float|int|string $value) + public function __construct(Decimal128|Int64|float|int $value) { $this->value = $value; } diff --git a/src/Builder/Query/MinDistanceOperator.php b/src/Builder/Query/MinDistanceOperator.php index 6940699db..74aadb397 100644 --- a/src/Builder/Query/MinDistanceOperator.php +++ b/src/Builder/Query/MinDistanceOperator.php @@ -25,13 +25,13 @@ final class MinDistanceOperator implements FieldQueryInterface, OperatorInterfac public const NAME = '$minDistance'; public const PROPERTIES = ['value' => 'value']; - /** @var Int64|float|int|string $value */ - public readonly Int64|float|int|string $value; + /** @var Int64|float|int $value */ + public readonly Int64|float|int $value; /** - * @param Int64|float|int|string $value + * @param Int64|float|int $value */ - public function __construct(Int64|float|int|string $value) + public function __construct(Int64|float|int $value) { $this->value = $value; } diff --git a/src/Builder/Query/ModOperator.php b/src/Builder/Query/ModOperator.php index 0c272f109..bbabdfdc9 100644 --- a/src/Builder/Query/ModOperator.php +++ b/src/Builder/Query/ModOperator.php @@ -26,20 +26,18 @@ final class ModOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$mod'; public const PROPERTIES = ['divisor' => 'divisor', 'remainder' => 'remainder']; - /** @var Decimal128|Int64|float|int|string $divisor */ - public readonly Decimal128|Int64|float|int|string $divisor; + /** @var Decimal128|Int64|float|int $divisor */ + public readonly Decimal128|Int64|float|int $divisor; - /** @var Decimal128|Int64|float|int|string $remainder */ - public readonly Decimal128|Int64|float|int|string $remainder; + /** @var Decimal128|Int64|float|int $remainder */ + public readonly Decimal128|Int64|float|int $remainder; /** - * @param Decimal128|Int64|float|int|string $divisor - * @param Decimal128|Int64|float|int|string $remainder + * @param Decimal128|Int64|float|int $divisor + * @param Decimal128|Int64|float|int $remainder */ - public function __construct( - Decimal128|Int64|float|int|string $divisor, - Decimal128|Int64|float|int|string $remainder, - ) { + public function __construct(Decimal128|Int64|float|int $divisor, Decimal128|Int64|float|int $remainder) + { $this->divisor = $divisor; $this->remainder = $remainder; } diff --git a/src/Builder/Query/NearOperator.php b/src/Builder/Query/NearOperator.php index 2b486a9db..85be90ac4 100644 --- a/src/Builder/Query/NearOperator.php +++ b/src/Builder/Query/NearOperator.php @@ -34,21 +34,21 @@ final class NearOperator implements FieldQueryInterface, OperatorInterface /** @var Document|GeometryInterface|Serializable|array|stdClass $geometry */ public readonly Document|Serializable|GeometryInterface|stdClass|array $geometry; - /** @var Optional|Decimal128|Int64|float|int|string $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. */ - public readonly Optional|Decimal128|Int64|float|int|string $maxDistance; + /** @var Optional|Decimal128|Int64|float|int $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. */ + public readonly Optional|Decimal128|Int64|float|int $maxDistance; - /** @var Optional|Decimal128|Int64|float|int|string $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ - public readonly Optional|Decimal128|Int64|float|int|string $minDistance; + /** @var Optional|Decimal128|Int64|float|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ + public readonly Optional|Decimal128|Int64|float|int $minDistance; /** * @param Document|GeometryInterface|Serializable|array|stdClass $geometry - * @param Optional|Decimal128|Int64|float|int|string $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. - * @param Optional|Decimal128|Int64|float|int|string $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. + * @param Optional|Decimal128|Int64|float|int $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. + * @param Optional|Decimal128|Int64|float|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ public function __construct( Document|Serializable|GeometryInterface|stdClass|array $geometry, - Optional|Decimal128|Int64|float|int|string $maxDistance = Optional::Undefined, - Optional|Decimal128|Int64|float|int|string $minDistance = Optional::Undefined, + Optional|Decimal128|Int64|float|int $maxDistance = Optional::Undefined, + Optional|Decimal128|Int64|float|int $minDistance = Optional::Undefined, ) { $this->geometry = $geometry; $this->maxDistance = $maxDistance; diff --git a/src/Builder/Query/NearSphereOperator.php b/src/Builder/Query/NearSphereOperator.php index ba3012cca..5494048b0 100644 --- a/src/Builder/Query/NearSphereOperator.php +++ b/src/Builder/Query/NearSphereOperator.php @@ -34,21 +34,21 @@ final class NearSphereOperator implements FieldQueryInterface, OperatorInterface /** @var Document|GeometryInterface|Serializable|array|stdClass $geometry */ public readonly Document|Serializable|GeometryInterface|stdClass|array $geometry; - /** @var Optional|Decimal128|Int64|float|int|string $maxDistance Distance in meters. */ - public readonly Optional|Decimal128|Int64|float|int|string $maxDistance; + /** @var Optional|Decimal128|Int64|float|int $maxDistance Distance in meters. */ + public readonly Optional|Decimal128|Int64|float|int $maxDistance; - /** @var Optional|Decimal128|Int64|float|int|string $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ - public readonly Optional|Decimal128|Int64|float|int|string $minDistance; + /** @var Optional|Decimal128|Int64|float|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ + public readonly Optional|Decimal128|Int64|float|int $minDistance; /** * @param Document|GeometryInterface|Serializable|array|stdClass $geometry - * @param Optional|Decimal128|Int64|float|int|string $maxDistance Distance in meters. - * @param Optional|Decimal128|Int64|float|int|string $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. + * @param Optional|Decimal128|Int64|float|int $maxDistance Distance in meters. + * @param Optional|Decimal128|Int64|float|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ public function __construct( Document|Serializable|GeometryInterface|stdClass|array $geometry, - Optional|Decimal128|Int64|float|int|string $maxDistance = Optional::Undefined, - Optional|Decimal128|Int64|float|int|string $minDistance = Optional::Undefined, + Optional|Decimal128|Int64|float|int $maxDistance = Optional::Undefined, + Optional|Decimal128|Int64|float|int $minDistance = Optional::Undefined, ) { $this->geometry = $geometry; $this->maxDistance = $maxDistance; diff --git a/src/Builder/Query/NinOperator.php b/src/Builder/Query/NinOperator.php index bad42a7e5..5c82c3fd8 100644 --- a/src/Builder/Query/NinOperator.php +++ b/src/Builder/Query/NinOperator.php @@ -30,13 +30,13 @@ final class NinOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$nin'; public const PROPERTIES = ['value' => 'value']; - /** @var BSONArray|PackedArray|array|string $value */ - public readonly PackedArray|BSONArray|array|string $value; + /** @var BSONArray|PackedArray|array $value */ + public readonly PackedArray|BSONArray|array $value; /** - * @param BSONArray|PackedArray|array|string $value + * @param BSONArray|PackedArray|array $value */ - public function __construct(PackedArray|BSONArray|array|string $value) + public function __construct(PackedArray|BSONArray|array $value) { if (is_array($value) && ! array_is_list($value)) { throw new InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); diff --git a/src/Builder/Query/PolygonOperator.php b/src/Builder/Query/PolygonOperator.php index e05d8838f..bba3aac08 100644 --- a/src/Builder/Query/PolygonOperator.php +++ b/src/Builder/Query/PolygonOperator.php @@ -30,13 +30,13 @@ final class PolygonOperator implements GeometryInterface, OperatorInterface public const NAME = '$polygon'; public const PROPERTIES = ['points' => 'points']; - /** @var BSONArray|PackedArray|array|string $points */ - public readonly PackedArray|BSONArray|array|string $points; + /** @var BSONArray|PackedArray|array $points */ + public readonly PackedArray|BSONArray|array $points; /** - * @param BSONArray|PackedArray|array|string $points + * @param BSONArray|PackedArray|array $points */ - public function __construct(PackedArray|BSONArray|array|string $points) + public function __construct(PackedArray|BSONArray|array $points) { if (is_array($points) && ! array_is_list($points)) { throw new InvalidArgumentException('Expected $points argument to be a list, got an associative array.'); diff --git a/src/Builder/Query/RegexOperator.php b/src/Builder/Query/RegexOperator.php index 2082cb8cd..cf9ee31ff 100644 --- a/src/Builder/Query/RegexOperator.php +++ b/src/Builder/Query/RegexOperator.php @@ -25,13 +25,13 @@ final class RegexOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$regex'; public const PROPERTIES = ['regex' => 'regex']; - /** @var Regex|string $regex */ - public readonly Regex|string $regex; + /** @var Regex $regex */ + public readonly Regex $regex; /** - * @param Regex|string $regex + * @param Regex $regex */ - public function __construct(Regex|string $regex) + public function __construct(Regex $regex) { $this->regex = $regex; } diff --git a/src/Builder/Query/SampleRateOperator.php b/src/Builder/Query/SampleRateOperator.php index 692a42436..a027972da 100644 --- a/src/Builder/Query/SampleRateOperator.php +++ b/src/Builder/Query/SampleRateOperator.php @@ -13,6 +13,10 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\QueryInterface; +use MongoDB\Exception\InvalidArgumentException; + +use function is_string; +use function str_starts_with; /** * Randomly select documents at a given rate. Although the exact number of documents selected varies on each run, the quantity chosen approximates the sample rate expressed as a percentage of the total number of documents. @@ -38,6 +42,10 @@ final class SampleRateOperator implements QueryInterface, OperatorInterface */ public function __construct(Int64|ResolvesToDouble|float|int|string $rate) { + if (is_string($rate) && ! str_starts_with($rate, '$')) { + throw new InvalidArgumentException('Argument $rate can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->rate = $rate; } } diff --git a/src/Builder/Query/SizeOperator.php b/src/Builder/Query/SizeOperator.php index 2b080954c..8ec123b11 100644 --- a/src/Builder/Query/SizeOperator.php +++ b/src/Builder/Query/SizeOperator.php @@ -24,13 +24,13 @@ final class SizeOperator implements FieldQueryInterface, OperatorInterface public const NAME = '$size'; public const PROPERTIES = ['value' => 'value']; - /** @var int|string $value */ - public readonly int|string $value; + /** @var int $value */ + public readonly int $value; /** - * @param int|string $value + * @param int $value */ - public function __construct(int|string $value) + public function __construct(int $value) { $this->value = $value; } diff --git a/src/Builder/Query/TextOperator.php b/src/Builder/Query/TextOperator.php index efdf46423..7c1c0a7ba 100644 --- a/src/Builder/Query/TextOperator.php +++ b/src/Builder/Query/TextOperator.php @@ -40,28 +40,28 @@ final class TextOperator implements QueryInterface, OperatorInterface */ public readonly Optional|string $language; - /** @var Optional|bool|string $caseSensitive A boolean flag to enable or disable case sensitive search. Defaults to false; i.e. the search defers to the case insensitivity of the text index. */ - public readonly Optional|bool|string $caseSensitive; + /** @var Optional|bool $caseSensitive A boolean flag to enable or disable case sensitive search. Defaults to false; i.e. the search defers to the case insensitivity of the text index. */ + public readonly Optional|bool $caseSensitive; /** - * @var Optional|bool|string $diacriticSensitive A boolean flag to enable or disable diacritic sensitive search against version 3 text indexes. Defaults to false; i.e. the search defers to the diacritic insensitivity of the text index. + * @var Optional|bool $diacriticSensitive A boolean flag to enable or disable diacritic sensitive search against version 3 text indexes. Defaults to false; i.e. the search defers to the diacritic insensitivity of the text index. * Text searches against earlier versions of the text index are inherently diacritic sensitive and cannot be diacritic insensitive. As such, the $diacriticSensitive option has no effect with earlier versions of the text index. */ - public readonly Optional|bool|string $diacriticSensitive; + public readonly Optional|bool $diacriticSensitive; /** * @param string $search A string of terms that MongoDB parses and uses to query the text index. MongoDB performs a logical OR search of the terms unless specified as a phrase. * @param Optional|string $language The language that determines the list of stop words for the search and the rules for the stemmer and tokenizer. If not specified, the search uses the default language of the index. * If you specify a default_language value of none, then the text index parses through each word in the field, including stop words, and ignores suffix stemming. - * @param Optional|bool|string $caseSensitive A boolean flag to enable or disable case sensitive search. Defaults to false; i.e. the search defers to the case insensitivity of the text index. - * @param Optional|bool|string $diacriticSensitive A boolean flag to enable or disable diacritic sensitive search against version 3 text indexes. Defaults to false; i.e. the search defers to the diacritic insensitivity of the text index. + * @param Optional|bool $caseSensitive A boolean flag to enable or disable case sensitive search. Defaults to false; i.e. the search defers to the case insensitivity of the text index. + * @param Optional|bool $diacriticSensitive A boolean flag to enable or disable diacritic sensitive search against version 3 text indexes. Defaults to false; i.e. the search defers to the diacritic insensitivity of the text index. * Text searches against earlier versions of the text index are inherently diacritic sensitive and cannot be diacritic insensitive. As such, the $diacriticSensitive option has no effect with earlier versions of the text index. */ public function __construct( string $search, Optional|string $language = Optional::Undefined, - Optional|bool|string $caseSensitive = Optional::Undefined, - Optional|bool|string $diacriticSensitive = Optional::Undefined, + Optional|bool $caseSensitive = Optional::Undefined, + Optional|bool $diacriticSensitive = Optional::Undefined, ) { $this->search = $search; $this->language = $language; diff --git a/src/Builder/Search/AutocompleteOperator.php b/src/Builder/Search/AutocompleteOperator.php index bf0431cbd..19bdbf92d 100644 --- a/src/Builder/Search/AutocompleteOperator.php +++ b/src/Builder/Search/AutocompleteOperator.php @@ -47,8 +47,8 @@ final class AutocompleteOperator implements SearchOperatorInterface, OperatorInt /** @var Optional|string $tokenOrder */ public readonly Optional|string $tokenOrder; - /** @var Optional|Document|Serializable|array|stdClass|string $fuzzy */ - public readonly Optional|Document|Serializable|stdClass|array|string $fuzzy; + /** @var Optional|Document|Serializable|array|stdClass $fuzzy */ + public readonly Optional|Document|Serializable|stdClass|array $fuzzy; /** @var Optional|Document|Serializable|array|stdClass $score */ public readonly Optional|Document|Serializable|stdClass|array $score; @@ -57,14 +57,14 @@ final class AutocompleteOperator implements SearchOperatorInterface, OperatorInt * @param array|string $path * @param string $query * @param Optional|string $tokenOrder - * @param Optional|Document|Serializable|array|stdClass|string $fuzzy + * @param Optional|Document|Serializable|array|stdClass $fuzzy * @param Optional|Document|Serializable|array|stdClass $score */ public function __construct( array|string $path, string $query, Optional|string $tokenOrder = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $fuzzy = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $fuzzy = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ) { $this->path = $path; diff --git a/src/Builder/Search/CompoundOperator.php b/src/Builder/Search/CompoundOperator.php index 4655c85b5..27b8c2aeb 100644 --- a/src/Builder/Search/CompoundOperator.php +++ b/src/Builder/Search/CompoundOperator.php @@ -40,38 +40,38 @@ final class CompoundOperator implements SearchOperatorInterface, OperatorInterfa 'score' => 'score', ]; - /** @var Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass|string $must */ - public readonly Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array|string $must; + /** @var Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $must */ + public readonly Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $must; - /** @var Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass|string $mustNot */ - public readonly Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array|string $mustNot; + /** @var Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $mustNot */ + public readonly Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $mustNot; - /** @var Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass|string $should */ - public readonly Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array|string $should; + /** @var Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $should */ + public readonly Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $should; - /** @var Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass|string $filter */ - public readonly Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array|string $filter; + /** @var Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $filter */ + public readonly Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $filter; - /** @var Optional|int|string $minimumShouldMatch */ - public readonly Optional|int|string $minimumShouldMatch; + /** @var Optional|int $minimumShouldMatch */ + public readonly Optional|int $minimumShouldMatch; /** @var Optional|Document|Serializable|array|stdClass $score */ public readonly Optional|Document|Serializable|stdClass|array $score; /** - * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass|string $must - * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass|string $mustNot - * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass|string $should - * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass|string $filter - * @param Optional|int|string $minimumShouldMatch + * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $must + * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $mustNot + * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $should + * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $filter + * @param Optional|int $minimumShouldMatch * @param Optional|Document|Serializable|array|stdClass $score */ public function __construct( - Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array|string $must = Optional::Undefined, - Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array|string $mustNot = Optional::Undefined, - Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array|string $should = Optional::Undefined, - Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array|string $filter = Optional::Undefined, - Optional|int|string $minimumShouldMatch = Optional::Undefined, + Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $must = Optional::Undefined, + Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $mustNot = Optional::Undefined, + Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $should = Optional::Undefined, + Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $filter = Optional::Undefined, + Optional|int $minimumShouldMatch = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ) { $this->must = $must; diff --git a/src/Builder/Search/FacetOperator.php b/src/Builder/Search/FacetOperator.php index b2643b117..15fc10830 100644 --- a/src/Builder/Search/FacetOperator.php +++ b/src/Builder/Search/FacetOperator.php @@ -29,18 +29,18 @@ final class FacetOperator implements SearchOperatorInterface, OperatorInterface public const NAME = 'facet'; public const PROPERTIES = ['facets' => 'facets', 'operator' => 'operator']; - /** @var Document|Serializable|array|stdClass|string $facets */ - public readonly Document|Serializable|stdClass|array|string $facets; + /** @var Document|Serializable|array|stdClass $facets */ + public readonly Document|Serializable|stdClass|array $facets; /** @var Optional|Document|SearchOperatorInterface|Serializable|array|stdClass $operator */ public readonly Optional|Document|Serializable|SearchOperatorInterface|stdClass|array $operator; /** - * @param Document|Serializable|array|stdClass|string $facets + * @param Document|Serializable|array|stdClass $facets * @param Optional|Document|SearchOperatorInterface|Serializable|array|stdClass $operator */ public function __construct( - Document|Serializable|stdClass|array|string $facets, + Document|Serializable|stdClass|array $facets, Optional|Document|Serializable|SearchOperatorInterface|stdClass|array $operator = Optional::Undefined, ) { $this->facets = $facets; diff --git a/src/Builder/Search/FactoryTrait.php b/src/Builder/Search/FactoryTrait.php index 9eb7103a4..3a7762521 100644 --- a/src/Builder/Search/FactoryTrait.php +++ b/src/Builder/Search/FactoryTrait.php @@ -38,14 +38,14 @@ trait FactoryTrait * @param array|string $path * @param string $query * @param Optional|string $tokenOrder - * @param Optional|Document|Serializable|array|stdClass|string $fuzzy + * @param Optional|Document|Serializable|array|stdClass $fuzzy * @param Optional|Document|Serializable|array|stdClass $score */ public static function autocomplete( array|string $path, string $query, Optional|string $tokenOrder = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $fuzzy = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $fuzzy = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ): AutocompleteOperator { return new AutocompleteOperator($path, $query, $tokenOrder, $fuzzy, $score); @@ -57,19 +57,19 @@ public static function autocomplete( * consists of one or more sub-queries. * * @see https://www.mongodb.com/docs/atlas/atlas-search/compound/ - * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass|string $must - * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass|string $mustNot - * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass|string $should - * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass|string $filter - * @param Optional|int|string $minimumShouldMatch + * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $must + * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $mustNot + * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $should + * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $filter + * @param Optional|int $minimumShouldMatch * @param Optional|Document|Serializable|array|stdClass $score */ public static function compound( - Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array|string $must = Optional::Undefined, - Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array|string $mustNot = Optional::Undefined, - Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array|string $should = Optional::Undefined, - Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array|string $filter = Optional::Undefined, - Optional|int|string $minimumShouldMatch = Optional::Undefined, + Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $must = Optional::Undefined, + Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $mustNot = Optional::Undefined, + Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $should = Optional::Undefined, + Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $filter = Optional::Undefined, + Optional|int $minimumShouldMatch = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ): CompoundOperator { return new CompoundOperator($must, $mustNot, $should, $filter, $minimumShouldMatch, $score); @@ -129,11 +129,11 @@ public static function exists( * faceted fields and returns the count for each of those groups. * * @see https://www.mongodb.com/docs/atlas/atlas-search/facet/ - * @param Document|Serializable|array|stdClass|string $facets + * @param Document|Serializable|array|stdClass $facets * @param Optional|Document|SearchOperatorInterface|Serializable|array|stdClass $operator */ public static function facet( - Document|Serializable|stdClass|array|string $facets, + Document|Serializable|stdClass|array $facets, Optional|Document|Serializable|SearchOperatorInterface|stdClass|array $operator = Optional::Undefined, ): FacetOperator { return new FacetOperator($facets, $operator); @@ -165,15 +165,15 @@ public static function geoShape( * * @see https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/ * @param array|string $path - * @param Optional|Document|Serializable|array|stdClass|string $box - * @param Optional|Document|Serializable|array|stdClass|string $circle + * @param Optional|Document|Serializable|array|stdClass $box + * @param Optional|Document|Serializable|array|stdClass $circle * @param Optional|Document|GeometryInterface|Serializable|array|stdClass $geometry * @param Optional|Document|Serializable|array|stdClass $score */ public static function geoWithin( array|string $path, - Optional|Document|Serializable|stdClass|array|string $box = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $circle = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $box = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $circle = Optional::Undefined, Optional|Document|Serializable|GeometryInterface|stdClass|array $geometry = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ): GeoWithinOperator { @@ -202,11 +202,11 @@ public static function in( * that display similar or alternative results based on one or more given documents. * * @see https://www.mongodb.com/docs/atlas/atlas-search/moreLikeThis/ - * @param BSONArray|Document|PackedArray|Serializable|array|stdClass|string $like + * @param BSONArray|Document|PackedArray|Serializable|array|stdClass $like * @param Optional|Document|Serializable|array|stdClass $score */ public static function moreLikeThis( - Document|PackedArray|Serializable|BSONArray|stdClass|array|string $like, + Document|PackedArray|Serializable|BSONArray|stdClass|array $like, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ): MoreLikeThisOperator { return new MoreLikeThisOperator($like, $score); @@ -217,14 +217,14 @@ public static function moreLikeThis( * * @see https://www.mongodb.com/docs/atlas/atlas-search/near/ * @param array|string $path - * @param Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass|string $origin - * @param Decimal128|Int64|float|int|string $pivot + * @param Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass $origin + * @param Decimal128|Int64|float|int $pivot * @param Optional|Document|Serializable|array|stdClass $score */ public static function near( array|string $path, - Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int|string $origin, - Decimal128|Int64|float|int|string $pivot, + Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int $origin, + Decimal128|Int64|float|int $pivot, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ): NearOperator { return new NearOperator($path, $origin, $pivot, $score); @@ -236,14 +236,14 @@ public static function near( * @see https://www.mongodb.com/docs/atlas/atlas-search/phrase/ * @param array|string $path * @param BSONArray|PackedArray|array|string $query - * @param Optional|int|string $slop + * @param Optional|int $slop * @param Optional|string $synonyms * @param Optional|Document|Serializable|array|stdClass $score */ public static function phrase( array|string $path, PackedArray|BSONArray|array|string $query, - Optional|int|string $slop = Optional::Undefined, + Optional|int $slop = Optional::Undefined, Optional|string $synonyms = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ): PhraseOperator { @@ -290,13 +290,13 @@ public static function range( * @see https://www.mongodb.com/docs/atlas/atlas-search/regex/ * @param array|string $path * @param string $query - * @param Optional|bool|string $allowAnalyzedField + * @param Optional|bool $allowAnalyzedField * @param Optional|Document|Serializable|array|stdClass $score */ public static function regex( array|string $path, string $query, - Optional|bool|string $allowAnalyzedField = Optional::Undefined, + Optional|bool $allowAnalyzedField = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ): RegexOperator { return new RegexOperator($path, $query, $allowAnalyzedField, $score); @@ -309,7 +309,7 @@ public static function regex( * @see https://www.mongodb.com/docs/atlas/atlas-search/text/ * @param array|string $path * @param string $query - * @param Optional|Document|Serializable|array|stdClass|string $fuzzy + * @param Optional|Document|Serializable|array|stdClass $fuzzy * @param Optional|string $matchCriteria * @param Optional|string $synonyms * @param Optional|Document|Serializable|array|stdClass $score @@ -317,7 +317,7 @@ public static function regex( public static function text( array|string $path, string $query, - Optional|Document|Serializable|stdClass|array|string $fuzzy = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $fuzzy = Optional::Undefined, Optional|string $matchCriteria = Optional::Undefined, Optional|string $synonyms = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, @@ -331,13 +331,13 @@ public static function text( * @see https://www.mongodb.com/docs/atlas/atlas-search/wildcard/ * @param array|string $path * @param string $query - * @param Optional|bool|string $allowAnalyzedField + * @param Optional|bool $allowAnalyzedField * @param Optional|Document|Serializable|array|stdClass $score */ public static function wildcard( array|string $path, string $query, - Optional|bool|string $allowAnalyzedField = Optional::Undefined, + Optional|bool $allowAnalyzedField = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ): WildcardOperator { return new WildcardOperator($path, $query, $allowAnalyzedField, $score); diff --git a/src/Builder/Search/GeoWithinOperator.php b/src/Builder/Search/GeoWithinOperator.php index 7efec6aff..dcf605697 100644 --- a/src/Builder/Search/GeoWithinOperator.php +++ b/src/Builder/Search/GeoWithinOperator.php @@ -41,11 +41,11 @@ final class GeoWithinOperator implements SearchOperatorInterface, OperatorInterf /** @var array|string $path */ public readonly array|string $path; - /** @var Optional|Document|Serializable|array|stdClass|string $box */ - public readonly Optional|Document|Serializable|stdClass|array|string $box; + /** @var Optional|Document|Serializable|array|stdClass $box */ + public readonly Optional|Document|Serializable|stdClass|array $box; - /** @var Optional|Document|Serializable|array|stdClass|string $circle */ - public readonly Optional|Document|Serializable|stdClass|array|string $circle; + /** @var Optional|Document|Serializable|array|stdClass $circle */ + public readonly Optional|Document|Serializable|stdClass|array $circle; /** @var Optional|Document|GeometryInterface|Serializable|array|stdClass $geometry */ public readonly Optional|Document|Serializable|GeometryInterface|stdClass|array $geometry; @@ -55,15 +55,15 @@ final class GeoWithinOperator implements SearchOperatorInterface, OperatorInterf /** * @param array|string $path - * @param Optional|Document|Serializable|array|stdClass|string $box - * @param Optional|Document|Serializable|array|stdClass|string $circle + * @param Optional|Document|Serializable|array|stdClass $box + * @param Optional|Document|Serializable|array|stdClass $circle * @param Optional|Document|GeometryInterface|Serializable|array|stdClass $geometry * @param Optional|Document|Serializable|array|stdClass $score */ public function __construct( array|string $path, - Optional|Document|Serializable|stdClass|array|string $box = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $circle = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $box = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $circle = Optional::Undefined, Optional|Document|Serializable|GeometryInterface|stdClass|array $geometry = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ) { diff --git a/src/Builder/Search/MoreLikeThisOperator.php b/src/Builder/Search/MoreLikeThisOperator.php index cf21a15a3..689508d53 100644 --- a/src/Builder/Search/MoreLikeThisOperator.php +++ b/src/Builder/Search/MoreLikeThisOperator.php @@ -32,18 +32,18 @@ final class MoreLikeThisOperator implements SearchOperatorInterface, OperatorInt public const NAME = 'moreLikeThis'; public const PROPERTIES = ['like' => 'like', 'score' => 'score']; - /** @var BSONArray|Document|PackedArray|Serializable|array|stdClass|string $like */ - public readonly Document|PackedArray|Serializable|BSONArray|stdClass|array|string $like; + /** @var BSONArray|Document|PackedArray|Serializable|array|stdClass $like */ + public readonly Document|PackedArray|Serializable|BSONArray|stdClass|array $like; /** @var Optional|Document|Serializable|array|stdClass $score */ public readonly Optional|Document|Serializable|stdClass|array $score; /** - * @param BSONArray|Document|PackedArray|Serializable|array|stdClass|string $like + * @param BSONArray|Document|PackedArray|Serializable|array|stdClass $like * @param Optional|Document|Serializable|array|stdClass $score */ public function __construct( - Document|PackedArray|Serializable|BSONArray|stdClass|array|string $like, + Document|PackedArray|Serializable|BSONArray|stdClass|array $like, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ) { $this->like = $like; diff --git a/src/Builder/Search/NearOperator.php b/src/Builder/Search/NearOperator.php index 2afa6517d..ab1b9b0c1 100644 --- a/src/Builder/Search/NearOperator.php +++ b/src/Builder/Search/NearOperator.php @@ -35,25 +35,25 @@ final class NearOperator implements SearchOperatorInterface, OperatorInterface /** @var array|string $path */ public readonly array|string $path; - /** @var Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass|string $origin */ - public readonly Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int|string $origin; + /** @var Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass $origin */ + public readonly Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int $origin; - /** @var Decimal128|Int64|float|int|string $pivot */ - public readonly Decimal128|Int64|float|int|string $pivot; + /** @var Decimal128|Int64|float|int $pivot */ + public readonly Decimal128|Int64|float|int $pivot; /** @var Optional|Document|Serializable|array|stdClass $score */ public readonly Optional|Document|Serializable|stdClass|array $score; /** * @param array|string $path - * @param Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass|string $origin - * @param Decimal128|Int64|float|int|string $pivot + * @param Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass $origin + * @param Decimal128|Int64|float|int $pivot * @param Optional|Document|Serializable|array|stdClass $score */ public function __construct( array|string $path, - Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int|string $origin, - Decimal128|Int64|float|int|string $pivot, + Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int $origin, + Decimal128|Int64|float|int $pivot, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ) { $this->path = $path; diff --git a/src/Builder/Search/PhraseOperator.php b/src/Builder/Search/PhraseOperator.php index c0303c34c..2bbb707a9 100644 --- a/src/Builder/Search/PhraseOperator.php +++ b/src/Builder/Search/PhraseOperator.php @@ -47,8 +47,8 @@ final class PhraseOperator implements SearchOperatorInterface, OperatorInterface /** @var BSONArray|PackedArray|array|string $query */ public readonly PackedArray|BSONArray|array|string $query; - /** @var Optional|int|string $slop */ - public readonly Optional|int|string $slop; + /** @var Optional|int $slop */ + public readonly Optional|int $slop; /** @var Optional|string $synonyms */ public readonly Optional|string $synonyms; @@ -59,14 +59,14 @@ final class PhraseOperator implements SearchOperatorInterface, OperatorInterface /** * @param array|string $path * @param BSONArray|PackedArray|array|string $query - * @param Optional|int|string $slop + * @param Optional|int $slop * @param Optional|string $synonyms * @param Optional|Document|Serializable|array|stdClass $score */ public function __construct( array|string $path, PackedArray|BSONArray|array|string $query, - Optional|int|string $slop = Optional::Undefined, + Optional|int $slop = Optional::Undefined, Optional|string $synonyms = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ) { diff --git a/src/Builder/Search/RegexOperator.php b/src/Builder/Search/RegexOperator.php index 3cc88fcff..6b2c2d63a 100644 --- a/src/Builder/Search/RegexOperator.php +++ b/src/Builder/Search/RegexOperator.php @@ -41,8 +41,8 @@ final class RegexOperator implements SearchOperatorInterface, OperatorInterface /** @var string $query */ public readonly string $query; - /** @var Optional|bool|string $allowAnalyzedField */ - public readonly Optional|bool|string $allowAnalyzedField; + /** @var Optional|bool $allowAnalyzedField */ + public readonly Optional|bool $allowAnalyzedField; /** @var Optional|Document|Serializable|array|stdClass $score */ public readonly Optional|Document|Serializable|stdClass|array $score; @@ -50,13 +50,13 @@ final class RegexOperator implements SearchOperatorInterface, OperatorInterface /** * @param array|string $path * @param string $query - * @param Optional|bool|string $allowAnalyzedField + * @param Optional|bool $allowAnalyzedField * @param Optional|Document|Serializable|array|stdClass $score */ public function __construct( array|string $path, string $query, - Optional|bool|string $allowAnalyzedField = Optional::Undefined, + Optional|bool $allowAnalyzedField = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ) { $this->path = $path; diff --git a/src/Builder/Search/TextOperator.php b/src/Builder/Search/TextOperator.php index 802672efe..4ade6b434 100644 --- a/src/Builder/Search/TextOperator.php +++ b/src/Builder/Search/TextOperator.php @@ -43,8 +43,8 @@ final class TextOperator implements SearchOperatorInterface, OperatorInterface /** @var string $query */ public readonly string $query; - /** @var Optional|Document|Serializable|array|stdClass|string $fuzzy */ - public readonly Optional|Document|Serializable|stdClass|array|string $fuzzy; + /** @var Optional|Document|Serializable|array|stdClass $fuzzy */ + public readonly Optional|Document|Serializable|stdClass|array $fuzzy; /** @var Optional|string $matchCriteria */ public readonly Optional|string $matchCriteria; @@ -58,7 +58,7 @@ final class TextOperator implements SearchOperatorInterface, OperatorInterface /** * @param array|string $path * @param string $query - * @param Optional|Document|Serializable|array|stdClass|string $fuzzy + * @param Optional|Document|Serializable|array|stdClass $fuzzy * @param Optional|string $matchCriteria * @param Optional|string $synonyms * @param Optional|Document|Serializable|array|stdClass $score @@ -66,7 +66,7 @@ final class TextOperator implements SearchOperatorInterface, OperatorInterface public function __construct( array|string $path, string $query, - Optional|Document|Serializable|stdClass|array|string $fuzzy = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $fuzzy = Optional::Undefined, Optional|string $matchCriteria = Optional::Undefined, Optional|string $synonyms = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, diff --git a/src/Builder/Search/WildcardOperator.php b/src/Builder/Search/WildcardOperator.php index 3ed54ed1a..ee481910e 100644 --- a/src/Builder/Search/WildcardOperator.php +++ b/src/Builder/Search/WildcardOperator.php @@ -40,8 +40,8 @@ final class WildcardOperator implements SearchOperatorInterface, OperatorInterfa /** @var string $query */ public readonly string $query; - /** @var Optional|bool|string $allowAnalyzedField */ - public readonly Optional|bool|string $allowAnalyzedField; + /** @var Optional|bool $allowAnalyzedField */ + public readonly Optional|bool $allowAnalyzedField; /** @var Optional|Document|Serializable|array|stdClass $score */ public readonly Optional|Document|Serializable|stdClass|array $score; @@ -49,13 +49,13 @@ final class WildcardOperator implements SearchOperatorInterface, OperatorInterfa /** * @param array|string $path * @param string $query - * @param Optional|bool|string $allowAnalyzedField + * @param Optional|bool $allowAnalyzedField * @param Optional|Document|Serializable|array|stdClass $score */ public function __construct( array|string $path, string $query, - Optional|bool|string $allowAnalyzedField = Optional::Undefined, + Optional|bool $allowAnalyzedField = Optional::Undefined, Optional|Document|Serializable|stdClass|array $score = Optional::Undefined, ) { $this->path = $path; diff --git a/src/Builder/Stage/BucketAutoStage.php b/src/Builder/Stage/BucketAutoStage.php index f1601a497..11c456e69 100644 --- a/src/Builder/Stage/BucketAutoStage.php +++ b/src/Builder/Stage/BucketAutoStage.php @@ -39,14 +39,14 @@ final class BucketAutoStage implements StageInterface, OperatorInterface /** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. */ public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy; - /** @var int|string $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. */ - public readonly int|string $buckets; + /** @var int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. */ + public readonly int $buckets; /** - * @var Optional|Document|Serializable|array|stdClass|string $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. + * @var Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * The default count field is not included in the output document when output is specified. Explicitly specify the count expression as part of the output document to include it. */ - public readonly Optional|Document|Serializable|stdClass|array|string $output; + public readonly Optional|Document|Serializable|stdClass|array $output; /** * @var Optional|string $granularity A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. @@ -56,16 +56,16 @@ final class BucketAutoStage implements StageInterface, OperatorInterface /** * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. - * @param int|string $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. - * @param Optional|Document|Serializable|array|stdClass|string $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. + * @param int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. + * @param Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * The default count field is not included in the output document when output is specified. Explicitly specify the count expression as part of the output document to include it. * @param Optional|string $granularity A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. * Available only if the all groupBy values are numeric and none of them are NaN. */ public function __construct( Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, - int|string $buckets, - Optional|Document|Serializable|stdClass|array|string $output = Optional::Undefined, + int $buckets, + Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, Optional|string $granularity = Optional::Undefined, ) { $this->groupBy = $groupBy; diff --git a/src/Builder/Stage/BucketStage.php b/src/Builder/Stage/BucketStage.php index 7ddd96912..211987c66 100644 --- a/src/Builder/Stage/BucketStage.php +++ b/src/Builder/Stage/BucketStage.php @@ -49,10 +49,10 @@ final class BucketStage implements StageInterface, OperatorInterface public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy; /** - * @var BSONArray|PackedArray|array|string $boundaries An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. + * @var BSONArray|PackedArray|array $boundaries An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. * The specified values must be in ascending order and all of the same type. The exception is if the values are of mixed numeric types, such as: */ - public readonly PackedArray|BSONArray|array|string $boundaries; + public readonly PackedArray|BSONArray|array $boundaries; /** * @var Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. @@ -63,30 +63,30 @@ final class BucketStage implements StageInterface, OperatorInterface public readonly Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default; /** - * @var Optional|Document|Serializable|array|stdClass|string $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. + * @var Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * If you do not specify an output document, the operation returns a count field containing the number of documents in each bucket. * If you specify an output document, only the fields specified in the document are returned; i.e. the count field is not returned unless it is explicitly included in the output document. */ - public readonly Optional|Document|Serializable|stdClass|array|string $output; + public readonly Optional|Document|Serializable|stdClass|array $output; /** * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * Unless $bucket includes a default specification, each input document must resolve the groupBy field path or expression to a value that falls within one of the ranges specified by the boundaries. - * @param BSONArray|PackedArray|array|string $boundaries An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. + * @param BSONArray|PackedArray|array $boundaries An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. * The specified values must be in ascending order and all of the same type. The exception is if the values are of mixed numeric types, such as: * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. * If unspecified, each input document must resolve the groupBy expression to a value within one of the bucket ranges specified by boundaries or the operation throws an error. * The default value must be less than the lowest boundaries value, or greater than or equal to the highest boundaries value. * The default value can be of a different type than the entries in boundaries. - * @param Optional|Document|Serializable|array|stdClass|string $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. + * @param Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * If you do not specify an output document, the operation returns a count field containing the number of documents in each bucket. * If you specify an output document, only the fields specified in the document are returned; i.e. the count field is not returned unless it is explicitly included in the output document. */ public function __construct( Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, - PackedArray|BSONArray|array|string $boundaries, + PackedArray|BSONArray|array $boundaries, Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $output = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, ) { $this->groupBy = $groupBy; if (is_array($boundaries) && ! array_is_list($boundaries)) { diff --git a/src/Builder/Stage/ChangeStreamStage.php b/src/Builder/Stage/ChangeStreamStage.php index f67cfaada..d9c22eaa4 100644 --- a/src/Builder/Stage/ChangeStreamStage.php +++ b/src/Builder/Stage/ChangeStreamStage.php @@ -38,8 +38,8 @@ final class ChangeStreamStage implements StageInterface, OperatorInterface 'startAtOperationTime' => 'startAtOperationTime', ]; - /** @var Optional|bool|string $allChangesForCluster A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. */ - public readonly Optional|bool|string $allChangesForCluster; + /** @var Optional|bool $allChangesForCluster A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. */ + public readonly Optional|bool $allChangesForCluster; /** @var Optional|string $fullDocument Specifies whether change notifications include a copy of the full document when modified by update operations. */ public readonly Optional|string $fullDocument; @@ -47,39 +47,39 @@ final class ChangeStreamStage implements StageInterface, OperatorInterface /** @var Optional|string $fullDocumentBeforeChange Valid values are "off", "whenAvailable", or "required". If set to "off", the "fullDocumentBeforeChange" field of the output document is always omitted. If set to "whenAvailable", the "fullDocumentBeforeChange" field will be populated with the pre-image of the document modified by the current change event if such a pre-image is available, and will be omitted otherwise. If set to "required", then the "fullDocumentBeforeChange" field is always populated and an exception is thrown if the pre-image is not available. */ public readonly Optional|string $fullDocumentBeforeChange; - /** @var Optional|int|string $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. */ - public readonly Optional|int|string $resumeAfter; + /** @var Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. */ + public readonly Optional|int $resumeAfter; /** - * @var Optional|bool|string $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. + * @var Optional|bool $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. * New in MongoDB 6.0. */ - public readonly Optional|bool|string $showExpandedEvents; + public readonly Optional|bool $showExpandedEvents; - /** @var Optional|Document|Serializable|array|stdClass|string $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. */ - public readonly Optional|Document|Serializable|stdClass|array|string $startAfter; + /** @var Optional|Document|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. */ + public readonly Optional|Document|Serializable|stdClass|array $startAfter; - /** @var Optional|Timestamp|int|string $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ - public readonly Optional|Timestamp|int|string $startAtOperationTime; + /** @var Optional|Timestamp|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ + public readonly Optional|Timestamp|int $startAtOperationTime; /** - * @param Optional|bool|string $allChangesForCluster A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. + * @param Optional|bool $allChangesForCluster A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. * @param Optional|string $fullDocument Specifies whether change notifications include a copy of the full document when modified by update operations. * @param Optional|string $fullDocumentBeforeChange Valid values are "off", "whenAvailable", or "required". If set to "off", the "fullDocumentBeforeChange" field of the output document is always omitted. If set to "whenAvailable", the "fullDocumentBeforeChange" field will be populated with the pre-image of the document modified by the current change event if such a pre-image is available, and will be omitted otherwise. If set to "required", then the "fullDocumentBeforeChange" field is always populated and an exception is thrown if the pre-image is not available. - * @param Optional|int|string $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. - * @param Optional|bool|string $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. + * @param Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. + * @param Optional|bool $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. * New in MongoDB 6.0. - * @param Optional|Document|Serializable|array|stdClass|string $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. - * @param Optional|Timestamp|int|string $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. + * @param Optional|Document|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. + * @param Optional|Timestamp|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ public function __construct( - Optional|bool|string $allChangesForCluster = Optional::Undefined, + Optional|bool $allChangesForCluster = Optional::Undefined, Optional|string $fullDocument = Optional::Undefined, Optional|string $fullDocumentBeforeChange = Optional::Undefined, - Optional|int|string $resumeAfter = Optional::Undefined, - Optional|bool|string $showExpandedEvents = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $startAfter = Optional::Undefined, - Optional|Timestamp|int|string $startAtOperationTime = Optional::Undefined, + Optional|int $resumeAfter = Optional::Undefined, + Optional|bool $showExpandedEvents = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $startAfter = Optional::Undefined, + Optional|Timestamp|int $startAtOperationTime = Optional::Undefined, ) { $this->allChangesForCluster = $allChangesForCluster; $this->fullDocument = $fullDocument; diff --git a/src/Builder/Stage/CollStatsStage.php b/src/Builder/Stage/CollStatsStage.php index 3163c0821..d84245320 100644 --- a/src/Builder/Stage/CollStatsStage.php +++ b/src/Builder/Stage/CollStatsStage.php @@ -34,29 +34,29 @@ final class CollStatsStage implements StageInterface, OperatorInterface 'queryExecStats' => 'queryExecStats', ]; - /** @var Optional|Document|Serializable|array|stdClass|string $latencyStats */ - public readonly Optional|Document|Serializable|stdClass|array|string $latencyStats; + /** @var Optional|Document|Serializable|array|stdClass $latencyStats */ + public readonly Optional|Document|Serializable|stdClass|array $latencyStats; - /** @var Optional|Document|Serializable|array|stdClass|string $storageStats */ - public readonly Optional|Document|Serializable|stdClass|array|string $storageStats; + /** @var Optional|Document|Serializable|array|stdClass $storageStats */ + public readonly Optional|Document|Serializable|stdClass|array $storageStats; - /** @var Optional|Document|Serializable|array|stdClass|string $count */ - public readonly Optional|Document|Serializable|stdClass|array|string $count; + /** @var Optional|Document|Serializable|array|stdClass $count */ + public readonly Optional|Document|Serializable|stdClass|array $count; - /** @var Optional|Document|Serializable|array|stdClass|string $queryExecStats */ - public readonly Optional|Document|Serializable|stdClass|array|string $queryExecStats; + /** @var Optional|Document|Serializable|array|stdClass $queryExecStats */ + public readonly Optional|Document|Serializable|stdClass|array $queryExecStats; /** - * @param Optional|Document|Serializable|array|stdClass|string $latencyStats - * @param Optional|Document|Serializable|array|stdClass|string $storageStats - * @param Optional|Document|Serializable|array|stdClass|string $count - * @param Optional|Document|Serializable|array|stdClass|string $queryExecStats + * @param Optional|Document|Serializable|array|stdClass $latencyStats + * @param Optional|Document|Serializable|array|stdClass $storageStats + * @param Optional|Document|Serializable|array|stdClass $count + * @param Optional|Document|Serializable|array|stdClass $queryExecStats */ public function __construct( - Optional|Document|Serializable|stdClass|array|string $latencyStats = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $storageStats = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $count = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $queryExecStats = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $latencyStats = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $storageStats = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $count = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $queryExecStats = Optional::Undefined, ) { $this->latencyStats = $latencyStats; $this->storageStats = $storageStats; diff --git a/src/Builder/Stage/CurrentOpStage.php b/src/Builder/Stage/CurrentOpStage.php index 201ff795b..3d0d6abb2 100644 --- a/src/Builder/Stage/CurrentOpStage.php +++ b/src/Builder/Stage/CurrentOpStage.php @@ -32,34 +32,34 @@ final class CurrentOpStage implements StageInterface, OperatorInterface 'localOps' => 'localOps', ]; - /** @var Optional|bool|string $allUsers */ - public readonly Optional|bool|string $allUsers; + /** @var Optional|bool $allUsers */ + public readonly Optional|bool $allUsers; - /** @var Optional|bool|string $idleConnections */ - public readonly Optional|bool|string $idleConnections; + /** @var Optional|bool $idleConnections */ + public readonly Optional|bool $idleConnections; - /** @var Optional|bool|string $idleCursors */ - public readonly Optional|bool|string $idleCursors; + /** @var Optional|bool $idleCursors */ + public readonly Optional|bool $idleCursors; - /** @var Optional|bool|string $idleSessions */ - public readonly Optional|bool|string $idleSessions; + /** @var Optional|bool $idleSessions */ + public readonly Optional|bool $idleSessions; - /** @var Optional|bool|string $localOps */ - public readonly Optional|bool|string $localOps; + /** @var Optional|bool $localOps */ + public readonly Optional|bool $localOps; /** - * @param Optional|bool|string $allUsers - * @param Optional|bool|string $idleConnections - * @param Optional|bool|string $idleCursors - * @param Optional|bool|string $idleSessions - * @param Optional|bool|string $localOps + * @param Optional|bool $allUsers + * @param Optional|bool $idleConnections + * @param Optional|bool $idleCursors + * @param Optional|bool $idleSessions + * @param Optional|bool $localOps */ public function __construct( - Optional|bool|string $allUsers = Optional::Undefined, - Optional|bool|string $idleConnections = Optional::Undefined, - Optional|bool|string $idleCursors = Optional::Undefined, - Optional|bool|string $idleSessions = Optional::Undefined, - Optional|bool|string $localOps = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, + Optional|bool $idleConnections = Optional::Undefined, + Optional|bool $idleCursors = Optional::Undefined, + Optional|bool $idleSessions = Optional::Undefined, + Optional|bool $localOps = Optional::Undefined, ) { $this->allUsers = $allUsers; $this->idleConnections = $idleConnections; diff --git a/src/Builder/Stage/DensifyStage.php b/src/Builder/Stage/DensifyStage.php index 7f83ae880..9ecff7bbc 100644 --- a/src/Builder/Stage/DensifyStage.php +++ b/src/Builder/Stage/DensifyStage.php @@ -44,20 +44,20 @@ final class DensifyStage implements StageInterface, OperatorInterface /** @var Document|Serializable|array|stdClass $range Specification for range based densification. */ public readonly Document|Serializable|stdClass|array $range; - /** @var Optional|BSONArray|PackedArray|array|string $partitionByFields The field(s) that will be used as the partition keys. */ - public readonly Optional|PackedArray|BSONArray|array|string $partitionByFields; + /** @var Optional|BSONArray|PackedArray|array $partitionByFields The field(s) that will be used as the partition keys. */ + public readonly Optional|PackedArray|BSONArray|array $partitionByFields; /** * @param string $field The field to densify. The values of the specified field must either be all numeric values or all dates. * Documents that do not contain the specified field continue through the pipeline unmodified. * To specify a in an embedded document or in an array, use dot notation. * @param Document|Serializable|array|stdClass $range Specification for range based densification. - * @param Optional|BSONArray|PackedArray|array|string $partitionByFields The field(s) that will be used as the partition keys. + * @param Optional|BSONArray|PackedArray|array $partitionByFields The field(s) that will be used as the partition keys. */ public function __construct( string $field, Document|Serializable|stdClass|array $range, - Optional|PackedArray|BSONArray|array|string $partitionByFields = Optional::Undefined, + Optional|PackedArray|BSONArray|array $partitionByFields = Optional::Undefined, ) { $this->field = $field; $this->range = $range; diff --git a/src/Builder/Stage/DocumentsStage.php b/src/Builder/Stage/DocumentsStage.php index a67dc2bec..316afda97 100644 --- a/src/Builder/Stage/DocumentsStage.php +++ b/src/Builder/Stage/DocumentsStage.php @@ -18,6 +18,8 @@ use function array_is_list; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns literal documents from input values. @@ -53,6 +55,10 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $ throw new InvalidArgumentException('Expected $documents argument to be a list, got an associative array.'); } + if (is_string($documents) && ! str_starts_with($documents, '$')) { + throw new InvalidArgumentException('Argument $documents can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->documents = $documents; } } diff --git a/src/Builder/Stage/FactoryTrait.php b/src/Builder/Stage/FactoryTrait.php index 92bf18de5..bb63bb107 100644 --- a/src/Builder/Stage/FactoryTrait.php +++ b/src/Builder/Stage/FactoryTrait.php @@ -52,21 +52,21 @@ public static function addFields( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/ * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * Unless $bucket includes a default specification, each input document must resolve the groupBy field path or expression to a value that falls within one of the ranges specified by the boundaries. - * @param BSONArray|PackedArray|array|string $boundaries An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. + * @param BSONArray|PackedArray|array $boundaries An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. * The specified values must be in ascending order and all of the same type. The exception is if the values are of mixed numeric types, such as: * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. * If unspecified, each input document must resolve the groupBy expression to a value within one of the bucket ranges specified by boundaries or the operation throws an error. * The default value must be less than the lowest boundaries value, or greater than or equal to the highest boundaries value. * The default value can be of a different type than the entries in boundaries. - * @param Optional|Document|Serializable|array|stdClass|string $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. + * @param Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * If you do not specify an output document, the operation returns a count field containing the number of documents in each bucket. * If you specify an output document, only the fields specified in the document are returned; i.e. the count field is not returned unless it is explicitly included in the output document. */ public static function bucket( Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, - PackedArray|BSONArray|array|string $boundaries, + PackedArray|BSONArray|array $boundaries, Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $output = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, ): BucketStage { return new BucketStage($groupBy, $boundaries, $default, $output); } @@ -76,16 +76,16 @@ public static function bucket( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/ * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. - * @param int|string $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. - * @param Optional|Document|Serializable|array|stdClass|string $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. + * @param int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. + * @param Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * The default count field is not included in the output document when output is specified. Explicitly specify the count expression as part of the output document to include it. * @param Optional|string $granularity A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. * Available only if the all groupBy values are numeric and none of them are NaN. */ public static function bucketAuto( Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, - int|string $buckets, - Optional|Document|Serializable|stdClass|array|string $output = Optional::Undefined, + int $buckets, + Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, Optional|string $granularity = Optional::Undefined, ): BucketAutoStage { return new BucketAutoStage($groupBy, $buckets, $output, $granularity); @@ -95,23 +95,23 @@ public static function bucketAuto( * Returns a Change Stream cursor for the collection or database. This stage can only occur once in an aggregation pipeline and it must occur as the first stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/ - * @param Optional|bool|string $allChangesForCluster A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. + * @param Optional|bool $allChangesForCluster A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. * @param Optional|string $fullDocument Specifies whether change notifications include a copy of the full document when modified by update operations. * @param Optional|string $fullDocumentBeforeChange Valid values are "off", "whenAvailable", or "required". If set to "off", the "fullDocumentBeforeChange" field of the output document is always omitted. If set to "whenAvailable", the "fullDocumentBeforeChange" field will be populated with the pre-image of the document modified by the current change event if such a pre-image is available, and will be omitted otherwise. If set to "required", then the "fullDocumentBeforeChange" field is always populated and an exception is thrown if the pre-image is not available. - * @param Optional|int|string $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. - * @param Optional|bool|string $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. + * @param Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. + * @param Optional|bool $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. * New in MongoDB 6.0. - * @param Optional|Document|Serializable|array|stdClass|string $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. - * @param Optional|Timestamp|int|string $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. + * @param Optional|Document|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. + * @param Optional|Timestamp|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ public static function changeStream( - Optional|bool|string $allChangesForCluster = Optional::Undefined, + Optional|bool $allChangesForCluster = Optional::Undefined, Optional|string $fullDocument = Optional::Undefined, Optional|string $fullDocumentBeforeChange = Optional::Undefined, - Optional|int|string $resumeAfter = Optional::Undefined, - Optional|bool|string $showExpandedEvents = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $startAfter = Optional::Undefined, - Optional|Timestamp|int|string $startAtOperationTime = Optional::Undefined, + Optional|int $resumeAfter = Optional::Undefined, + Optional|bool $showExpandedEvents = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $startAfter = Optional::Undefined, + Optional|Timestamp|int $startAtOperationTime = Optional::Undefined, ): ChangeStreamStage { return new ChangeStreamStage($allChangesForCluster, $fullDocument, $fullDocumentBeforeChange, $resumeAfter, $showExpandedEvents, $startAfter, $startAtOperationTime); } @@ -131,16 +131,16 @@ public static function changeStreamSplitLargeEvent(): ChangeStreamSplitLargeEven * Returns statistics regarding a collection or view. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/ - * @param Optional|Document|Serializable|array|stdClass|string $latencyStats - * @param Optional|Document|Serializable|array|stdClass|string $storageStats - * @param Optional|Document|Serializable|array|stdClass|string $count - * @param Optional|Document|Serializable|array|stdClass|string $queryExecStats + * @param Optional|Document|Serializable|array|stdClass $latencyStats + * @param Optional|Document|Serializable|array|stdClass $storageStats + * @param Optional|Document|Serializable|array|stdClass $count + * @param Optional|Document|Serializable|array|stdClass $queryExecStats */ public static function collStats( - Optional|Document|Serializable|stdClass|array|string $latencyStats = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $storageStats = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $count = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $queryExecStats = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $latencyStats = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $storageStats = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $count = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $queryExecStats = Optional::Undefined, ): CollStatsStage { return new CollStatsStage($latencyStats, $storageStats, $count, $queryExecStats); } @@ -161,18 +161,18 @@ public static function count(string $field): CountStage * Returns information on active and/or dormant operations for the MongoDB deployment. To run, use the db.aggregate() method. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/ - * @param Optional|bool|string $allUsers - * @param Optional|bool|string $idleConnections - * @param Optional|bool|string $idleCursors - * @param Optional|bool|string $idleSessions - * @param Optional|bool|string $localOps + * @param Optional|bool $allUsers + * @param Optional|bool $idleConnections + * @param Optional|bool $idleCursors + * @param Optional|bool $idleSessions + * @param Optional|bool $localOps */ public static function currentOp( - Optional|bool|string $allUsers = Optional::Undefined, - Optional|bool|string $idleConnections = Optional::Undefined, - Optional|bool|string $idleCursors = Optional::Undefined, - Optional|bool|string $idleSessions = Optional::Undefined, - Optional|bool|string $localOps = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, + Optional|bool $idleConnections = Optional::Undefined, + Optional|bool $idleCursors = Optional::Undefined, + Optional|bool $idleSessions = Optional::Undefined, + Optional|bool $localOps = Optional::Undefined, ): CurrentOpStage { return new CurrentOpStage($allUsers, $idleConnections, $idleCursors, $idleSessions, $localOps); } @@ -185,12 +185,12 @@ public static function currentOp( * Documents that do not contain the specified field continue through the pipeline unmodified. * To specify a in an embedded document or in an array, use dot notation. * @param Document|Serializable|array|stdClass $range Specification for range based densification. - * @param Optional|BSONArray|PackedArray|array|string $partitionByFields The field(s) that will be used as the partition keys. + * @param Optional|BSONArray|PackedArray|array $partitionByFields The field(s) that will be used as the partition keys. */ public static function densify( string $field, Document|Serializable|stdClass|array $range, - Optional|PackedArray|BSONArray|array|string $partitionByFields = Optional::Undefined, + Optional|PackedArray|BSONArray|array $partitionByFields = Optional::Undefined, ): DensifyStage { return new DensifyStage($field, $range, $partitionByFields); } @@ -225,20 +225,20 @@ public static function facet(PackedArray|Pipeline|BSONArray|array ...$facet): Fa * Populates null and missing field values within documents. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/ - * @param Document|Serializable|array|stdClass|string $output Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. + * @param Document|Serializable|array|stdClass $output Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. * The object name is the name of the field to fill. The object value specifies how the field is filled. * @param Optional|Document|Serializable|array|stdClass|string $partitionBy Specifies an expression to group the documents. In the $fill stage, a group of documents is known as a partition. * If you omit partitionBy and partitionByFields, $fill uses one partition for the entire collection. * partitionBy and partitionByFields are mutually exclusive. - * @param Optional|BSONArray|PackedArray|array|string $partitionByFields Specifies an array of fields as the compound key to group the documents. In the $fill stage, each group of documents is known as a partition. + * @param Optional|BSONArray|PackedArray|array $partitionByFields Specifies an array of fields as the compound key to group the documents. In the $fill stage, each group of documents is known as a partition. * If you omit partitionBy and partitionByFields, $fill uses one partition for the entire collection. * partitionBy and partitionByFields are mutually exclusive. * @param Optional|Document|Serializable|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ public static function fill( - Document|Serializable|stdClass|array|string $output, + Document|Serializable|stdClass|array $output, Optional|Document|Serializable|stdClass|array|string $partitionBy = Optional::Undefined, - Optional|PackedArray|BSONArray|array|string $partitionByFields = Optional::Undefined, + Optional|PackedArray|BSONArray|array $partitionByFields = Optional::Undefined, Optional|Document|Serializable|stdClass|array $sortBy = Optional::Undefined, ): FillStage { return new FillStage($output, $partitionBy, $partitionByFields, $sortBy); @@ -250,16 +250,16 @@ public static function fill( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/ * @param Document|ResolvesToObject|Serializable|array|stdClass|string $near The point for which to find the closest documents. * @param Optional|string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. - * @param Optional|Decimal128|Int64|float|int|string $distanceMultiplier The factor to multiply all distances returned by the query. For example, use the distanceMultiplier to convert radians, as returned by a spherical query, to kilometers by multiplying by the radius of the Earth. + * @param Optional|Decimal128|Int64|float|int $distanceMultiplier The factor to multiply all distances returned by the query. For example, use the distanceMultiplier to convert radians, as returned by a spherical query, to kilometers by multiplying by the radius of the Earth. * @param Optional|string $includeLocs This specifies the output field that identifies the location used to calculate the distance. This option is useful when a location field contains multiple locations. To specify a field within an embedded document, use dot notation. * @param Optional|string $key Specify the geospatial indexed field to use when calculating the distance. - * @param Optional|Decimal128|Int64|float|int|string $maxDistance The maximum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall within the specified distance from the center point. + * @param Optional|Decimal128|Int64|float|int $maxDistance The maximum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall within the specified distance from the center point. * Specify the distance in meters if the specified point is GeoJSON and in radians if the specified point is legacy coordinate pairs. - * @param Optional|Decimal128|Int64|float|int|string $minDistance The minimum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall outside the specified distance from the center point. + * @param Optional|Decimal128|Int64|float|int $minDistance The minimum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall outside the specified distance from the center point. * Specify the distance in meters for GeoJSON data and in radians for legacy coordinate pairs. * @param Optional|QueryInterface|array $query Limits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. * You cannot specify a $near predicate in the query field of the $geoNear stage. - * @param Optional|bool|string $spherical Determines how MongoDB calculates the distance between two points: + * @param Optional|bool $spherical Determines how MongoDB calculates the distance between two points: * - When true, MongoDB uses $nearSphere semantics and calculates distances using spherical geometry. * - When false, MongoDB uses $near semantics: spherical geometry for 2dsphere indexes and planar geometry for 2d indexes. * Default: false. @@ -267,13 +267,13 @@ public static function fill( public static function geoNear( Document|Serializable|ResolvesToObject|stdClass|array|string $near, Optional|string $distanceField = Optional::Undefined, - Optional|Decimal128|Int64|float|int|string $distanceMultiplier = Optional::Undefined, + Optional|Decimal128|Int64|float|int $distanceMultiplier = Optional::Undefined, Optional|string $includeLocs = Optional::Undefined, Optional|string $key = Optional::Undefined, - Optional|Decimal128|Int64|float|int|string $maxDistance = Optional::Undefined, - Optional|Decimal128|Int64|float|int|string $minDistance = Optional::Undefined, + Optional|Decimal128|Int64|float|int $maxDistance = Optional::Undefined, + Optional|Decimal128|Int64|float|int $minDistance = Optional::Undefined, Optional|QueryInterface|array $query = Optional::Undefined, - Optional|bool|string $spherical = Optional::Undefined, + Optional|bool $spherical = Optional::Undefined, ): GeoNearStage { return new GeoNearStage($near, $distanceField, $distanceMultiplier, $includeLocs, $key, $maxDistance, $minDistance, $query, $spherical); } @@ -288,7 +288,7 @@ public static function geoNear( * @param string $connectFromField Field name whose value $graphLookup uses to recursively match against the connectToField of other documents in the collection. If the value is an array, each element is individually followed through the traversal process. * @param string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. * @param string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. - * @param Optional|int|string $maxDepth Non-negative integral number specifying the maximum recursion depth. + * @param Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. * @param Optional|string $depthField Name of the field to add to each traversed document in the search path. The value of this field is the recursion depth for the document, represented as a NumberLong. Recursion depth value starts at zero, so the first lookup corresponds to zero depth. * @param Optional|QueryInterface|array $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ @@ -298,7 +298,7 @@ public static function graphLookup( string $connectFromField, string $connectToField, string $as, - Optional|int|string $maxDepth = Optional::Undefined, + Optional|int $maxDepth = Optional::Undefined, Optional|string $depthField = Optional::Undefined, Optional|QueryInterface|array $restrictSearchWithMatch = Optional::Undefined, ): GraphLookupStage { @@ -333,9 +333,9 @@ public static function indexStats(): IndexStatsStage * Passes the first n documents unmodified to the pipeline where n is the specified limit. For each input document, outputs either one document (for the first n documents) or zero documents (after the first n documents). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/ - * @param int|string $limit + * @param int $limit */ - public static function limit(int|string $limit): LimitStage + public static function limit(int $limit): LimitStage { return new LimitStage($limit); } @@ -344,12 +344,12 @@ public static function limit(int|string $limit): LimitStage * Lists all active sessions recently in use on the currently connected mongos or mongod instance. These sessions may have not yet propagated to the system.sessions collection. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/ - * @param Optional|BSONArray|PackedArray|array|string $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. - * @param Optional|bool|string $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + * @param Optional|BSONArray|PackedArray|array $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. + * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public static function listLocalSessions( - Optional|PackedArray|BSONArray|array|string $users = Optional::Undefined, - Optional|bool|string $allUsers = Optional::Undefined, + Optional|PackedArray|BSONArray|array $users = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, ): ListLocalSessionsStage { return new ListLocalSessionsStage($users, $allUsers); } @@ -384,12 +384,12 @@ public static function listSearchIndexes( * Lists all sessions that have been active long enough to propagate to the system.sessions collection. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/ - * @param Optional|BSONArray|PackedArray|array|string $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. - * @param Optional|bool|string $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + * @param Optional|BSONArray|PackedArray|array $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. + * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public static function listSessions( - Optional|PackedArray|BSONArray|array|string $users = Optional::Undefined, - Optional|bool|string $allUsers = Optional::Undefined, + Optional|PackedArray|BSONArray|array $users = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, ): ListSessionsStage { return new ListSessionsStage($users, $allUsers); } @@ -404,7 +404,7 @@ public static function listSessions( * Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded. * @param Optional|string $localField Specifies the field from the documents input to the $lookup stage. $lookup performs an equality match on the localField to the foreignField from the documents of the from collection. If an input document does not contain the localField, the $lookup treats the field as having a value of null for matching purposes. * @param Optional|string $foreignField Specifies the field from the documents in the from collection. $lookup performs an equality match on the foreignField to the localField from the input documents. If a document in the from collection does not contain the foreignField, the $lookup treats the value as null for matching purposes. - * @param Optional|Document|Serializable|array|stdClass|string $let Specifies variables to use in the pipeline stages. Use the variable expressions to access the fields from the joined collection's documents that are input to the pipeline. + * @param Optional|Document|Serializable|array|stdClass $let Specifies variables to use in the pipeline stages. Use the variable expressions to access the fields from the joined collection's documents that are input to the pipeline. * @param Optional|BSONArray|PackedArray|Pipeline|array $pipeline Specifies the pipeline to run on the joined collection. The pipeline determines the resulting documents from the joined collection. To return all documents, specify an empty pipeline []. * The pipeline cannot include the $out stage or the $merge stage. Starting in v6.0, the pipeline can contain the Atlas Search $search stage as the first stage inside the pipeline. * The pipeline cannot directly access the joined document fields. Instead, define variables for the joined document fields using the let option and then reference the variables in the pipeline stages. @@ -414,7 +414,7 @@ public static function lookup( Optional|string $from = Optional::Undefined, Optional|string $localField = Optional::Undefined, Optional|string $foreignField = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $let = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $let = Optional::Undefined, Optional|PackedArray|Pipeline|BSONArray|array $pipeline = Optional::Undefined, ): LookupStage { return new LookupStage($as, $from, $localField, $foreignField, $let, $pipeline); @@ -438,14 +438,14 @@ public static function match(QueryInterface|array $query): MatchStage * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/ * @param Document|Serializable|array|stdClass|string $into The output collection. * @param Optional|BSONArray|PackedArray|array|string $on Field or fields that act as a unique identifier for a document. The identifier determines if a results document matches an existing document in the output collection. - * @param Optional|Document|Serializable|array|stdClass|string $let Specifies variables for use in the whenMatched pipeline. + * @param Optional|Document|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. * @param Optional|BSONArray|PackedArray|Pipeline|array|string $whenMatched The behavior of $merge if a result document and an existing document in the collection have the same value for the specified on field(s). * @param Optional|string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. */ public static function merge( Document|Serializable|stdClass|array|string $into, Optional|PackedArray|BSONArray|array|string $on = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $let = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $let = Optional::Undefined, Optional|PackedArray|Pipeline|BSONArray|array|string $whenMatched = Optional::Undefined, Optional|string $whenNotMatched = Optional::Undefined, ): MergeStage { @@ -526,9 +526,9 @@ public static function replaceWith( * Randomly selects the specified number of documents from its input. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/ - * @param int|string $size The number of documents to randomly select. + * @param int $size The number of documents to randomly select. */ - public static function sample(int|string $size): SampleStage + public static function sample(int $size): SampleStage { return new SampleStage($size); } @@ -541,30 +541,30 @@ public static function sample(int|string $size): SampleStage * @param Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use * the compound operator to run a compound query with multiple operators. * @param Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to "default". - * @param Optional|Document|Serializable|array|stdClass|string $highlight Specifies the highlighting options for displaying search terms in their original context. - * @param Optional|bool|string $concurrent Parallelize search across segments on dedicated search nodes. + * @param Optional|Document|Serializable|array|stdClass $highlight Specifies the highlighting options for displaying search terms in their original context. + * @param Optional|bool $concurrent Parallelize search across segments on dedicated search nodes. * If you don't have separate search nodes on your cluster, * Atlas Search ignores this flag. If omitted, defaults to false. - * @param Optional|Document|Serializable|array|stdClass|string $count Document that specifies the count options for retrieving a count of the results. + * @param Optional|Document|Serializable|array|stdClass $count Document that specifies the count options for retrieving a count of the results. * @param Optional|string $searchAfter Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point. * @param Optional|string $searchBefore Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point. - * @param Optional|bool|string $scoreDetails Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false. - * @param Optional|Document|Serializable|array|stdClass|string $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order. - * @param Optional|bool|string $returnStoredSource Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search. - * @param Optional|Document|Serializable|array|stdClass|string $tracking Document that specifies the tracking option to retrieve analytics information on the search terms. + * @param Optional|bool $scoreDetails Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false. + * @param Optional|Document|Serializable|array|stdClass $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order. + * @param Optional|bool $returnStoredSource Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search. + * @param Optional|Document|Serializable|array|stdClass $tracking Document that specifies the tracking option to retrieve analytics information on the search terms. */ public static function search( Document|Serializable|SearchOperatorInterface|stdClass|array $operator, Optional|string $index = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $highlight = Optional::Undefined, - Optional|bool|string $concurrent = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $count = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $highlight = Optional::Undefined, + Optional|bool $concurrent = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $count = Optional::Undefined, Optional|string $searchAfter = Optional::Undefined, Optional|string $searchBefore = Optional::Undefined, - Optional|bool|string $scoreDetails = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $sort = Optional::Undefined, - Optional|bool|string $returnStoredSource = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $tracking = Optional::Undefined, + Optional|bool $scoreDetails = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $sort = Optional::Undefined, + Optional|bool $returnStoredSource = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $tracking = Optional::Undefined, ): SearchStage { return new SearchStage($operator, $index, $highlight, $concurrent, $count, $searchAfter, $searchBefore, $scoreDetails, $sort, $returnStoredSource, $tracking); } @@ -577,12 +577,12 @@ public static function search( * @param Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use * the compound operator to run a compound query with multiple operators. * @param Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to default. - * @param Optional|Document|Serializable|array|stdClass|string $count Document that specifies the count options for retrieving a count of the results. + * @param Optional|Document|Serializable|array|stdClass $count Document that specifies the count options for retrieving a count of the results. */ public static function searchMeta( Document|Serializable|SearchOperatorInterface|stdClass|array $operator, Optional|string $index = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $count = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $count = Optional::Undefined, ): SearchMetaStage { return new SearchMetaStage($operator, $index, $count); } @@ -605,13 +605,13 @@ public static function set(Type|ExpressionInterface|stdClass|array|bool|float|in * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/ * @param Document|Serializable|array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. - * @param Document|Serializable|array|stdClass|string $output Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. + * @param Document|Serializable|array|stdClass $output Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. * A field can contain dots to specify embedded document fields and array fields. The semantics for the embedded document dotted notation in the $setWindowFields stage are the same as the $addFields and $set stages. * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $partitionBy Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. */ public static function setWindowFields( Document|Serializable|stdClass|array $sortBy, - Document|Serializable|stdClass|array|string $output, + Document|Serializable|stdClass|array $output, Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $partitionBy = Optional::Undefined, ): SetWindowFieldsStage { return new SetWindowFieldsStage($sortBy, $output, $partitionBy); @@ -632,9 +632,9 @@ public static function shardedDataDistribution(): ShardedDataDistributionStage * Skips the first n documents where n is the specified skip number and passes the remaining documents unmodified to the pipeline. For each input document, outputs either zero documents (for the first n documents) or one document (if after the first n documents). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/ - * @param int|string $skip + * @param int $skip */ - public static function skip(int|string $skip): SkipStage + public static function skip(int $skip): SkipStage { return new SkipStage($skip); } @@ -698,14 +698,14 @@ public static function unset(FieldPath|string ...$field): UnsetStage * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/ * @param ArrayFieldPath|string $path Field path to an array field. * @param Optional|string $includeArrayIndex The name of a new field to hold the array index of the element. The name cannot start with a dollar sign $. - * @param Optional|bool|string $preserveNullAndEmptyArrays If true, if the path is null, missing, or an empty array, $unwind outputs the document. + * @param Optional|bool $preserveNullAndEmptyArrays If true, if the path is null, missing, or an empty array, $unwind outputs the document. * If false, if path is null, missing, or an empty array, $unwind does not output a document. * The default value is false. */ public static function unwind( ArrayFieldPath|string $path, Optional|string $includeArrayIndex = Optional::Undefined, - Optional|bool|string $preserveNullAndEmptyArrays = Optional::Undefined, + Optional|bool $preserveNullAndEmptyArrays = Optional::Undefined, ): UnwindStage { return new UnwindStage($path, $includeArrayIndex, $preserveNullAndEmptyArrays); } @@ -715,22 +715,22 @@ public static function unwind( * * @see https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/ * @param string $index Name of the Atlas Vector Search index to use. - * @param int|string $limit Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates. + * @param int $limit Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates. * @param array|string $path Indexed vector type field to search. - * @param BSONArray|PackedArray|array|string $queryVector Array of numbers that represent the query vector. The number type must match the indexed field value type. - * @param Optional|bool|string $exact This is required if numCandidates is omitted. false to run ANN search. true to run ENN search. + * @param BSONArray|PackedArray|array $queryVector Array of numbers that represent the query vector. The number type must match the indexed field value type. + * @param Optional|bool $exact This is required if numCandidates is omitted. false to run ANN search. true to run ENN search. * @param Optional|QueryInterface|array $filter Any match query that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter. - * @param Optional|int|string $numCandidates This field is required if exact is false or omitted. + * @param Optional|int $numCandidates This field is required if exact is false or omitted. * Number of nearest neighbors to use during the search. Value must be less than or equal to (<=) 10000. You can't specify a number less than the number of documents to return (limit). */ public static function vectorSearch( string $index, - int|string $limit, + int $limit, array|string $path, - PackedArray|BSONArray|array|string $queryVector, - Optional|bool|string $exact = Optional::Undefined, + PackedArray|BSONArray|array $queryVector, + Optional|bool $exact = Optional::Undefined, Optional|QueryInterface|array $filter = Optional::Undefined, - Optional|int|string $numCandidates = Optional::Undefined, + Optional|int $numCandidates = Optional::Undefined, ): VectorSearchStage { return new VectorSearchStage($index, $limit, $path, $queryVector, $exact, $filter, $numCandidates); } diff --git a/src/Builder/Stage/FillStage.php b/src/Builder/Stage/FillStage.php index a6bda8137..f7b3b35e2 100644 --- a/src/Builder/Stage/FillStage.php +++ b/src/Builder/Stage/FillStage.php @@ -41,10 +41,10 @@ final class FillStage implements StageInterface, OperatorInterface ]; /** - * @var Document|Serializable|array|stdClass|string $output Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. + * @var Document|Serializable|array|stdClass $output Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. * The object name is the name of the field to fill. The object value specifies how the field is filled. */ - public readonly Document|Serializable|stdClass|array|string $output; + public readonly Document|Serializable|stdClass|array $output; /** * @var Optional|Document|Serializable|array|stdClass|string $partitionBy Specifies an expression to group the documents. In the $fill stage, a group of documents is known as a partition. @@ -54,30 +54,30 @@ final class FillStage implements StageInterface, OperatorInterface public readonly Optional|Document|Serializable|stdClass|array|string $partitionBy; /** - * @var Optional|BSONArray|PackedArray|array|string $partitionByFields Specifies an array of fields as the compound key to group the documents. In the $fill stage, each group of documents is known as a partition. + * @var Optional|BSONArray|PackedArray|array $partitionByFields Specifies an array of fields as the compound key to group the documents. In the $fill stage, each group of documents is known as a partition. * If you omit partitionBy and partitionByFields, $fill uses one partition for the entire collection. * partitionBy and partitionByFields are mutually exclusive. */ - public readonly Optional|PackedArray|BSONArray|array|string $partitionByFields; + public readonly Optional|PackedArray|BSONArray|array $partitionByFields; /** @var Optional|Document|Serializable|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ public readonly Optional|Document|Serializable|stdClass|array $sortBy; /** - * @param Document|Serializable|array|stdClass|string $output Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. + * @param Document|Serializable|array|stdClass $output Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. * The object name is the name of the field to fill. The object value specifies how the field is filled. * @param Optional|Document|Serializable|array|stdClass|string $partitionBy Specifies an expression to group the documents. In the $fill stage, a group of documents is known as a partition. * If you omit partitionBy and partitionByFields, $fill uses one partition for the entire collection. * partitionBy and partitionByFields are mutually exclusive. - * @param Optional|BSONArray|PackedArray|array|string $partitionByFields Specifies an array of fields as the compound key to group the documents. In the $fill stage, each group of documents is known as a partition. + * @param Optional|BSONArray|PackedArray|array $partitionByFields Specifies an array of fields as the compound key to group the documents. In the $fill stage, each group of documents is known as a partition. * If you omit partitionBy and partitionByFields, $fill uses one partition for the entire collection. * partitionBy and partitionByFields are mutually exclusive. * @param Optional|Document|Serializable|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ public function __construct( - Document|Serializable|stdClass|array|string $output, + Document|Serializable|stdClass|array $output, Optional|Document|Serializable|stdClass|array|string $partitionBy = Optional::Undefined, - Optional|PackedArray|BSONArray|array|string $partitionByFields = Optional::Undefined, + Optional|PackedArray|BSONArray|array $partitionByFields = Optional::Undefined, Optional|Document|Serializable|stdClass|array $sortBy = Optional::Undefined, ) { $this->output = $output; diff --git a/src/Builder/Stage/FluentFactoryTrait.php b/src/Builder/Stage/FluentFactoryTrait.php index 8230fee37..64fdc6b3c 100644 --- a/src/Builder/Stage/FluentFactoryTrait.php +++ b/src/Builder/Stage/FluentFactoryTrait.php @@ -77,21 +77,21 @@ public function addFields( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/ * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * Unless $bucket includes a default specification, each input document must resolve the groupBy field path or expression to a value that falls within one of the ranges specified by the boundaries. - * @param BSONArray|PackedArray|array|string $boundaries An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. + * @param BSONArray|PackedArray|array $boundaries An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. * The specified values must be in ascending order and all of the same type. The exception is if the values are of mixed numeric types, such as: * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $default A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. * If unspecified, each input document must resolve the groupBy expression to a value within one of the bucket ranges specified by boundaries or the operation throws an error. * The default value must be less than the lowest boundaries value, or greater than or equal to the highest boundaries value. * The default value can be of a different type than the entries in boundaries. - * @param Optional|Document|Serializable|array|stdClass|string $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. + * @param Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * If you do not specify an output document, the operation returns a count field containing the number of documents in each bucket. * If you specify an output document, only the fields specified in the document are returned; i.e. the count field is not returned unless it is explicitly included in the output document. */ public function bucket( Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $groupBy, - PackedArray|BSONArray|array|string $boundaries, + PackedArray|BSONArray|array $boundaries, Optional|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $default = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $output = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, ): static { $this->pipeline[] = Stage::bucket($groupBy, $boundaries, $default, $output); @@ -103,16 +103,16 @@ public function bucket( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/ * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. - * @param int|string $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. - * @param Optional|Document|Serializable|array|stdClass|string $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. + * @param int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. + * @param Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * The default count field is not included in the output document when output is specified. Explicitly specify the count expression as part of the output document to include it. * @param Optional|string $granularity A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. * Available only if the all groupBy values are numeric and none of them are NaN. */ public function bucketAuto( Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $groupBy, - string|int $buckets, - Optional|Document|Serializable|stdClass|array|string $output = Optional::Undefined, + int $buckets, + Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, Optional|string $granularity = Optional::Undefined, ): static { $this->pipeline[] = Stage::bucketAuto($groupBy, $buckets, $output, $granularity); @@ -124,23 +124,23 @@ public function bucketAuto( * Returns a Change Stream cursor for the collection or database. This stage can only occur once in an aggregation pipeline and it must occur as the first stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/ - * @param Optional|bool|string $allChangesForCluster A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. + * @param Optional|bool $allChangesForCluster A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. * @param Optional|string $fullDocument Specifies whether change notifications include a copy of the full document when modified by update operations. * @param Optional|string $fullDocumentBeforeChange Valid values are "off", "whenAvailable", or "required". If set to "off", the "fullDocumentBeforeChange" field of the output document is always omitted. If set to "whenAvailable", the "fullDocumentBeforeChange" field will be populated with the pre-image of the document modified by the current change event if such a pre-image is available, and will be omitted otherwise. If set to "required", then the "fullDocumentBeforeChange" field is always populated and an exception is thrown if the pre-image is not available. - * @param Optional|int|string $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. - * @param Optional|bool|string $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. + * @param Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. + * @param Optional|bool $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. * New in MongoDB 6.0. - * @param Optional|Document|Serializable|array|stdClass|string $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. - * @param Optional|Timestamp|int|string $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. + * @param Optional|Document|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. + * @param Optional|Timestamp|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ public function changeStream( - Optional|string|bool $allChangesForCluster = Optional::Undefined, + Optional|bool $allChangesForCluster = Optional::Undefined, Optional|string $fullDocument = Optional::Undefined, Optional|string $fullDocumentBeforeChange = Optional::Undefined, - Optional|string|int $resumeAfter = Optional::Undefined, - Optional|string|bool $showExpandedEvents = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $startAfter = Optional::Undefined, - Optional|Timestamp|string|int $startAtOperationTime = Optional::Undefined, + Optional|int $resumeAfter = Optional::Undefined, + Optional|bool $showExpandedEvents = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $startAfter = Optional::Undefined, + Optional|Timestamp|int $startAtOperationTime = Optional::Undefined, ): static { $this->pipeline[] = Stage::changeStream($allChangesForCluster, $fullDocument, $fullDocumentBeforeChange, $resumeAfter, $showExpandedEvents, $startAfter, $startAtOperationTime); @@ -164,16 +164,16 @@ public function changeStreamSplitLargeEvent(): static * Returns statistics regarding a collection or view. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/ - * @param Optional|Document|Serializable|array|stdClass|string $latencyStats - * @param Optional|Document|Serializable|array|stdClass|string $storageStats - * @param Optional|Document|Serializable|array|stdClass|string $count - * @param Optional|Document|Serializable|array|stdClass|string $queryExecStats + * @param Optional|Document|Serializable|array|stdClass $latencyStats + * @param Optional|Document|Serializable|array|stdClass $storageStats + * @param Optional|Document|Serializable|array|stdClass $count + * @param Optional|Document|Serializable|array|stdClass $queryExecStats */ public function collStats( - Optional|Document|Serializable|stdClass|array|string $latencyStats = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $storageStats = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $count = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $queryExecStats = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $latencyStats = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $storageStats = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $count = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $queryExecStats = Optional::Undefined, ): static { $this->pipeline[] = Stage::collStats($latencyStats, $storageStats, $count, $queryExecStats); @@ -198,18 +198,18 @@ public function count(string $field): static * Returns information on active and/or dormant operations for the MongoDB deployment. To run, use the db.aggregate() method. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/ - * @param Optional|bool|string $allUsers - * @param Optional|bool|string $idleConnections - * @param Optional|bool|string $idleCursors - * @param Optional|bool|string $idleSessions - * @param Optional|bool|string $localOps + * @param Optional|bool $allUsers + * @param Optional|bool $idleConnections + * @param Optional|bool $idleCursors + * @param Optional|bool $idleSessions + * @param Optional|bool $localOps */ public function currentOp( - Optional|string|bool $allUsers = Optional::Undefined, - Optional|string|bool $idleConnections = Optional::Undefined, - Optional|string|bool $idleCursors = Optional::Undefined, - Optional|string|bool $idleSessions = Optional::Undefined, - Optional|string|bool $localOps = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, + Optional|bool $idleConnections = Optional::Undefined, + Optional|bool $idleCursors = Optional::Undefined, + Optional|bool $idleSessions = Optional::Undefined, + Optional|bool $localOps = Optional::Undefined, ): static { $this->pipeline[] = Stage::currentOp($allUsers, $idleConnections, $idleCursors, $idleSessions, $localOps); @@ -224,12 +224,12 @@ public function currentOp( * Documents that do not contain the specified field continue through the pipeline unmodified. * To specify a in an embedded document or in an array, use dot notation. * @param Document|Serializable|array|stdClass $range Specification for range based densification. - * @param Optional|BSONArray|PackedArray|array|string $partitionByFields The field(s) that will be used as the partition keys. + * @param Optional|BSONArray|PackedArray|array $partitionByFields The field(s) that will be used as the partition keys. */ public function densify( string $field, Document|Serializable|stdClass|array $range, - Optional|PackedArray|BSONArray|array|string $partitionByFields = Optional::Undefined, + Optional|PackedArray|BSONArray|array $partitionByFields = Optional::Undefined, ): static { $this->pipeline[] = Stage::densify($field, $range, $partitionByFields); @@ -270,20 +270,20 @@ public function facet(PackedArray|Pipeline|BSONArray|array ...$facet): static * Populates null and missing field values within documents. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/ - * @param Document|Serializable|array|stdClass|string $output Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. + * @param Document|Serializable|array|stdClass $output Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. * The object name is the name of the field to fill. The object value specifies how the field is filled. * @param Optional|Document|Serializable|array|stdClass|string $partitionBy Specifies an expression to group the documents. In the $fill stage, a group of documents is known as a partition. * If you omit partitionBy and partitionByFields, $fill uses one partition for the entire collection. * partitionBy and partitionByFields are mutually exclusive. - * @param Optional|BSONArray|PackedArray|array|string $partitionByFields Specifies an array of fields as the compound key to group the documents. In the $fill stage, each group of documents is known as a partition. + * @param Optional|BSONArray|PackedArray|array $partitionByFields Specifies an array of fields as the compound key to group the documents. In the $fill stage, each group of documents is known as a partition. * If you omit partitionBy and partitionByFields, $fill uses one partition for the entire collection. * partitionBy and partitionByFields are mutually exclusive. * @param Optional|Document|Serializable|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ public function fill( - Document|Serializable|stdClass|array|string $output, + Document|Serializable|stdClass|array $output, Optional|Document|Serializable|stdClass|array|string $partitionBy = Optional::Undefined, - Optional|PackedArray|BSONArray|array|string $partitionByFields = Optional::Undefined, + Optional|PackedArray|BSONArray|array $partitionByFields = Optional::Undefined, Optional|Document|Serializable|stdClass|array $sortBy = Optional::Undefined, ): static { $this->pipeline[] = Stage::fill($output, $partitionBy, $partitionByFields, $sortBy); @@ -297,16 +297,16 @@ public function fill( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/ * @param Document|ResolvesToObject|Serializable|array|stdClass|string $near The point for which to find the closest documents. * @param Optional|string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. - * @param Optional|Decimal128|Int64|float|int|string $distanceMultiplier The factor to multiply all distances returned by the query. For example, use the distanceMultiplier to convert radians, as returned by a spherical query, to kilometers by multiplying by the radius of the Earth. + * @param Optional|Decimal128|Int64|float|int $distanceMultiplier The factor to multiply all distances returned by the query. For example, use the distanceMultiplier to convert radians, as returned by a spherical query, to kilometers by multiplying by the radius of the Earth. * @param Optional|string $includeLocs This specifies the output field that identifies the location used to calculate the distance. This option is useful when a location field contains multiple locations. To specify a field within an embedded document, use dot notation. * @param Optional|string $key Specify the geospatial indexed field to use when calculating the distance. - * @param Optional|Decimal128|Int64|float|int|string $maxDistance The maximum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall within the specified distance from the center point. + * @param Optional|Decimal128|Int64|float|int $maxDistance The maximum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall within the specified distance from the center point. * Specify the distance in meters if the specified point is GeoJSON and in radians if the specified point is legacy coordinate pairs. - * @param Optional|Decimal128|Int64|float|int|string $minDistance The minimum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall outside the specified distance from the center point. + * @param Optional|Decimal128|Int64|float|int $minDistance The minimum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall outside the specified distance from the center point. * Specify the distance in meters for GeoJSON data and in radians for legacy coordinate pairs. * @param Optional|QueryInterface|array $query Limits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. * You cannot specify a $near predicate in the query field of the $geoNear stage. - * @param Optional|bool|string $spherical Determines how MongoDB calculates the distance between two points: + * @param Optional|bool $spherical Determines how MongoDB calculates the distance between two points: * - When true, MongoDB uses $nearSphere semantics and calculates distances using spherical geometry. * - When false, MongoDB uses $near semantics: spherical geometry for 2dsphere indexes and planar geometry for 2d indexes. * Default: false. @@ -314,13 +314,13 @@ public function fill( public function geoNear( Document|Serializable|ResolvesToObject|stdClass|array|string $near, Optional|string $distanceField = Optional::Undefined, - Optional|Decimal128|Int64|string|int|float $distanceMultiplier = Optional::Undefined, + Optional|Decimal128|Int64|int|float $distanceMultiplier = Optional::Undefined, Optional|string $includeLocs = Optional::Undefined, Optional|string $key = Optional::Undefined, - Optional|Decimal128|Int64|string|int|float $maxDistance = Optional::Undefined, - Optional|Decimal128|Int64|string|int|float $minDistance = Optional::Undefined, + Optional|Decimal128|Int64|int|float $maxDistance = Optional::Undefined, + Optional|Decimal128|Int64|int|float $minDistance = Optional::Undefined, Optional|QueryInterface|array $query = Optional::Undefined, - Optional|string|bool $spherical = Optional::Undefined, + Optional|bool $spherical = Optional::Undefined, ): static { $this->pipeline[] = Stage::geoNear($near, $distanceField, $distanceMultiplier, $includeLocs, $key, $maxDistance, $minDistance, $query, $spherical); @@ -337,7 +337,7 @@ public function geoNear( * @param string $connectFromField Field name whose value $graphLookup uses to recursively match against the connectToField of other documents in the collection. If the value is an array, each element is individually followed through the traversal process. * @param string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. * @param string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. - * @param Optional|int|string $maxDepth Non-negative integral number specifying the maximum recursion depth. + * @param Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. * @param Optional|string $depthField Name of the field to add to each traversed document in the search path. The value of this field is the recursion depth for the document, represented as a NumberLong. Recursion depth value starts at zero, so the first lookup corresponds to zero depth. * @param Optional|QueryInterface|array $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ @@ -347,7 +347,7 @@ public function graphLookup( string $connectFromField, string $connectToField, string $as, - Optional|string|int $maxDepth = Optional::Undefined, + Optional|int $maxDepth = Optional::Undefined, Optional|string $depthField = Optional::Undefined, Optional|QueryInterface|array $restrictSearchWithMatch = Optional::Undefined, ): static { @@ -388,9 +388,9 @@ public function indexStats(): static * Passes the first n documents unmodified to the pipeline where n is the specified limit. For each input document, outputs either one document (for the first n documents) or zero documents (after the first n documents). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/ - * @param int|string $limit + * @param int $limit */ - public function limit(string|int $limit): static + public function limit(int $limit): static { $this->pipeline[] = Stage::limit($limit); @@ -401,12 +401,12 @@ public function limit(string|int $limit): static * Lists all active sessions recently in use on the currently connected mongos or mongod instance. These sessions may have not yet propagated to the system.sessions collection. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/ - * @param Optional|BSONArray|PackedArray|array|string $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. - * @param Optional|bool|string $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + * @param Optional|BSONArray|PackedArray|array $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. + * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public function listLocalSessions( - Optional|PackedArray|BSONArray|array|string $users = Optional::Undefined, - Optional|string|bool $allUsers = Optional::Undefined, + Optional|PackedArray|BSONArray|array $users = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, ): static { $this->pipeline[] = Stage::listLocalSessions($users, $allUsers); @@ -446,12 +446,12 @@ public function listSearchIndexes( * Lists all sessions that have been active long enough to propagate to the system.sessions collection. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/ - * @param Optional|BSONArray|PackedArray|array|string $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. - * @param Optional|bool|string $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + * @param Optional|BSONArray|PackedArray|array $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. + * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public function listSessions( - Optional|PackedArray|BSONArray|array|string $users = Optional::Undefined, - Optional|string|bool $allUsers = Optional::Undefined, + Optional|PackedArray|BSONArray|array $users = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, ): static { $this->pipeline[] = Stage::listSessions($users, $allUsers); @@ -468,7 +468,7 @@ public function listSessions( * Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded. * @param Optional|string $localField Specifies the field from the documents input to the $lookup stage. $lookup performs an equality match on the localField to the foreignField from the documents of the from collection. If an input document does not contain the localField, the $lookup treats the field as having a value of null for matching purposes. * @param Optional|string $foreignField Specifies the field from the documents in the from collection. $lookup performs an equality match on the foreignField to the localField from the input documents. If a document in the from collection does not contain the foreignField, the $lookup treats the value as null for matching purposes. - * @param Optional|Document|Serializable|array|stdClass|string $let Specifies variables to use in the pipeline stages. Use the variable expressions to access the fields from the joined collection's documents that are input to the pipeline. + * @param Optional|Document|Serializable|array|stdClass $let Specifies variables to use in the pipeline stages. Use the variable expressions to access the fields from the joined collection's documents that are input to the pipeline. * @param Optional|BSONArray|PackedArray|Pipeline|array $pipeline Specifies the pipeline to run on the joined collection. The pipeline determines the resulting documents from the joined collection. To return all documents, specify an empty pipeline []. * The pipeline cannot include the $out stage or the $merge stage. Starting in v6.0, the pipeline can contain the Atlas Search $search stage as the first stage inside the pipeline. * The pipeline cannot directly access the joined document fields. Instead, define variables for the joined document fields using the let option and then reference the variables in the pipeline stages. @@ -478,7 +478,7 @@ public function lookup( Optional|string $from = Optional::Undefined, Optional|string $localField = Optional::Undefined, Optional|string $foreignField = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $let = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $let = Optional::Undefined, Optional|PackedArray|Pipeline|BSONArray|array $pipeline = Optional::Undefined, ): static { $this->pipeline[] = Stage::lookup($as, $from, $localField, $foreignField, $let, $pipeline); @@ -493,14 +493,14 @@ public function lookup( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/ * @param Document|Serializable|array|stdClass|string $into The output collection. * @param Optional|BSONArray|PackedArray|array|string $on Field or fields that act as a unique identifier for a document. The identifier determines if a results document matches an existing document in the output collection. - * @param Optional|Document|Serializable|array|stdClass|string $let Specifies variables for use in the whenMatched pipeline. + * @param Optional|Document|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. * @param Optional|BSONArray|PackedArray|Pipeline|array|string $whenMatched The behavior of $merge if a result document and an existing document in the collection have the same value for the specified on field(s). * @param Optional|string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. */ public function merge( Document|Serializable|stdClass|array|string $into, Optional|PackedArray|BSONArray|array|string $on = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $let = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $let = Optional::Undefined, Optional|PackedArray|Pipeline|BSONArray|array|string $whenMatched = Optional::Undefined, Optional|string $whenNotMatched = Optional::Undefined, ): static { @@ -592,9 +592,9 @@ public function replaceWith(Document|Serializable|ResolvesToObject|stdClass|arra * Randomly selects the specified number of documents from its input. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/ - * @param int|string $size The number of documents to randomly select. + * @param int $size The number of documents to randomly select. */ - public function sample(string|int $size): static + public function sample(int $size): static { $this->pipeline[] = Stage::sample($size); @@ -609,30 +609,30 @@ public function sample(string|int $size): static * @param Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use * the compound operator to run a compound query with multiple operators. * @param Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to "default". - * @param Optional|Document|Serializable|array|stdClass|string $highlight Specifies the highlighting options for displaying search terms in their original context. - * @param Optional|bool|string $concurrent Parallelize search across segments on dedicated search nodes. + * @param Optional|Document|Serializable|array|stdClass $highlight Specifies the highlighting options for displaying search terms in their original context. + * @param Optional|bool $concurrent Parallelize search across segments on dedicated search nodes. * If you don't have separate search nodes on your cluster, * Atlas Search ignores this flag. If omitted, defaults to false. - * @param Optional|Document|Serializable|array|stdClass|string $count Document that specifies the count options for retrieving a count of the results. + * @param Optional|Document|Serializable|array|stdClass $count Document that specifies the count options for retrieving a count of the results. * @param Optional|string $searchAfter Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point. * @param Optional|string $searchBefore Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point. - * @param Optional|bool|string $scoreDetails Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false. - * @param Optional|Document|Serializable|array|stdClass|string $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order. - * @param Optional|bool|string $returnStoredSource Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search. - * @param Optional|Document|Serializable|array|stdClass|string $tracking Document that specifies the tracking option to retrieve analytics information on the search terms. + * @param Optional|bool $scoreDetails Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false. + * @param Optional|Document|Serializable|array|stdClass $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order. + * @param Optional|bool $returnStoredSource Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search. + * @param Optional|Document|Serializable|array|stdClass $tracking Document that specifies the tracking option to retrieve analytics information on the search terms. */ public function search( Document|Serializable|SearchOperatorInterface|stdClass|array $operator, Optional|string $index = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $highlight = Optional::Undefined, - Optional|string|bool $concurrent = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $count = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $highlight = Optional::Undefined, + Optional|bool $concurrent = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $count = Optional::Undefined, Optional|string $searchAfter = Optional::Undefined, Optional|string $searchBefore = Optional::Undefined, - Optional|string|bool $scoreDetails = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $sort = Optional::Undefined, - Optional|string|bool $returnStoredSource = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $tracking = Optional::Undefined, + Optional|bool $scoreDetails = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $sort = Optional::Undefined, + Optional|bool $returnStoredSource = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $tracking = Optional::Undefined, ): static { $this->pipeline[] = Stage::search($operator, $index, $highlight, $concurrent, $count, $searchAfter, $searchBefore, $scoreDetails, $sort, $returnStoredSource, $tracking); @@ -647,12 +647,12 @@ public function search( * @param Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use * the compound operator to run a compound query with multiple operators. * @param Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to default. - * @param Optional|Document|Serializable|array|stdClass|string $count Document that specifies the count options for retrieving a count of the results. + * @param Optional|Document|Serializable|array|stdClass $count Document that specifies the count options for retrieving a count of the results. */ public function searchMeta( Document|Serializable|SearchOperatorInterface|stdClass|array $operator, Optional|string $index = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $count = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $count = Optional::Undefined, ): static { $this->pipeline[] = Stage::searchMeta($operator, $index, $count); @@ -679,13 +679,13 @@ public function set(Type|ExpressionInterface|stdClass|array|string|int|float|boo * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/ * @param Document|Serializable|array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. - * @param Document|Serializable|array|stdClass|string $output Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. + * @param Document|Serializable|array|stdClass $output Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. * A field can contain dots to specify embedded document fields and array fields. The semantics for the embedded document dotted notation in the $setWindowFields stage are the same as the $addFields and $set stages. * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $partitionBy Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. */ public function setWindowFields( Document|Serializable|stdClass|array $sortBy, - Document|Serializable|stdClass|array|string $output, + Document|Serializable|stdClass|array $output, Optional|Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $partitionBy = Optional::Undefined, ): static { $this->pipeline[] = Stage::setWindowFields($sortBy, $output, $partitionBy); @@ -710,9 +710,9 @@ public function shardedDataDistribution(): static * Skips the first n documents where n is the specified skip number and passes the remaining documents unmodified to the pipeline. For each input document, outputs either zero documents (for the first n documents) or one document (if after the first n documents). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/ - * @param int|string $skip + * @param int $skip */ - public function skip(string|int $skip): static + public function skip(int $skip): static { $this->pipeline[] = Stage::skip($skip); @@ -785,14 +785,14 @@ public function unset(FieldPath|string ...$field): static * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/ * @param ArrayFieldPath|string $path Field path to an array field. * @param Optional|string $includeArrayIndex The name of a new field to hold the array index of the element. The name cannot start with a dollar sign $. - * @param Optional|bool|string $preserveNullAndEmptyArrays If true, if the path is null, missing, or an empty array, $unwind outputs the document. + * @param Optional|bool $preserveNullAndEmptyArrays If true, if the path is null, missing, or an empty array, $unwind outputs the document. * If false, if path is null, missing, or an empty array, $unwind does not output a document. * The default value is false. */ public function unwind( ArrayFieldPath|string $path, Optional|string $includeArrayIndex = Optional::Undefined, - Optional|string|bool $preserveNullAndEmptyArrays = Optional::Undefined, + Optional|bool $preserveNullAndEmptyArrays = Optional::Undefined, ): static { $this->pipeline[] = Stage::unwind($path, $includeArrayIndex, $preserveNullAndEmptyArrays); @@ -804,22 +804,22 @@ public function unwind( * * @see https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/ * @param string $index Name of the Atlas Vector Search index to use. - * @param int|string $limit Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates. + * @param int $limit Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates. * @param array|string $path Indexed vector type field to search. - * @param BSONArray|PackedArray|array|string $queryVector Array of numbers that represent the query vector. The number type must match the indexed field value type. - * @param Optional|bool|string $exact This is required if numCandidates is omitted. false to run ANN search. true to run ENN search. + * @param BSONArray|PackedArray|array $queryVector Array of numbers that represent the query vector. The number type must match the indexed field value type. + * @param Optional|bool $exact This is required if numCandidates is omitted. false to run ANN search. true to run ENN search. * @param Optional|QueryInterface|array $filter Any match query that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter. - * @param Optional|int|string $numCandidates This field is required if exact is false or omitted. + * @param Optional|int $numCandidates This field is required if exact is false or omitted. * Number of nearest neighbors to use during the search. Value must be less than or equal to (<=) 10000. You can't specify a number less than the number of documents to return (limit). */ public function vectorSearch( string $index, - string|int $limit, + int $limit, array|string $path, - PackedArray|BSONArray|array|string $queryVector, - Optional|string|bool $exact = Optional::Undefined, + PackedArray|BSONArray|array $queryVector, + Optional|bool $exact = Optional::Undefined, Optional|QueryInterface|array $filter = Optional::Undefined, - Optional|string|int $numCandidates = Optional::Undefined, + Optional|int $numCandidates = Optional::Undefined, ): static { $this->pipeline[] = Stage::vectorSearch($index, $limit, $path, $queryVector, $exact, $filter, $numCandidates); diff --git a/src/Builder/Stage/GeoNearStage.php b/src/Builder/Stage/GeoNearStage.php index 77fe1a306..21600a5b8 100644 --- a/src/Builder/Stage/GeoNearStage.php +++ b/src/Builder/Stage/GeoNearStage.php @@ -19,9 +19,12 @@ use MongoDB\Builder\Type\QueryInterface; use MongoDB\Builder\Type\QueryObject; use MongoDB\Builder\Type\StageInterface; +use MongoDB\Exception\InvalidArgumentException; use stdClass; use function is_array; +use function is_string; +use function str_starts_with; /** * Returns an ordered stream of documents based on the proximity to a geospatial point. Incorporates the functionality of $match, $sort, and $limit for geospatial data. The output documents include an additional distance field and can include a location identifier field. @@ -52,8 +55,8 @@ final class GeoNearStage implements StageInterface, OperatorInterface /** @var Optional|string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. */ public readonly Optional|string $distanceField; - /** @var Optional|Decimal128|Int64|float|int|string $distanceMultiplier The factor to multiply all distances returned by the query. For example, use the distanceMultiplier to convert radians, as returned by a spherical query, to kilometers by multiplying by the radius of the Earth. */ - public readonly Optional|Decimal128|Int64|float|int|string $distanceMultiplier; + /** @var Optional|Decimal128|Int64|float|int $distanceMultiplier The factor to multiply all distances returned by the query. For example, use the distanceMultiplier to convert radians, as returned by a spherical query, to kilometers by multiplying by the radius of the Earth. */ + public readonly Optional|Decimal128|Int64|float|int $distanceMultiplier; /** @var Optional|string $includeLocs This specifies the output field that identifies the location used to calculate the distance. This option is useful when a location field contains multiple locations. To specify a field within an embedded document, use dot notation. */ public readonly Optional|string $includeLocs; @@ -62,16 +65,16 @@ final class GeoNearStage implements StageInterface, OperatorInterface public readonly Optional|string $key; /** - * @var Optional|Decimal128|Int64|float|int|string $maxDistance The maximum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall within the specified distance from the center point. + * @var Optional|Decimal128|Int64|float|int $maxDistance The maximum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall within the specified distance from the center point. * Specify the distance in meters if the specified point is GeoJSON and in radians if the specified point is legacy coordinate pairs. */ - public readonly Optional|Decimal128|Int64|float|int|string $maxDistance; + public readonly Optional|Decimal128|Int64|float|int $maxDistance; /** - * @var Optional|Decimal128|Int64|float|int|string $minDistance The minimum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall outside the specified distance from the center point. + * @var Optional|Decimal128|Int64|float|int $minDistance The minimum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall outside the specified distance from the center point. * Specify the distance in meters for GeoJSON data and in radians for legacy coordinate pairs. */ - public readonly Optional|Decimal128|Int64|float|int|string $minDistance; + public readonly Optional|Decimal128|Int64|float|int $minDistance; /** * @var Optional|QueryInterface|array $query Limits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. @@ -80,26 +83,26 @@ final class GeoNearStage implements StageInterface, OperatorInterface public readonly Optional|QueryInterface|array $query; /** - * @var Optional|bool|string $spherical Determines how MongoDB calculates the distance between two points: + * @var Optional|bool $spherical Determines how MongoDB calculates the distance between two points: * - When true, MongoDB uses $nearSphere semantics and calculates distances using spherical geometry. * - When false, MongoDB uses $near semantics: spherical geometry for 2dsphere indexes and planar geometry for 2d indexes. * Default: false. */ - public readonly Optional|bool|string $spherical; + public readonly Optional|bool $spherical; /** * @param Document|ResolvesToObject|Serializable|array|stdClass|string $near The point for which to find the closest documents. * @param Optional|string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. - * @param Optional|Decimal128|Int64|float|int|string $distanceMultiplier The factor to multiply all distances returned by the query. For example, use the distanceMultiplier to convert radians, as returned by a spherical query, to kilometers by multiplying by the radius of the Earth. + * @param Optional|Decimal128|Int64|float|int $distanceMultiplier The factor to multiply all distances returned by the query. For example, use the distanceMultiplier to convert radians, as returned by a spherical query, to kilometers by multiplying by the radius of the Earth. * @param Optional|string $includeLocs This specifies the output field that identifies the location used to calculate the distance. This option is useful when a location field contains multiple locations. To specify a field within an embedded document, use dot notation. * @param Optional|string $key Specify the geospatial indexed field to use when calculating the distance. - * @param Optional|Decimal128|Int64|float|int|string $maxDistance The maximum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall within the specified distance from the center point. + * @param Optional|Decimal128|Int64|float|int $maxDistance The maximum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall within the specified distance from the center point. * Specify the distance in meters if the specified point is GeoJSON and in radians if the specified point is legacy coordinate pairs. - * @param Optional|Decimal128|Int64|float|int|string $minDistance The minimum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall outside the specified distance from the center point. + * @param Optional|Decimal128|Int64|float|int $minDistance The minimum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall outside the specified distance from the center point. * Specify the distance in meters for GeoJSON data and in radians for legacy coordinate pairs. * @param Optional|QueryInterface|array $query Limits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. * You cannot specify a $near predicate in the query field of the $geoNear stage. - * @param Optional|bool|string $spherical Determines how MongoDB calculates the distance between two points: + * @param Optional|bool $spherical Determines how MongoDB calculates the distance between two points: * - When true, MongoDB uses $nearSphere semantics and calculates distances using spherical geometry. * - When false, MongoDB uses $near semantics: spherical geometry for 2dsphere indexes and planar geometry for 2d indexes. * Default: false. @@ -107,14 +110,18 @@ final class GeoNearStage implements StageInterface, OperatorInterface public function __construct( Document|Serializable|ResolvesToObject|stdClass|array|string $near, Optional|string $distanceField = Optional::Undefined, - Optional|Decimal128|Int64|float|int|string $distanceMultiplier = Optional::Undefined, + Optional|Decimal128|Int64|float|int $distanceMultiplier = Optional::Undefined, Optional|string $includeLocs = Optional::Undefined, Optional|string $key = Optional::Undefined, - Optional|Decimal128|Int64|float|int|string $maxDistance = Optional::Undefined, - Optional|Decimal128|Int64|float|int|string $minDistance = Optional::Undefined, + Optional|Decimal128|Int64|float|int $maxDistance = Optional::Undefined, + Optional|Decimal128|Int64|float|int $minDistance = Optional::Undefined, Optional|QueryInterface|array $query = Optional::Undefined, - Optional|bool|string $spherical = Optional::Undefined, + Optional|bool $spherical = Optional::Undefined, ) { + if (is_string($near) && ! str_starts_with($near, '$')) { + throw new InvalidArgumentException('Argument $near can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->near = $near; $this->distanceField = $distanceField; $this->distanceMultiplier = $distanceMultiplier; diff --git a/src/Builder/Stage/GraphLookupStage.php b/src/Builder/Stage/GraphLookupStage.php index b4257f795..936b59861 100644 --- a/src/Builder/Stage/GraphLookupStage.php +++ b/src/Builder/Stage/GraphLookupStage.php @@ -64,8 +64,8 @@ final class GraphLookupStage implements StageInterface, OperatorInterface /** @var string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. */ public readonly string $as; - /** @var Optional|int|string $maxDepth Non-negative integral number specifying the maximum recursion depth. */ - public readonly Optional|int|string $maxDepth; + /** @var Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. */ + public readonly Optional|int $maxDepth; /** @var Optional|string $depthField Name of the field to add to each traversed document in the search path. The value of this field is the recursion depth for the document, represented as a NumberLong. Recursion depth value starts at zero, so the first lookup corresponds to zero depth. */ public readonly Optional|string $depthField; @@ -80,7 +80,7 @@ final class GraphLookupStage implements StageInterface, OperatorInterface * @param string $connectFromField Field name whose value $graphLookup uses to recursively match against the connectToField of other documents in the collection. If the value is an array, each element is individually followed through the traversal process. * @param string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. * @param string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. - * @param Optional|int|string $maxDepth Non-negative integral number specifying the maximum recursion depth. + * @param Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. * @param Optional|string $depthField Name of the field to add to each traversed document in the search path. The value of this field is the recursion depth for the document, represented as a NumberLong. Recursion depth value starts at zero, so the first lookup corresponds to zero depth. * @param Optional|QueryInterface|array $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ @@ -90,7 +90,7 @@ public function __construct( string $connectFromField, string $connectToField, string $as, - Optional|int|string $maxDepth = Optional::Undefined, + Optional|int $maxDepth = Optional::Undefined, Optional|string $depthField = Optional::Undefined, Optional|QueryInterface|array $restrictSearchWithMatch = Optional::Undefined, ) { diff --git a/src/Builder/Stage/LimitStage.php b/src/Builder/Stage/LimitStage.php index edd09a475..ec765fa8a 100644 --- a/src/Builder/Stage/LimitStage.php +++ b/src/Builder/Stage/LimitStage.php @@ -24,13 +24,13 @@ final class LimitStage implements StageInterface, OperatorInterface public const NAME = '$limit'; public const PROPERTIES = ['limit' => 'limit']; - /** @var int|string $limit */ - public readonly int|string $limit; + /** @var int $limit */ + public readonly int $limit; /** - * @param int|string $limit + * @param int $limit */ - public function __construct(int|string $limit) + public function __construct(int $limit) { $this->limit = $limit; } diff --git a/src/Builder/Stage/ListLocalSessionsStage.php b/src/Builder/Stage/ListLocalSessionsStage.php index 31701f75d..f438b0148 100644 --- a/src/Builder/Stage/ListLocalSessionsStage.php +++ b/src/Builder/Stage/ListLocalSessionsStage.php @@ -31,19 +31,19 @@ final class ListLocalSessionsStage implements StageInterface, OperatorInterface public const NAME = '$listLocalSessions'; public const PROPERTIES = ['users' => 'users', 'allUsers' => 'allUsers']; - /** @var Optional|BSONArray|PackedArray|array|string $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. */ - public readonly Optional|PackedArray|BSONArray|array|string $users; + /** @var Optional|BSONArray|PackedArray|array $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. */ + public readonly Optional|PackedArray|BSONArray|array $users; - /** @var Optional|bool|string $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ - public readonly Optional|bool|string $allUsers; + /** @var Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ + public readonly Optional|bool $allUsers; /** - * @param Optional|BSONArray|PackedArray|array|string $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. - * @param Optional|bool|string $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + * @param Optional|BSONArray|PackedArray|array $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. + * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public function __construct( - Optional|PackedArray|BSONArray|array|string $users = Optional::Undefined, - Optional|bool|string $allUsers = Optional::Undefined, + Optional|PackedArray|BSONArray|array $users = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, ) { if (is_array($users) && ! array_is_list($users)) { throw new InvalidArgumentException('Expected $users argument to be a list, got an associative array.'); diff --git a/src/Builder/Stage/ListSessionsStage.php b/src/Builder/Stage/ListSessionsStage.php index 66919c075..687425ce1 100644 --- a/src/Builder/Stage/ListSessionsStage.php +++ b/src/Builder/Stage/ListSessionsStage.php @@ -31,19 +31,19 @@ final class ListSessionsStage implements StageInterface, OperatorInterface public const NAME = '$listSessions'; public const PROPERTIES = ['users' => 'users', 'allUsers' => 'allUsers']; - /** @var Optional|BSONArray|PackedArray|array|string $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. */ - public readonly Optional|PackedArray|BSONArray|array|string $users; + /** @var Optional|BSONArray|PackedArray|array $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. */ + public readonly Optional|PackedArray|BSONArray|array $users; - /** @var Optional|bool|string $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ - public readonly Optional|bool|string $allUsers; + /** @var Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ + public readonly Optional|bool $allUsers; /** - * @param Optional|BSONArray|PackedArray|array|string $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. - * @param Optional|bool|string $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + * @param Optional|BSONArray|PackedArray|array $users Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. + * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public function __construct( - Optional|PackedArray|BSONArray|array|string $users = Optional::Undefined, - Optional|bool|string $allUsers = Optional::Undefined, + Optional|PackedArray|BSONArray|array $users = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, ) { if (is_array($users) && ! array_is_list($users)) { throw new InvalidArgumentException('Expected $users argument to be a list, got an associative array.'); diff --git a/src/Builder/Stage/LookupStage.php b/src/Builder/Stage/LookupStage.php index a473de6e7..a9bf0d7ee 100644 --- a/src/Builder/Stage/LookupStage.php +++ b/src/Builder/Stage/LookupStage.php @@ -59,8 +59,8 @@ final class LookupStage implements StageInterface, OperatorInterface /** @var Optional|string $foreignField Specifies the field from the documents in the from collection. $lookup performs an equality match on the foreignField to the localField from the input documents. If a document in the from collection does not contain the foreignField, the $lookup treats the value as null for matching purposes. */ public readonly Optional|string $foreignField; - /** @var Optional|Document|Serializable|array|stdClass|string $let Specifies variables to use in the pipeline stages. Use the variable expressions to access the fields from the joined collection's documents that are input to the pipeline. */ - public readonly Optional|Document|Serializable|stdClass|array|string $let; + /** @var Optional|Document|Serializable|array|stdClass $let Specifies variables to use in the pipeline stages. Use the variable expressions to access the fields from the joined collection's documents that are input to the pipeline. */ + public readonly Optional|Document|Serializable|stdClass|array $let; /** * @var Optional|BSONArray|PackedArray|Pipeline|array $pipeline Specifies the pipeline to run on the joined collection. The pipeline determines the resulting documents from the joined collection. To return all documents, specify an empty pipeline []. @@ -76,7 +76,7 @@ final class LookupStage implements StageInterface, OperatorInterface * Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded. * @param Optional|string $localField Specifies the field from the documents input to the $lookup stage. $lookup performs an equality match on the localField to the foreignField from the documents of the from collection. If an input document does not contain the localField, the $lookup treats the field as having a value of null for matching purposes. * @param Optional|string $foreignField Specifies the field from the documents in the from collection. $lookup performs an equality match on the foreignField to the localField from the input documents. If a document in the from collection does not contain the foreignField, the $lookup treats the value as null for matching purposes. - * @param Optional|Document|Serializable|array|stdClass|string $let Specifies variables to use in the pipeline stages. Use the variable expressions to access the fields from the joined collection's documents that are input to the pipeline. + * @param Optional|Document|Serializable|array|stdClass $let Specifies variables to use in the pipeline stages. Use the variable expressions to access the fields from the joined collection's documents that are input to the pipeline. * @param Optional|BSONArray|PackedArray|Pipeline|array $pipeline Specifies the pipeline to run on the joined collection. The pipeline determines the resulting documents from the joined collection. To return all documents, specify an empty pipeline []. * The pipeline cannot include the $out stage or the $merge stage. Starting in v6.0, the pipeline can contain the Atlas Search $search stage as the first stage inside the pipeline. * The pipeline cannot directly access the joined document fields. Instead, define variables for the joined document fields using the let option and then reference the variables in the pipeline stages. @@ -86,7 +86,7 @@ public function __construct( Optional|string $from = Optional::Undefined, Optional|string $localField = Optional::Undefined, Optional|string $foreignField = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $let = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $let = Optional::Undefined, Optional|PackedArray|Pipeline|BSONArray|array $pipeline = Optional::Undefined, ) { $this->as = $as; diff --git a/src/Builder/Stage/MergeStage.php b/src/Builder/Stage/MergeStage.php index 0d63e40c0..2fc3e94da 100644 --- a/src/Builder/Stage/MergeStage.php +++ b/src/Builder/Stage/MergeStage.php @@ -49,8 +49,8 @@ final class MergeStage implements StageInterface, OperatorInterface /** @var Optional|BSONArray|PackedArray|array|string $on Field or fields that act as a unique identifier for a document. The identifier determines if a results document matches an existing document in the output collection. */ public readonly Optional|PackedArray|BSONArray|array|string $on; - /** @var Optional|Document|Serializable|array|stdClass|string $let Specifies variables for use in the whenMatched pipeline. */ - public readonly Optional|Document|Serializable|stdClass|array|string $let; + /** @var Optional|Document|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. */ + public readonly Optional|Document|Serializable|stdClass|array $let; /** @var Optional|BSONArray|PackedArray|Pipeline|array|string $whenMatched The behavior of $merge if a result document and an existing document in the collection have the same value for the specified on field(s). */ public readonly Optional|PackedArray|Pipeline|BSONArray|array|string $whenMatched; @@ -61,14 +61,14 @@ final class MergeStage implements StageInterface, OperatorInterface /** * @param Document|Serializable|array|stdClass|string $into The output collection. * @param Optional|BSONArray|PackedArray|array|string $on Field or fields that act as a unique identifier for a document. The identifier determines if a results document matches an existing document in the output collection. - * @param Optional|Document|Serializable|array|stdClass|string $let Specifies variables for use in the whenMatched pipeline. + * @param Optional|Document|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. * @param Optional|BSONArray|PackedArray|Pipeline|array|string $whenMatched The behavior of $merge if a result document and an existing document in the collection have the same value for the specified on field(s). * @param Optional|string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. */ public function __construct( Document|Serializable|stdClass|array|string $into, Optional|PackedArray|BSONArray|array|string $on = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $let = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $let = Optional::Undefined, Optional|PackedArray|Pipeline|BSONArray|array|string $whenMatched = Optional::Undefined, Optional|string $whenNotMatched = Optional::Undefined, ) { diff --git a/src/Builder/Stage/ReplaceRootStage.php b/src/Builder/Stage/ReplaceRootStage.php index c4d636a2d..2cf5c34b2 100644 --- a/src/Builder/Stage/ReplaceRootStage.php +++ b/src/Builder/Stage/ReplaceRootStage.php @@ -14,8 +14,12 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\StageInterface; +use MongoDB\Exception\InvalidArgumentException; use stdClass; +use function is_string; +use function str_starts_with; + /** * Replaces a document with the specified embedded document. The operation replaces all existing fields in the input document, including the _id field. Specify a document embedded in the input document to promote the embedded document to the top level. * @@ -36,6 +40,10 @@ final class ReplaceRootStage implements StageInterface, OperatorInterface */ public function __construct(Document|Serializable|ResolvesToObject|stdClass|array|string $newRoot) { + if (is_string($newRoot) && ! str_starts_with($newRoot, '$')) { + throw new InvalidArgumentException('Argument $newRoot can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->newRoot = $newRoot; } } diff --git a/src/Builder/Stage/ReplaceWithStage.php b/src/Builder/Stage/ReplaceWithStage.php index 4db813e6a..95746bfa9 100644 --- a/src/Builder/Stage/ReplaceWithStage.php +++ b/src/Builder/Stage/ReplaceWithStage.php @@ -14,8 +14,12 @@ use MongoDB\Builder\Type\Encode; use MongoDB\Builder\Type\OperatorInterface; use MongoDB\Builder\Type\StageInterface; +use MongoDB\Exception\InvalidArgumentException; use stdClass; +use function is_string; +use function str_starts_with; + /** * Replaces a document with the specified embedded document. The operation replaces all existing fields in the input document, including the _id field. Specify a document embedded in the input document to promote the embedded document to the top level. * Alias for $replaceRoot. @@ -37,6 +41,10 @@ final class ReplaceWithStage implements StageInterface, OperatorInterface */ public function __construct(Document|Serializable|ResolvesToObject|stdClass|array|string $expression) { + if (is_string($expression) && ! str_starts_with($expression, '$')) { + throw new InvalidArgumentException('Argument $expression can be an expression, field paths and variable names must be prefixed by "$" or "$$".'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Stage/SampleStage.php b/src/Builder/Stage/SampleStage.php index dc19083ae..c00b2bb26 100644 --- a/src/Builder/Stage/SampleStage.php +++ b/src/Builder/Stage/SampleStage.php @@ -24,13 +24,13 @@ final class SampleStage implements StageInterface, OperatorInterface public const NAME = '$sample'; public const PROPERTIES = ['size' => 'size']; - /** @var int|string $size The number of documents to randomly select. */ - public readonly int|string $size; + /** @var int $size The number of documents to randomly select. */ + public readonly int $size; /** - * @param int|string $size The number of documents to randomly select. + * @param int $size The number of documents to randomly select. */ - public function __construct(int|string $size) + public function __construct(int $size) { $this->size = $size; } diff --git a/src/Builder/Stage/SearchMetaStage.php b/src/Builder/Stage/SearchMetaStage.php index e90d75619..14687161b 100644 --- a/src/Builder/Stage/SearchMetaStage.php +++ b/src/Builder/Stage/SearchMetaStage.php @@ -39,19 +39,19 @@ final class SearchMetaStage implements StageInterface, OperatorInterface /** @var Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to default. */ public readonly Optional|string $index; - /** @var Optional|Document|Serializable|array|stdClass|string $count Document that specifies the count options for retrieving a count of the results. */ - public readonly Optional|Document|Serializable|stdClass|array|string $count; + /** @var Optional|Document|Serializable|array|stdClass $count Document that specifies the count options for retrieving a count of the results. */ + public readonly Optional|Document|Serializable|stdClass|array $count; /** * @param Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use * the compound operator to run a compound query with multiple operators. * @param Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to default. - * @param Optional|Document|Serializable|array|stdClass|string $count Document that specifies the count options for retrieving a count of the results. + * @param Optional|Document|Serializable|array|stdClass $count Document that specifies the count options for retrieving a count of the results. */ public function __construct( Document|Serializable|SearchOperatorInterface|stdClass|array $operator, Optional|string $index = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $count = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $count = Optional::Undefined, ) { $this->operator = $operator; $this->index = $index; diff --git a/src/Builder/Stage/SearchStage.php b/src/Builder/Stage/SearchStage.php index 03f3419e4..1aac4a423 100644 --- a/src/Builder/Stage/SearchStage.php +++ b/src/Builder/Stage/SearchStage.php @@ -52,18 +52,18 @@ final class SearchStage implements StageInterface, OperatorInterface /** @var Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to "default". */ public readonly Optional|string $index; - /** @var Optional|Document|Serializable|array|stdClass|string $highlight Specifies the highlighting options for displaying search terms in their original context. */ - public readonly Optional|Document|Serializable|stdClass|array|string $highlight; + /** @var Optional|Document|Serializable|array|stdClass $highlight Specifies the highlighting options for displaying search terms in their original context. */ + public readonly Optional|Document|Serializable|stdClass|array $highlight; /** - * @var Optional|bool|string $concurrent Parallelize search across segments on dedicated search nodes. + * @var Optional|bool $concurrent Parallelize search across segments on dedicated search nodes. * If you don't have separate search nodes on your cluster, * Atlas Search ignores this flag. If omitted, defaults to false. */ - public readonly Optional|bool|string $concurrent; + public readonly Optional|bool $concurrent; - /** @var Optional|Document|Serializable|array|stdClass|string $count Document that specifies the count options for retrieving a count of the results. */ - public readonly Optional|Document|Serializable|stdClass|array|string $count; + /** @var Optional|Document|Serializable|array|stdClass $count Document that specifies the count options for retrieving a count of the results. */ + public readonly Optional|Document|Serializable|stdClass|array $count; /** @var Optional|string $searchAfter Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point. */ public readonly Optional|string $searchAfter; @@ -71,46 +71,46 @@ final class SearchStage implements StageInterface, OperatorInterface /** @var Optional|string $searchBefore Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point. */ public readonly Optional|string $searchBefore; - /** @var Optional|bool|string $scoreDetails Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false. */ - public readonly Optional|bool|string $scoreDetails; + /** @var Optional|bool $scoreDetails Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false. */ + public readonly Optional|bool $scoreDetails; - /** @var Optional|Document|Serializable|array|stdClass|string $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order. */ - public readonly Optional|Document|Serializable|stdClass|array|string $sort; + /** @var Optional|Document|Serializable|array|stdClass $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order. */ + public readonly Optional|Document|Serializable|stdClass|array $sort; - /** @var Optional|bool|string $returnStoredSource Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search. */ - public readonly Optional|bool|string $returnStoredSource; + /** @var Optional|bool $returnStoredSource Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search. */ + public readonly Optional|bool $returnStoredSource; - /** @var Optional|Document|Serializable|array|stdClass|string $tracking Document that specifies the tracking option to retrieve analytics information on the search terms. */ - public readonly Optional|Document|Serializable|stdClass|array|string $tracking; + /** @var Optional|Document|Serializable|array|stdClass $tracking Document that specifies the tracking option to retrieve analytics information on the search terms. */ + public readonly Optional|Document|Serializable|stdClass|array $tracking; /** * @param Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use * the compound operator to run a compound query with multiple operators. * @param Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to "default". - * @param Optional|Document|Serializable|array|stdClass|string $highlight Specifies the highlighting options for displaying search terms in their original context. - * @param Optional|bool|string $concurrent Parallelize search across segments on dedicated search nodes. + * @param Optional|Document|Serializable|array|stdClass $highlight Specifies the highlighting options for displaying search terms in their original context. + * @param Optional|bool $concurrent Parallelize search across segments on dedicated search nodes. * If you don't have separate search nodes on your cluster, * Atlas Search ignores this flag. If omitted, defaults to false. - * @param Optional|Document|Serializable|array|stdClass|string $count Document that specifies the count options for retrieving a count of the results. + * @param Optional|Document|Serializable|array|stdClass $count Document that specifies the count options for retrieving a count of the results. * @param Optional|string $searchAfter Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point. * @param Optional|string $searchBefore Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point. - * @param Optional|bool|string $scoreDetails Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false. - * @param Optional|Document|Serializable|array|stdClass|string $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order. - * @param Optional|bool|string $returnStoredSource Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search. - * @param Optional|Document|Serializable|array|stdClass|string $tracking Document that specifies the tracking option to retrieve analytics information on the search terms. + * @param Optional|bool $scoreDetails Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false. + * @param Optional|Document|Serializable|array|stdClass $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order. + * @param Optional|bool $returnStoredSource Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search. + * @param Optional|Document|Serializable|array|stdClass $tracking Document that specifies the tracking option to retrieve analytics information on the search terms. */ public function __construct( Document|Serializable|SearchOperatorInterface|stdClass|array $operator, Optional|string $index = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $highlight = Optional::Undefined, - Optional|bool|string $concurrent = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $count = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $highlight = Optional::Undefined, + Optional|bool $concurrent = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $count = Optional::Undefined, Optional|string $searchAfter = Optional::Undefined, Optional|string $searchBefore = Optional::Undefined, - Optional|bool|string $scoreDetails = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $sort = Optional::Undefined, - Optional|bool|string $returnStoredSource = Optional::Undefined, - Optional|Document|Serializable|stdClass|array|string $tracking = Optional::Undefined, + Optional|bool $scoreDetails = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $sort = Optional::Undefined, + Optional|bool $returnStoredSource = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $tracking = Optional::Undefined, ) { $this->operator = $operator; $this->index = $index; diff --git a/src/Builder/Stage/SetWindowFieldsStage.php b/src/Builder/Stage/SetWindowFieldsStage.php index 8796211ee..ba8d63edf 100644 --- a/src/Builder/Stage/SetWindowFieldsStage.php +++ b/src/Builder/Stage/SetWindowFieldsStage.php @@ -35,23 +35,23 @@ final class SetWindowFieldsStage implements StageInterface, OperatorInterface public readonly Document|Serializable|stdClass|array $sortBy; /** - * @var Document|Serializable|array|stdClass|string $output Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. + * @var Document|Serializable|array|stdClass $output Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. * A field can contain dots to specify embedded document fields and array fields. The semantics for the embedded document dotted notation in the $setWindowFields stage are the same as the $addFields and $set stages. */ - public readonly Document|Serializable|stdClass|array|string $output; + public readonly Document|Serializable|stdClass|array $output; /** @var Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $partitionBy Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. */ public readonly Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $partitionBy; /** * @param Document|Serializable|array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. - * @param Document|Serializable|array|stdClass|string $output Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. + * @param Document|Serializable|array|stdClass $output Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. * A field can contain dots to specify embedded document fields and array fields. The semantics for the embedded document dotted notation in the $setWindowFields stage are the same as the $addFields and $set stages. * @param Optional|ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $partitionBy Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. */ public function __construct( Document|Serializable|stdClass|array $sortBy, - Document|Serializable|stdClass|array|string $output, + Document|Serializable|stdClass|array $output, Optional|Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $partitionBy = Optional::Undefined, ) { $this->sortBy = $sortBy; diff --git a/src/Builder/Stage/SkipStage.php b/src/Builder/Stage/SkipStage.php index 807075bd4..aab0242d8 100644 --- a/src/Builder/Stage/SkipStage.php +++ b/src/Builder/Stage/SkipStage.php @@ -24,13 +24,13 @@ final class SkipStage implements StageInterface, OperatorInterface public const NAME = '$skip'; public const PROPERTIES = ['skip' => 'skip']; - /** @var int|string $skip */ - public readonly int|string $skip; + /** @var int $skip */ + public readonly int $skip; /** - * @param int|string $skip + * @param int $skip */ - public function __construct(int|string $skip) + public function __construct(int $skip) { $this->skip = $skip; } diff --git a/src/Builder/Stage/UnwindStage.php b/src/Builder/Stage/UnwindStage.php index 653c6cc86..9959f462b 100644 --- a/src/Builder/Stage/UnwindStage.php +++ b/src/Builder/Stage/UnwindStage.php @@ -38,23 +38,23 @@ final class UnwindStage implements StageInterface, OperatorInterface public readonly Optional|string $includeArrayIndex; /** - * @var Optional|bool|string $preserveNullAndEmptyArrays If true, if the path is null, missing, or an empty array, $unwind outputs the document. + * @var Optional|bool $preserveNullAndEmptyArrays If true, if the path is null, missing, or an empty array, $unwind outputs the document. * If false, if path is null, missing, or an empty array, $unwind does not output a document. * The default value is false. */ - public readonly Optional|bool|string $preserveNullAndEmptyArrays; + public readonly Optional|bool $preserveNullAndEmptyArrays; /** * @param ArrayFieldPath|string $path Field path to an array field. * @param Optional|string $includeArrayIndex The name of a new field to hold the array index of the element. The name cannot start with a dollar sign $. - * @param Optional|bool|string $preserveNullAndEmptyArrays If true, if the path is null, missing, or an empty array, $unwind outputs the document. + * @param Optional|bool $preserveNullAndEmptyArrays If true, if the path is null, missing, or an empty array, $unwind outputs the document. * If false, if path is null, missing, or an empty array, $unwind does not output a document. * The default value is false. */ public function __construct( ArrayFieldPath|string $path, Optional|string $includeArrayIndex = Optional::Undefined, - Optional|bool|string $preserveNullAndEmptyArrays = Optional::Undefined, + Optional|bool $preserveNullAndEmptyArrays = Optional::Undefined, ) { $this->path = $path; $this->includeArrayIndex = $includeArrayIndex; diff --git a/src/Builder/Stage/VectorSearchStage.php b/src/Builder/Stage/VectorSearchStage.php index 1ca5809ff..e8f7738cc 100644 --- a/src/Builder/Stage/VectorSearchStage.php +++ b/src/Builder/Stage/VectorSearchStage.php @@ -45,45 +45,45 @@ final class VectorSearchStage implements StageInterface, OperatorInterface /** @var string $index Name of the Atlas Vector Search index to use. */ public readonly string $index; - /** @var int|string $limit Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates. */ - public readonly int|string $limit; + /** @var int $limit Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates. */ + public readonly int $limit; /** @var array|string $path Indexed vector type field to search. */ public readonly array|string $path; - /** @var BSONArray|PackedArray|array|string $queryVector Array of numbers that represent the query vector. The number type must match the indexed field value type. */ - public readonly PackedArray|BSONArray|array|string $queryVector; + /** @var BSONArray|PackedArray|array $queryVector Array of numbers that represent the query vector. The number type must match the indexed field value type. */ + public readonly PackedArray|BSONArray|array $queryVector; - /** @var Optional|bool|string $exact This is required if numCandidates is omitted. false to run ANN search. true to run ENN search. */ - public readonly Optional|bool|string $exact; + /** @var Optional|bool $exact This is required if numCandidates is omitted. false to run ANN search. true to run ENN search. */ + public readonly Optional|bool $exact; /** @var Optional|QueryInterface|array $filter Any match query that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter. */ public readonly Optional|QueryInterface|array $filter; /** - * @var Optional|int|string $numCandidates This field is required if exact is false or omitted. + * @var Optional|int $numCandidates This field is required if exact is false or omitted. * Number of nearest neighbors to use during the search. Value must be less than or equal to (<=) 10000. You can't specify a number less than the number of documents to return (limit). */ - public readonly Optional|int|string $numCandidates; + public readonly Optional|int $numCandidates; /** * @param string $index Name of the Atlas Vector Search index to use. - * @param int|string $limit Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates. + * @param int $limit Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates. * @param array|string $path Indexed vector type field to search. - * @param BSONArray|PackedArray|array|string $queryVector Array of numbers that represent the query vector. The number type must match the indexed field value type. - * @param Optional|bool|string $exact This is required if numCandidates is omitted. false to run ANN search. true to run ENN search. + * @param BSONArray|PackedArray|array $queryVector Array of numbers that represent the query vector. The number type must match the indexed field value type. + * @param Optional|bool $exact This is required if numCandidates is omitted. false to run ANN search. true to run ENN search. * @param Optional|QueryInterface|array $filter Any match query that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter. - * @param Optional|int|string $numCandidates This field is required if exact is false or omitted. + * @param Optional|int $numCandidates This field is required if exact is false or omitted. * Number of nearest neighbors to use during the search. Value must be less than or equal to (<=) 10000. You can't specify a number less than the number of documents to return (limit). */ public function __construct( string $index, - int|string $limit, + int $limit, array|string $path, - PackedArray|BSONArray|array|string $queryVector, - Optional|bool|string $exact = Optional::Undefined, + PackedArray|BSONArray|array $queryVector, + Optional|bool $exact = Optional::Undefined, Optional|QueryInterface|array $filter = Optional::Undefined, - Optional|int|string $numCandidates = Optional::Undefined, + Optional|int $numCandidates = Optional::Undefined, ) { $this->index = $index; $this->limit = $limit; diff --git a/tests/Builder/FieldPathTest.php b/tests/Builder/FieldPathTest.php index afd1a15de..496e66951 100644 --- a/tests/Builder/FieldPathTest.php +++ b/tests/Builder/FieldPathTest.php @@ -56,4 +56,18 @@ public static function provideFieldPath(): Generator yield 'number' => ['numberFieldPath', Expression\ResolvesToNumber::class]; yield 'any' => ['fieldPath', Expression\ResolvesToAny::class]; } + + public function testStringFieldPathAcceptedAsExpression(): void + { + $operator = Expression::abs('$foo'); + + $this->assertSame('$foo', $operator->value); + } + + public function testNonDollarPrefixedStringRejected(): void + { + self::expectException(\InvalidArgumentException::class); + + Expression::abs('foo'); + } }