-
Notifications
You must be signed in to change notification settings - Fork 11.6k
[12.x] Use array_first
and array_last
#56706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -507,7 +507,7 @@ public function fillForInsert(array $values) | |
return []; | ||
} | ||
|
||
if (! is_array(reset($values))) { | ||
if (! is_array(array_first($values))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here it is fine. |
||
$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]); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here it also seems to be swapped. IMO it should be |
||
$values = [$values]; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many in this file have had Is it intentional? |
||
} | ||
|
||
/** | ||
|
@@ -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(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here,
reset
is replaced witharray_last
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it seems to be an oversight. I guess it should be fixed.
Especially as the method description reads as "Run a select statement and return the first column of the first row."
ping @KIKOmanasijev