diff --git a/src/Illuminate/Collections/Arr.php b/src/Illuminate/Collections/Arr.php index cfc89dc39281..5c2dec1381c4 100644 --- a/src/Illuminate/Collections/Arr.php +++ b/src/Illuminate/Collections/Arr.php @@ -637,7 +637,7 @@ public static function join($array, $glue, $finalGlue = '') } if (count($array) === 1) { - return end($array); + return array_last($array); } $finalItem = array_pop($array); diff --git a/src/Illuminate/Collections/helpers.php b/src/Illuminate/Collections/helpers.php index 2203771da072..ed94004f47fc 100644 --- a/src/Illuminate/Collections/helpers.php +++ b/src/Illuminate/Collections/helpers.php @@ -203,7 +203,7 @@ function data_forget(&$target, $key) */ function head($array) { - return reset($array); + return empty($array) ? false : array_first($array); } } @@ -216,7 +216,7 @@ function head($array) */ function last($array) { - return end($array); + return empty($array) ? false : array_last($array); } } diff --git a/src/Illuminate/Console/Scheduling/Schedule.php b/src/Illuminate/Console/Scheduling/Schedule.php index 64e72c08903c..8d497fda1389 100644 --- a/src/Illuminate/Console/Scheduling/Schedule.php +++ b/src/Illuminate/Console/Scheduling/Schedule.php @@ -334,7 +334,7 @@ protected function mergePendingAttributes(Event $event) } if (! empty($this->groupStack)) { - $group = end($this->groupStack); + $group = array_last($this->groupStack); $group->mergeAttributes($event); } @@ -476,7 +476,7 @@ public function __call($method, $parameters) } if (method_exists(PendingEventAttributes::class, $method)) { - $this->attributes ??= end($this->groupStack) ?: new PendingEventAttributes($this); + $this->attributes ??= array_last($this->groupStack) ?: new PendingEventAttributes($this); return $this->attributes->$method(...$parameters); } diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index d8faaf228166..8d107f14e21d 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -1286,7 +1286,7 @@ protected function getParameterOverride($dependency) */ protected function getLastParameterOverride() { - return count($this->with) ? end($this->with) : []; + return count($this->with) ? array_last($this->with) : []; } /** @@ -1646,7 +1646,7 @@ protected function fireCallbackArray($object, array $callbacks) */ public function currentlyResolving() { - return end($this->buildStack) ?: null; + return array_last($this->buildStack) ?: null; } /** diff --git a/src/Illuminate/Database/Connection.php b/src/Illuminate/Database/Connection.php index c00987db53ae..4e09d21ee599 100755 --- a/src/Illuminate/Database/Connection.php +++ b/src/Illuminate/Database/Connection.php @@ -369,7 +369,7 @@ public function scalar($query, $bindings = [], $useReadPdo = true) throw new MultipleColumnsSelectedException; } - return reset($record); + return array_last($record); } /** diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index b53f26a2c699..0d524e47f480 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -507,7 +507,7 @@ public function fillForInsert(array $values) return []; } - if (! is_array(reset($values))) { + if (! is_array(array_first($values))) { $values = [$values]; } @@ -1265,12 +1265,12 @@ public function upsert(array $values, $uniqueBy, $update = null) return 0; } - if (! is_array(reset($values))) { + if (! is_array(array_first($values))) { $values = [$values]; } if (is_null($update)) { - $update = array_keys(reset($values)); + $update = array_keys(array_first($values)); } return $this->toBase()->upsert( @@ -1366,7 +1366,7 @@ protected function addUpdatedAtColumn(array $values) $segments = preg_split('/\s+as\s+/i', $this->query->from); - $qualifiedColumn = end($segments).'.'.$column; + $qualifiedColumn = array_last($segments).'.'.$column; $values[$qualifiedColumn] = Arr::get($values, $qualifiedColumn, $values[$column]); diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index 3f267914902c..3ec4200aee07 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -240,7 +240,7 @@ public function loadMissing($relations) } if (is_callable($value)) { - $path[count($segments) - 1][end($segments)] = $value; + $path[count($segments) - 1][array_last($segments)] = $value; } $this->loadMissingRelation($this, $path); diff --git a/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php b/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php index 66bc0044951b..c4c684d8e234 100755 --- a/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php @@ -291,7 +291,7 @@ public function updateOrCreate(array $attributes, array $values = []) */ public function upsert(array $values, $uniqueBy, $update = null) { - if (! empty($values) && ! is_array(reset($values))) { + if (! empty($values) && ! is_array(array_first($values))) { $values = [$values]; } @@ -581,7 +581,7 @@ public function getForeignKeyName() { $segments = explode('.', $this->getQualifiedForeignKeyName()); - return end($segments); + return array_last($segments); } /** diff --git a/src/Illuminate/Database/Eloquent/Relations/MorphOneOrMany.php b/src/Illuminate/Database/Eloquent/Relations/MorphOneOrMany.php index 6d6a34c31f38..aff262759dbf 100755 --- a/src/Illuminate/Database/Eloquent/Relations/MorphOneOrMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/MorphOneOrMany.php @@ -116,7 +116,7 @@ protected function setForeignAttributesForCreate(Model $model) */ public function upsert(array $values, $uniqueBy, $update = null) { - if (! empty($values) && ! is_array(reset($values))) { + if (! empty($values) && ! is_array(array_last($values))) { $values = [$values]; } diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 7c585a169533..b921164ef061 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -3130,7 +3130,7 @@ public function value($column) { $result = (array) $this->first([$column]); - return count($result) > 0 ? reset($result) : null; + return count($result) > 0 ? array_first($result) : null; } /** @@ -3142,7 +3142,7 @@ public function rawValue(string $expression, array $bindings = []) { $result = (array) $this->selectRaw($expression, $bindings)->first(); - return count($result) > 0 ? reset($result) : null; + return count($result) > 0 ? array_first($result) : null; } /** @@ -3158,7 +3158,7 @@ public function soleValue($column) { $result = (array) $this->sole([$column]); - return reset($result); + return array_last($result); } /** @@ -3781,7 +3781,7 @@ public function insert(array $values) return true; } - if (! is_array(reset($values))) { + if (! is_array(array_last($values))) { $values = [$values]; } @@ -3818,7 +3818,7 @@ public function insertOrIgnore(array $values) return 0; } - if (! is_array(reset($values))) { + if (! is_array(array_last($values))) { $values = [$values]; } else { foreach ($values as $key => $value) { @@ -3976,7 +3976,7 @@ public function upsert(array $values, array|string $uniqueBy, ?array $update = n return (int) $this->insert($values); } - if (! is_array(reset($values))) { + if (! is_array(array_last($values))) { $values = [$values]; } else { foreach ($values as $key => $value) { @@ -3987,7 +3987,7 @@ public function upsert(array $values, array|string $uniqueBy, ?array $update = n } if (is_null($update)) { - $update = array_keys(reset($values)); + $update = array_keys(array_last($values)); } $this->applyBeforeQueryCallbacks(); diff --git a/src/Illuminate/Database/Query/Grammars/Grammar.php b/src/Illuminate/Database/Query/Grammars/Grammar.php index 27effd7c4a34..6a42c4d7144e 100755 --- a/src/Illuminate/Database/Query/Grammars/Grammar.php +++ b/src/Illuminate/Database/Query/Grammars/Grammar.php @@ -430,9 +430,9 @@ protected function whereBetween(Builder $query, $where) { $between = $where['not'] ? 'not between' : 'between'; - $min = $this->parameter(is_array($where['values']) ? reset($where['values']) : $where['values'][0]); + $min = $this->parameter(is_array($where['values']) ? array_first($where['values']) : $where['values'][0]); - $max = $this->parameter(is_array($where['values']) ? end($where['values']) : $where['values'][1]); + $max = $this->parameter(is_array($where['values']) ? array_last($where['values']) : $where['values'][1]); return $this->wrap($where['column']).' '.$between.' '.$min.' and '.$max; } @@ -448,9 +448,9 @@ protected function whereBetweenColumns(Builder $query, $where) { $between = $where['not'] ? 'not between' : 'between'; - $min = $this->wrap(is_array($where['values']) ? reset($where['values']) : $where['values'][0]); + $min = $this->wrap(is_array($where['values']) ? array_first($where['values']) : $where['values'][0]); - $max = $this->wrap(is_array($where['values']) ? end($where['values']) : $where['values'][1]); + $max = $this->wrap(is_array($where['values']) ? array_last($where['values']) : $where['values'][1]); return $this->wrap($where['column']).' '.$between.' '.$min.' and '.$max; } @@ -466,9 +466,9 @@ protected function whereValueBetween(Builder $query, $where) { $between = $where['not'] ? 'not between' : 'between'; - $min = $this->wrap(is_array($where['columns']) ? reset($where['columns']) : $where['columns'][0]); + $min = $this->wrap(is_array($where['columns']) ? array_first($where['columns']) : $where['columns'][0]); - $max = $this->wrap(is_array($where['columns']) ? end($where['columns']) : $where['columns'][1]); + $max = $this->wrap(is_array($where['columns']) ? array_last($where['columns']) : $where['columns'][1]); return $this->parameter($where['value']).' '.$between.' '.$min.' and '.$max; } @@ -1186,11 +1186,11 @@ public function compileInsert(Builder $query, array $values) return "insert into {$table} default values"; } - if (! is_array(reset($values))) { + if (! is_array(array_last($values))) { $values = [$values]; } - $columns = $this->columnize(array_keys(reset($values))); + $columns = $this->columnize(array_keys(array_last($values))); // We need to build a list of parameter place-holders of values that are bound // to the query. Each insert should have the exact same number of parameter diff --git a/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php index 6426abbfde0f..6c3b2836b020 100755 --- a/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php @@ -415,7 +415,7 @@ protected function compileUpdateWithJoins(Builder $query, $table, $columns, $whe */ public function compileUpsert(Builder $query, array $values, array $uniqueBy, array $update) { - $columns = $this->columnize(array_keys(reset($values))); + $columns = $this->columnize(array_keys(array_last($values))); $sql = 'merge '.$this->wrapTable($query->from).' '; diff --git a/src/Illuminate/Database/Schema/Grammars/Grammar.php b/src/Illuminate/Database/Schema/Grammars/Grammar.php index 9e17e6204a36..8cadfec09219 100755 --- a/src/Illuminate/Database/Schema/Grammars/Grammar.php +++ b/src/Illuminate/Database/Schema/Grammars/Grammar.php @@ -387,7 +387,7 @@ protected function getCommandByName(Blueprint $blueprint, $name) $commands = $this->getCommandsByName($blueprint, $name); if (count($commands) > 0) { - return reset($commands); + return array_last($commands); } } diff --git a/src/Illuminate/Foundation/Console/BroadcastingInstallCommand.php b/src/Illuminate/Foundation/Console/BroadcastingInstallCommand.php index 6cc442e8c3c7..028825255c4d 100644 --- a/src/Illuminate/Foundation/Console/BroadcastingInstallCommand.php +++ b/src/Illuminate/Foundation/Console/BroadcastingInstallCommand.php @@ -341,7 +341,7 @@ protected function injectFrameworkSpecificConfiguration() file_put_contents($filePath, $newContents); } else { // Add Echo configuration after the last import... - $lastImport = end($matches[0]); + $lastImport = array_last($matches[0]); $positionOfLastImport = strrpos($contents, $lastImport); diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index b27fa3bc15a4..d006841f740a 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -294,7 +294,7 @@ function cache($key = null, $default = null) ); } - return app('cache')->put(key($key), reset($key), ttl: $default); + return app('cache')->put(key($key), array_first($key), ttl: $default); } } diff --git a/src/Illuminate/Routing/Router.php b/src/Illuminate/Routing/Router.php index 1ff7bc58d61a..29722dee62ed 100644 --- a/src/Illuminate/Routing/Router.php +++ b/src/Illuminate/Routing/Router.php @@ -509,7 +509,7 @@ protected function updateGroupStack(array $attributes) */ public function mergeWithLastGroup($new, $prependExistingPrefix = true) { - return RouteGroup::merge($new, end($this->groupStack), $prependExistingPrefix); + return RouteGroup::merge($new, array_last($this->groupStack), $prependExistingPrefix); } /** @@ -535,7 +535,7 @@ protected function loadRoutes($routes) public function getLastGroupPrefix() { if ($this->hasGroupStack()) { - $last = end($this->groupStack); + $last = array_last($this->groupStack); return $last['prefix'] ?? ''; } @@ -640,7 +640,7 @@ protected function convertToControllerAction($action) */ protected function prependGroupNamespace($class) { - $group = end($this->groupStack); + $group = array_last($this->groupStack); return isset($group['namespace']) && ! str_starts_with($class, '\\') && ! str_starts_with($class, $group['namespace']) ? $group['namespace'].'\\'.$class @@ -655,7 +655,7 @@ protected function prependGroupNamespace($class) */ protected function prependGroupController($class) { - $group = end($this->groupStack); + $group = array_last($this->groupStack); if (! isset($group['controller'])) { return $class; diff --git a/src/Illuminate/Support/Fluent.php b/src/Illuminate/Support/Fluent.php index 45fabc9c6b9d..2915f2e9d4ec 100755 --- a/src/Illuminate/Support/Fluent.php +++ b/src/Illuminate/Support/Fluent.php @@ -301,7 +301,7 @@ public function __call($method, $parameters) return $this->macroCall($method, $parameters); } - $this->attributes[$method] = count($parameters) > 0 ? reset($parameters) : true; + $this->attributes[$method] = count($parameters) > 0 ? array_last($parameters) : true; return $this; } diff --git a/src/Illuminate/Support/Reflector.php b/src/Illuminate/Support/Reflector.php index f5eb72f0fcdd..2ee9c5fee550 100644 --- a/src/Illuminate/Support/Reflector.php +++ b/src/Illuminate/Support/Reflector.php @@ -94,7 +94,7 @@ public static function getClassAttributes($objectOrClass, $attribute, $includePa )); } while ($includeParents && false !== $reflectionClass = $reflectionClass->getParentClass()); - return $includeParents ? new Collection($attributes) : reset($attributes); + return $includeParents ? new Collection($attributes) : array_first($attributes); } /**