Skip to content

Commit 7d40750

Browse files
committed
Improve static analysis results
1 parent ba5c7b9 commit 7d40750

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

psalm-baseline.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
<MixedAssignment>
6464
<code><![CDATA[$result]]></code>
6565
<code><![CDATA[$result[]]]></code>
66+
<code><![CDATA[$subval]]></code>
67+
<code><![CDATA[$val]]></code>
6668
<code><![CDATA[$val]]></code>
6769
<code><![CDATA[$val]]></code>
6870
<code><![CDATA[$val]]></code>
@@ -168,6 +170,11 @@
168170
<code><![CDATA[stdClass]]></code>
169171
</TooManyTemplateParams>
170172
</file>
173+
<file src="src/Builder/Stage/VectorSearchStage.php">
174+
<MixedArgumentTypeCoercion>
175+
<code><![CDATA[$filter]]></code>
176+
</MixedArgumentTypeCoercion>
177+
</file>
171178
<file src="src/Builder/Type/QueryObject.php">
172179
<MixedAssignment>
173180
<code><![CDATA[$queries[$fieldPath]]]></code>

src/Builder/Encoder/OperatorEncoder.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,47 +115,49 @@ private function encodeAsGroup(OperatorInterface $value): stdClass
115115
return $this->wrap($value, $result);
116116
}
117117

118-
private function encodeAsSearch(OperatorInterface $value): stdClass
118+
private function encodeAsObject(OperatorInterface $value): stdClass
119119
{
120-
assert($value instanceof SearchStage || $value instanceof SearchMetaStage);
121-
122120
$result = new stdClass();
123121
foreach (get_object_vars($value) as $key => $val) {
124122
// Skip optional arguments. If they have a default value, it is resolved by the server.
125123
if ($val === Optional::Undefined) {
126124
continue;
127125
}
128126

129-
// Merge the operator properties into the result object
130-
if ($key === 'operator') {
131-
foreach (get_object_vars($this->recursiveEncode($val)) as $subkey => $subval) {
132-
$result->{$subkey} = $subval;
133-
}
134-
135-
continue;
136-
}
137-
138127
$result->{$key} = $this->recursiveEncode($val);
139128
}
140129

141-
return $this->wrap($value, $result);
130+
return $value::ENCODE === Encode::FlatObject
131+
? $result
132+
: $this->wrap($value, $result);
142133
}
143134

144-
private function encodeAsObject(OperatorInterface $value): stdClass
135+
private function encodeAsSearch(OperatorInterface $value): stdClass
145136
{
137+
assert($value instanceof SearchStage || $value instanceof SearchMetaStage);
138+
146139
$result = new stdClass();
147140
foreach (get_object_vars($value) as $key => $val) {
148141
// Skip optional arguments. If they have a default value, it is resolved by the server.
149142
if ($val === Optional::Undefined) {
150143
continue;
151144
}
152145

146+
// Merge the operator properties into the result object
147+
if ($key === 'operator') {
148+
$val = $this->recursiveEncode($val);
149+
assert($val instanceof stdClass);
150+
foreach (get_object_vars($val) as $subkey => $subval) {
151+
$result->{$subkey} = $subval;
152+
}
153+
154+
continue;
155+
}
156+
153157
$result->{$key} = $this->recursiveEncode($val);
154158
}
155159

156-
return $value::ENCODE === Encode::FlatObject
157-
? $result
158-
: $this->wrap($value, $result);
160+
return $this->wrap($value, $result);
159161
}
160162

161163
/**

0 commit comments

Comments
 (0)