Skip to content

Commit f9539b6

Browse files
committed
Simplify is_builder_pipeline
1 parent f3b4961 commit f9539b6

File tree

3 files changed

+5
-16
lines changed

3 files changed

+5
-16
lines changed

psalm-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@
890890
<MixedAssignment>
891891
<code><![CDATA[$element[$key]]]></code>
892892
<code><![CDATA[$stage]]></code>
893+
<code><![CDATA[$stage]]></code>
893894
<code><![CDATA[$type]]></code>
894895
<code><![CDATA[$typeMap['fieldPaths'][$fieldPath . '.' . $existingFieldPath]]]></code>
895896
<code><![CDATA[$typeMap['fieldPaths'][$fieldPath]]]></code>

src/functions.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -336,28 +336,17 @@ function is_pipeline(array|object $pipeline, bool $allowEmpty = false): bool
336336
*/
337337
function is_builder_pipeline(array $pipeline): bool
338338
{
339-
if (! $pipeline) {
339+
if (! $pipeline || ! array_is_list($pipeline)) {
340340
return false;
341341
}
342342

343-
if (! array_is_list($pipeline)) {
344-
return false;
345-
}
346-
347-
$result = false;
348343
foreach ($pipeline as $stage) {
349-
if (! is_array($stage) && ! is_object($stage)) {
350-
return false;
351-
}
352-
353-
if ($stage instanceof StageInterface) {
354-
$result = true;
355-
} elseif (! is_first_key_operator($stage)) {
356-
return false;
344+
if (is_object($stage) && $stage instanceof StageInterface) {
345+
return true;
357346
}
358347
}
359348

360-
return $result;
349+
return false;
361350
}
362351

363352
/**

tests/FunctionsTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ public function provideStagePipelines(): iterable
327327
yield 'map of stages' => [false, [1 => new MatchStage([])]];
328328
yield 'stages' => [true, [new MatchStage([]), new LimitStage(1)]];
329329
yield 'stages and operators' => [true, [new MatchStage([]), ['$limit' => 1]]];
330-
yield 'stages and invalid' => [false, [new MatchStage([]), ['foo' => 'bar']]];
331330
}
332331

333332
/** @dataProvider provideWriteConcerns */

0 commit comments

Comments
 (0)