Skip to content

Commit

Permalink
Use strong arg type instead of assert
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Nov 27, 2024
1 parent f88512c commit 661e969
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/Builder/Encoder/OperatorEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ private function encodeAsDollarObject(OperatorInterface $value): stdClass
/**
* $group stage have a specific encoding because the _id argument is required and others are variadic
*/
private function encodeAsGroup(OperatorInterface $value): stdClass
private function encodeAsGroup(GroupStage $value): stdClass
{
assert($value instanceof GroupStage);

$result = new stdClass();
$result->_id = $this->recursiveEncode($value->_id);

Expand Down Expand Up @@ -132,10 +130,8 @@ private function encodeAsObject(OperatorInterface $value): stdClass
: $this->wrap($value, $result);
}

private function encodeAsSearch(OperatorInterface $value): stdClass
private function encodeAsSearch(SearchStage|SearchMetaStage $value): stdClass
{
assert($value instanceof SearchStage || $value instanceof SearchMetaStage);

$result = new stdClass();
foreach (get_object_vars($value) as $key => $val) {
// Skip optional arguments. If they have a default value, it is resolved by the server.
Expand All @@ -147,7 +143,7 @@ private function encodeAsSearch(OperatorInterface $value): stdClass
if ($key === 'operator') {
$val = $this->recursiveEncode($val);
assert($val instanceof stdClass);
foreach (get_object_vars($val) as $subkey => $subval) {
foreach ($val as $subkey => $subval) {
$result->{$subkey} = $subval;
}

Expand Down

0 comments on commit 661e969

Please sign in to comment.