Skip to content

Commit 316d6d6

Browse files
authored
PHPLIB-1161: Leverage array_key_first in functions (#1101)
1 parent c0738eb commit 316d6d6

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

src/functions.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@
4141
use function is_array;
4242
use function is_object;
4343
use function is_string;
44-
use function key;
4544
use function MongoDB\BSON\fromPHP;
4645
use function MongoDB\BSON\toPHP;
47-
use function reset;
4846
use function substr;
4947

5048
/**
@@ -319,11 +317,9 @@ function is_last_pipeline_operator_write(array $pipeline): bool
319317
return false;
320318
}
321319

322-
$lastOp = document_to_array($lastOp);
320+
$key = array_key_first(document_to_array($lastOp));
323321

324-
reset($lastOp);
325-
326-
return key($lastOp) === '$merge' || key($lastOp) === '$out';
322+
return $key === '$merge' || $key === '$out';
327323
}
328324

329325
/**
@@ -341,11 +337,7 @@ function is_mapreduce_output_inline($out): bool
341337
return false;
342338
}
343339

344-
$out = document_to_array($out);
345-
346-
reset($out);
347-
348-
return key($out) === 'inline';
340+
return array_key_first(document_to_array($out)) === 'inline';
349341
}
350342

351343
/**

0 commit comments

Comments
 (0)