Skip to content

Commit c6e9e71

Browse files
KIKOmanasijevkikomanasijev
andauthored
[12.x] Use array_first and array_last polyfills (#56703)
* Use array_first and array_last polyfills * trigger tests * fix tests --------- Co-authored-by: kikomanasijev <hristijan.manasijev@nteams.com>
1 parent 7d7fe23 commit c6e9e71

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"symfony/mime": "^7.2.0",
5454
"symfony/polyfill-php83": "^1.31",
5555
"symfony/polyfill-php84": "^1.31",
56-
"symfony/polyfill-php85": "^1.31",
56+
"symfony/polyfill-php85": "^1.33",
5757
"symfony/process": "^7.2.0",
5858
"symfony/routing": "^7.2.0",
5959
"symfony/uid": "^7.2.0",

src/Illuminate/Collections/Arr.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ public static function first($array, ?callable $callback = null, $default = null
256256
return value($default);
257257
}
258258

259+
if (is_array($array)) {
260+
return array_first($array);
261+
}
262+
259263
foreach ($array as $item) {
260264
return $item;
261265
}
@@ -283,7 +287,7 @@ public static function first($array, ?callable $callback = null, $default = null
283287
public static function last($array, ?callable $callback = null, $default = null)
284288
{
285289
if (is_null($callback)) {
286-
return empty($array) ? value($default) : end($array);
290+
return empty($array) ? value($default) : array_last($array);
287291
}
288292

289293
return static::first(array_reverse($array, true), $callback, $default);

src/Illuminate/Testing/Constraints/HasInDatabase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class HasInDatabase extends Constraint
3434
*
3535
* @param \Illuminate\Database\Connection $database
3636
* @param array<string, mixed> $data
37+
* @return void
3738
*/
3839
public function __construct(Connection $database, array $data)
3940
{
@@ -81,7 +82,7 @@ protected function getAdditionalInfo($table)
8182

8283
$similarResults = $query->where(
8384
array_key_first($this->data),
84-
$this->data[array_key_first($this->data)]
85+
array_first($this->data),
8586
)->select(array_keys($this->data))->limit($this->show)->get();
8687

8788
if ($similarResults->isNotEmpty()) {

0 commit comments

Comments
 (0)