Skip to content

Commit 9586098

Browse files
committed
wrapObject=false is only for encode object
1 parent 2c805b6 commit 9586098

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

generator/src/Definition/OperatorDefinition.php

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public function __construct(
4343
default => throw new UnexpectedValueException(sprintf('Unexpected "encode" value for operator "%s". Got "%s"', $name, $encode)),
4444
};
4545

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

psalm-baseline.xml

-6
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@
7575
<code><![CDATA[$val]]></code>
7676
<code><![CDATA[$val]]></code>
7777
</MixedAssignment>
78-
<MixedInferredReturnType>
79-
<code><![CDATA[stdClass]]></code>
80-
</MixedInferredReturnType>
81-
<MixedReturnStatement>
82-
<code><![CDATA[$result]]></code>
83-
</MixedReturnStatement>
8478
<PossibleRawObjectIteration>
8579
<code><![CDATA[$val]]></code>
8680
</PossibleRawObjectIteration>

src/Builder/Encoder/OperatorEncoder.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use MongoDB\Exception\UnsupportedValueException;
1313
use stdClass;
1414

15+
use function assert;
16+
use function is_string;
1517
use function sprintf;
1618

1719
/**
@@ -89,6 +91,10 @@ private function encodeAsObject(OperatorInterface $value): stdClass
8991
}
9092
}
9193

94+
if ($value::NAME === null) {
95+
return $result;
96+
}
97+
9298
return $this->wrap($value, $result);
9399
}
94100

@@ -106,16 +112,9 @@ private function encodeAsSingle(OperatorInterface $value): stdClass
106112
throw new LogicException(sprintf('Class "%s" does not have a single property.', $value::class));
107113
}
108114

109-
/**
110-
* Wrap the result in an object if the operator has a name.
111-
* The operator name is NULL, and the result is returned as is
112-
* when wrapObject is false in the YAML configuration of the operator.
113-
*/
114115
private function wrap(OperatorInterface $value, mixed $result): stdClass
115116
{
116-
if ($value::NAME === null) {
117-
return $result;
118-
}
117+
assert(is_string($value::NAME));
119118

120119
$object = new stdClass();
121120
$object->{$value::NAME} = $result;

0 commit comments

Comments
 (0)