From 663418de1a2f9667891778c4715742157de2aea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 27 Jan 2025 15:17:18 +0100 Subject: [PATCH] Change order of conditions to please psalm --- generator/config/accumulator/accumulator.yaml | 5 ++-- generator/src/OperatorClassGenerator.php | 24 +++++++++---------- .../Accumulator/AccumulatorAccumulator.php | 16 ++++++------- src/Builder/Accumulator/LastNAccumulator.php | 8 +++---- src/Builder/Accumulator/MaxNAccumulator.php | 8 +++---- src/Builder/Accumulator/MinNAccumulator.php | 8 +++---- .../Accumulator/PercentileAccumulator.php | 8 +++---- .../Expression/AllElementsTrueOperator.php | 8 +++---- .../Expression/AnyElementTrueOperator.php | 8 +++---- .../Expression/ArrayElemAtOperator.php | 8 +++---- .../Expression/ArrayToObjectOperator.php | 8 +++---- src/Builder/Expression/FilterOperator.php | 8 +++---- src/Builder/Expression/FirstNOperator.php | 8 +++---- src/Builder/Expression/FirstOperator.php | 8 +++---- src/Builder/Expression/InOperator.php | 8 +++---- .../Expression/IndexOfArrayOperator.php | 8 +++---- src/Builder/Expression/LastNOperator.php | 8 +++---- src/Builder/Expression/LastOperator.php | 8 +++---- src/Builder/Expression/MapOperator.php | 8 +++---- src/Builder/Expression/MaxNOperator.php | 8 +++---- src/Builder/Expression/MedianOperator.php | 8 +++---- src/Builder/Expression/MinNOperator.php | 8 +++---- src/Builder/Expression/PercentileOperator.php | 14 +++++------ src/Builder/Expression/ReduceOperator.php | 8 +++---- .../Expression/ReverseArrayOperator.php | 8 +++---- .../Expression/SetDifferenceOperator.php | 14 +++++------ .../Expression/SetIsSubsetOperator.php | 14 +++++------ src/Builder/Expression/SizeOperator.php | 8 +++---- src/Builder/Expression/SliceOperator.php | 8 +++---- src/Builder/Expression/SortArrayOperator.php | 8 +++---- src/Builder/Expression/ZipOperator.php | 8 +++---- src/Builder/Stage/DocumentsStage.php | 8 +++---- 32 files changed, 147 insertions(+), 148 deletions(-) diff --git a/generator/config/accumulator/accumulator.yaml b/generator/config/accumulator/accumulator.yaml index e90fbbf52..9cfdb6b53 100644 --- a/generator/config/accumulator/accumulator.yaml +++ b/generator/config/accumulator/accumulator.yaml @@ -73,7 +73,7 @@ tests: function(state, numCopies) { return { count: state.count + 1, sum: state.sum + numCopies } } - accumulateArgs: [ "$copies" ], + accumulateArgs: [ "$copies" ] merge: $code: |- function(state1, state2) { @@ -115,8 +115,7 @@ tests: } return state; } - accumulateArgs: - - '$name' + accumulateArgs: ['$name'] merge: $code: |- function(state1, state2) { diff --git a/generator/src/OperatorClassGenerator.php b/generator/src/OperatorClassGenerator.php index c0ab405c8..6fd80cc41 100644 --- a/generator/src/OperatorClassGenerator.php +++ b/generator/src/OperatorClassGenerator.php @@ -135,6 +135,18 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition $constructorParam->setDefaultValue($argument->default); } + 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); + } + // List type must be validated with array_is_list() if ($type->list) { $namespace->addUseFunction('is_array'); @@ -169,18 +181,6 @@ 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/src/Builder/Accumulator/AccumulatorAccumulator.php b/src/Builder/Accumulator/AccumulatorAccumulator.php index 94c503996..f26e5f7da 100644 --- a/src/Builder/Accumulator/AccumulatorAccumulator.php +++ b/src/Builder/Accumulator/AccumulatorAccumulator.php @@ -94,14 +94,14 @@ public function __construct( } $this->accumulate = $accumulate; - if (is_array($accumulateArgs) && ! array_is_list($accumulateArgs)) { - 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 "$$".'); } + if (is_array($accumulateArgs) && ! array_is_list($accumulateArgs)) { + throw new InvalidArgumentException('Expected $accumulateArgs argument to be a list, got an associative array.'); + } + $this->accumulateArgs = $accumulateArgs; if (is_string($merge)) { $merge = new Javascript($merge); @@ -109,14 +109,14 @@ public function __construct( $this->merge = $merge; $this->lang = $lang; - if (is_array($initArgs) && ! array_is_list($initArgs)) { - 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 "$$".'); } + if (is_array($initArgs) && ! array_is_list($initArgs)) { + throw new InvalidArgumentException('Expected $initArgs argument to be a list, got an associative array.'); + } + $this->initArgs = $initArgs; if (is_string($finalize)) { $finalize = new Javascript($finalize); diff --git a/src/Builder/Accumulator/LastNAccumulator.php b/src/Builder/Accumulator/LastNAccumulator.php index 67e1b0b0a..45a2a0f95 100644 --- a/src/Builder/Accumulator/LastNAccumulator.php +++ b/src/Builder/Accumulator/LastNAccumulator.php @@ -51,14 +51,14 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $input, ResolvesToInt|int|string $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 "$$".'); } + if (is_array($input) && ! array_is_list($input)) { + throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $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 "$$".'); diff --git a/src/Builder/Accumulator/MaxNAccumulator.php b/src/Builder/Accumulator/MaxNAccumulator.php index e44e8953f..eafbfbcfe 100644 --- a/src/Builder/Accumulator/MaxNAccumulator.php +++ b/src/Builder/Accumulator/MaxNAccumulator.php @@ -49,14 +49,14 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $input, ResolvesToInt|int|string $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 "$$".'); } + if (is_array($input) && ! array_is_list($input)) { + throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $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 "$$".'); diff --git a/src/Builder/Accumulator/MinNAccumulator.php b/src/Builder/Accumulator/MinNAccumulator.php index fc088a831..2d5eeab7e 100644 --- a/src/Builder/Accumulator/MinNAccumulator.php +++ b/src/Builder/Accumulator/MinNAccumulator.php @@ -49,14 +49,14 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $input, ResolvesToInt|int|string $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 "$$".'); } + if (is_array($input) && ! array_is_list($input)) { + throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $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 "$$".'); diff --git a/src/Builder/Accumulator/PercentileAccumulator.php b/src/Builder/Accumulator/PercentileAccumulator.php index 7e6b4af67..030f13aab 100644 --- a/src/Builder/Accumulator/PercentileAccumulator.php +++ b/src/Builder/Accumulator/PercentileAccumulator.php @@ -73,14 +73,14 @@ public function __construct( } $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 "$$".'); } + if (is_array($p) && ! array_is_list($p)) { + throw new InvalidArgumentException('Expected $p argument to be a list, got an associative array.'); + } + $this->p = $p; $this->method = $method; } diff --git a/src/Builder/Expression/AllElementsTrueOperator.php b/src/Builder/Expression/AllElementsTrueOperator.php index 4dd9c5b4b..282de6dfa 100644 --- a/src/Builder/Expression/AllElementsTrueOperator.php +++ b/src/Builder/Expression/AllElementsTrueOperator.php @@ -39,14 +39,14 @@ final class AllElementsTrueOperator implements ResolvesToBool, OperatorInterface */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $expression) { - if (is_array($expression) && ! array_is_list($expression)) { - 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 "$$".'); } + if (is_array($expression) && ! array_is_list($expression)) { + throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/AnyElementTrueOperator.php b/src/Builder/Expression/AnyElementTrueOperator.php index a37315e9d..c3566ca9e 100644 --- a/src/Builder/Expression/AnyElementTrueOperator.php +++ b/src/Builder/Expression/AnyElementTrueOperator.php @@ -39,14 +39,14 @@ final class AnyElementTrueOperator implements ResolvesToBool, OperatorInterface */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $expression) { - if (is_array($expression) && ! array_is_list($expression)) { - 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 "$$".'); } + if (is_array($expression) && ! array_is_list($expression)) { + throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/ArrayElemAtOperator.php b/src/Builder/Expression/ArrayElemAtOperator.php index 0f492ce0b..9cbca3cfe 100644 --- a/src/Builder/Expression/ArrayElemAtOperator.php +++ b/src/Builder/Expression/ArrayElemAtOperator.php @@ -45,14 +45,14 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $array, ResolvesToInt|int|string $idx, ) { - if (is_array($array) && ! array_is_list($array)) { - 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 "$$".'); } + if (is_array($array) && ! array_is_list($array)) { + throw new InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); + } + $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 "$$".'); diff --git a/src/Builder/Expression/ArrayToObjectOperator.php b/src/Builder/Expression/ArrayToObjectOperator.php index 77382c984..3a881363e 100644 --- a/src/Builder/Expression/ArrayToObjectOperator.php +++ b/src/Builder/Expression/ArrayToObjectOperator.php @@ -39,14 +39,14 @@ final class ArrayToObjectOperator implements ResolvesToObject, OperatorInterface */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $array) { - if (is_array($array) && ! array_is_list($array)) { - 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 "$$".'); } + if (is_array($array) && ! array_is_list($array)) { + throw new InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); + } + $this->array = $array; } } diff --git a/src/Builder/Expression/FilterOperator.php b/src/Builder/Expression/FilterOperator.php index 62f3b8c6c..b2f2df99c 100644 --- a/src/Builder/Expression/FilterOperator.php +++ b/src/Builder/Expression/FilterOperator.php @@ -60,14 +60,14 @@ public function __construct( Optional|string $as = Optional::Undefined, Optional|ResolvesToInt|int|string $limit = Optional::Undefined, ) { - 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 "$$".'); } + if (is_array($input) && ! array_is_list($input)) { + throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $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 "$$".'); diff --git a/src/Builder/Expression/FirstNOperator.php b/src/Builder/Expression/FirstNOperator.php index 19f90488a..9051441dc 100644 --- a/src/Builder/Expression/FirstNOperator.php +++ b/src/Builder/Expression/FirstNOperator.php @@ -50,14 +50,14 @@ public function __construct( } $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 "$$".'); } + if (is_array($input) && ! array_is_list($input)) { + throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; } } diff --git a/src/Builder/Expression/FirstOperator.php b/src/Builder/Expression/FirstOperator.php index db7f547fc..d967bf7d2 100644 --- a/src/Builder/Expression/FirstOperator.php +++ b/src/Builder/Expression/FirstOperator.php @@ -39,14 +39,14 @@ final class FirstOperator implements ResolvesToAny, OperatorInterface */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $expression) { - if (is_array($expression) && ! array_is_list($expression)) { - 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 "$$".'); } + if (is_array($expression) && ! array_is_list($expression)) { + throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/InOperator.php b/src/Builder/Expression/InOperator.php index bddbe6e29..2bc43265f 100644 --- a/src/Builder/Expression/InOperator.php +++ b/src/Builder/Expression/InOperator.php @@ -49,14 +49,14 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $array, ) { $this->expression = $expression; - if (is_array($array) && ! array_is_list($array)) { - 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 "$$".'); } + if (is_array($array) && ! array_is_list($array)) { + throw new InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); + } + $this->array = $array; } } diff --git a/src/Builder/Expression/IndexOfArrayOperator.php b/src/Builder/Expression/IndexOfArrayOperator.php index 29c0dad41..d364b0a10 100644 --- a/src/Builder/Expression/IndexOfArrayOperator.php +++ b/src/Builder/Expression/IndexOfArrayOperator.php @@ -73,14 +73,14 @@ public function __construct( Optional|ResolvesToInt|int|string $start = Optional::Undefined, Optional|ResolvesToInt|int|string $end = Optional::Undefined, ) { - if (is_array($array) && ! array_is_list($array)) { - 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 "$$".'); } + if (is_array($array) && ! array_is_list($array)) { + throw new InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); + } + $this->array = $array; $this->search = $search; if (is_string($start) && ! str_starts_with($start, '$')) { diff --git a/src/Builder/Expression/LastNOperator.php b/src/Builder/Expression/LastNOperator.php index 930fe1196..be714cd9b 100644 --- a/src/Builder/Expression/LastNOperator.php +++ b/src/Builder/Expression/LastNOperator.php @@ -50,14 +50,14 @@ public function __construct( } $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 "$$".'); } + if (is_array($input) && ! array_is_list($input)) { + throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; } } diff --git a/src/Builder/Expression/LastOperator.php b/src/Builder/Expression/LastOperator.php index e4104948a..68043d7d5 100644 --- a/src/Builder/Expression/LastOperator.php +++ b/src/Builder/Expression/LastOperator.php @@ -39,14 +39,14 @@ final class LastOperator implements ResolvesToAny, OperatorInterface */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $expression) { - if (is_array($expression) && ! array_is_list($expression)) { - 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 "$$".'); } + if (is_array($expression) && ! array_is_list($expression)) { + throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/MapOperator.php b/src/Builder/Expression/MapOperator.php index eecdc1fd0..bafa03ef8 100644 --- a/src/Builder/Expression/MapOperator.php +++ b/src/Builder/Expression/MapOperator.php @@ -54,14 +54,14 @@ public function __construct( Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, Optional|ResolvesToString|string $as = Optional::Undefined, ) { - 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 "$$".'); } + if (is_array($input) && ! array_is_list($input)) { + throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; $this->in = $in; $this->as = $as; diff --git a/src/Builder/Expression/MaxNOperator.php b/src/Builder/Expression/MaxNOperator.php index 76f9f6ea9..b0da2c042 100644 --- a/src/Builder/Expression/MaxNOperator.php +++ b/src/Builder/Expression/MaxNOperator.php @@ -45,14 +45,14 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $input, ResolvesToInt|int|string $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 "$$".'); } + if (is_array($input) && ! array_is_list($input)) { + throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $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 "$$".'); diff --git a/src/Builder/Expression/MedianOperator.php b/src/Builder/Expression/MedianOperator.php index ee1547f50..ec9afbdcf 100644 --- a/src/Builder/Expression/MedianOperator.php +++ b/src/Builder/Expression/MedianOperator.php @@ -52,14 +52,14 @@ public function __construct( Decimal128|Int64|PackedArray|ResolvesToNumber|BSONArray|array|float|int|string $input, string $method, ) { - 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 "$$".'); } + if (is_array($input) && ! array_is_list($input)) { + throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; $this->method = $method; } diff --git a/src/Builder/Expression/MinNOperator.php b/src/Builder/Expression/MinNOperator.php index 031b03179..50b22e1fd 100644 --- a/src/Builder/Expression/MinNOperator.php +++ b/src/Builder/Expression/MinNOperator.php @@ -45,14 +45,14 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $input, ResolvesToInt|int|string $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 "$$".'); } + if (is_array($input) && ! array_is_list($input)) { + throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $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 "$$".'); diff --git a/src/Builder/Expression/PercentileOperator.php b/src/Builder/Expression/PercentileOperator.php index 133a04f7b..c30775ca3 100644 --- a/src/Builder/Expression/PercentileOperator.php +++ b/src/Builder/Expression/PercentileOperator.php @@ -64,23 +64,23 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $p, string $method, ) { - 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; - if (is_array($p) && ! array_is_list($p)) { - throw new InvalidArgumentException('Expected $p argument to be a list, got an associative array.'); + if (is_array($input) && ! array_is_list($input)) { + throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + $this->input = $input; 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 "$$".'); } + if (is_array($p) && ! array_is_list($p)) { + throw new InvalidArgumentException('Expected $p argument to be a list, got an associative array.'); + } + $this->p = $p; $this->method = $method; } diff --git a/src/Builder/Expression/ReduceOperator.php b/src/Builder/Expression/ReduceOperator.php index 89e3b9f85..27d0d6398 100644 --- a/src/Builder/Expression/ReduceOperator.php +++ b/src/Builder/Expression/ReduceOperator.php @@ -67,14 +67,14 @@ public function __construct( Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $initialValue, Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $in, ) { - 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 "$$".'); } + if (is_array($input) && ! array_is_list($input)) { + throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; $this->initialValue = $initialValue; $this->in = $in; diff --git a/src/Builder/Expression/ReverseArrayOperator.php b/src/Builder/Expression/ReverseArrayOperator.php index 6c8a14424..4a02b1062 100644 --- a/src/Builder/Expression/ReverseArrayOperator.php +++ b/src/Builder/Expression/ReverseArrayOperator.php @@ -39,14 +39,14 @@ final class ReverseArrayOperator implements ResolvesToArray, OperatorInterface */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $expression) { - if (is_array($expression) && ! array_is_list($expression)) { - 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 "$$".'); } + if (is_array($expression) && ! array_is_list($expression)) { + throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/SetDifferenceOperator.php b/src/Builder/Expression/SetDifferenceOperator.php index 783e3baa5..297897425 100644 --- a/src/Builder/Expression/SetDifferenceOperator.php +++ b/src/Builder/Expression/SetDifferenceOperator.php @@ -45,23 +45,23 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $expression1, PackedArray|ResolvesToArray|BSONArray|array|string $expression2, ) { - if (is_array($expression1) && ! array_is_list($expression1)) { - 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_array($expression1) && ! array_is_list($expression1)) { + throw new InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); } + $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 "$$".'); } + if (is_array($expression2) && ! array_is_list($expression2)) { + throw new InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Expression/SetIsSubsetOperator.php b/src/Builder/Expression/SetIsSubsetOperator.php index b4215d58d..8d9a63e45 100644 --- a/src/Builder/Expression/SetIsSubsetOperator.php +++ b/src/Builder/Expression/SetIsSubsetOperator.php @@ -45,23 +45,23 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $expression1, PackedArray|ResolvesToArray|BSONArray|array|string $expression2, ) { - if (is_array($expression1) && ! array_is_list($expression1)) { - 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_array($expression1) && ! array_is_list($expression1)) { + throw new InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); } + $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 "$$".'); } + if (is_array($expression2) && ! array_is_list($expression2)) { + throw new InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Expression/SizeOperator.php b/src/Builder/Expression/SizeOperator.php index 7157e4d50..53b6cdd1a 100644 --- a/src/Builder/Expression/SizeOperator.php +++ b/src/Builder/Expression/SizeOperator.php @@ -39,14 +39,14 @@ final class SizeOperator implements ResolvesToInt, OperatorInterface */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $expression) { - if (is_array($expression) && ! array_is_list($expression)) { - 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 "$$".'); } + if (is_array($expression) && ! array_is_list($expression)) { + throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Expression/SliceOperator.php b/src/Builder/Expression/SliceOperator.php index 4dbccfbb3..71cc07415 100644 --- a/src/Builder/Expression/SliceOperator.php +++ b/src/Builder/Expression/SliceOperator.php @@ -63,14 +63,14 @@ public function __construct( ResolvesToInt|int|string $n, Optional|ResolvesToInt|int|string $position = Optional::Undefined, ) { - if (is_array($expression) && ! array_is_list($expression)) { - 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 "$$".'); } + if (is_array($expression) && ! array_is_list($expression)) { + throw new InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $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 "$$".'); diff --git a/src/Builder/Expression/SortArrayOperator.php b/src/Builder/Expression/SortArrayOperator.php index bfb93198e..6b1d26e0f 100644 --- a/src/Builder/Expression/SortArrayOperator.php +++ b/src/Builder/Expression/SortArrayOperator.php @@ -55,14 +55,14 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array|string $input, 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 "$$".'); } + if (is_array($input) && ! array_is_list($input)) { + throw new InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; $this->sortBy = $sortBy; } diff --git a/src/Builder/Expression/ZipOperator.php b/src/Builder/Expression/ZipOperator.php index af647b541..cc98f9ecf 100644 --- a/src/Builder/Expression/ZipOperator.php +++ b/src/Builder/Expression/ZipOperator.php @@ -67,14 +67,14 @@ public function __construct( 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 "$$".'); } + if (is_array($inputs) && ! array_is_list($inputs)) { + throw new InvalidArgumentException('Expected $inputs argument to be a list, got an associative array.'); + } + $this->inputs = $inputs; $this->useLongestLength = $useLongestLength; if (is_array($defaults) && ! array_is_list($defaults)) { diff --git a/src/Builder/Stage/DocumentsStage.php b/src/Builder/Stage/DocumentsStage.php index 316afda97..c020a9cb0 100644 --- a/src/Builder/Stage/DocumentsStage.php +++ b/src/Builder/Stage/DocumentsStage.php @@ -51,14 +51,14 @@ final class DocumentsStage implements StageInterface, OperatorInterface */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array|string $documents) { - if (is_array($documents) && ! array_is_list($documents)) { - 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 "$$".'); } + if (is_array($documents) && ! array_is_list($documents)) { + throw new InvalidArgumentException('Expected $documents argument to be a list, got an associative array.'); + } + $this->documents = $documents; } }