Skip to content
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

Rename ArArrayHelper::populate() to ArArrayHelper::index() #348

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public function populate(array $rows, Closure|string|null $indexBy = null): arra
$this->addInverseRelations($models);
}

return ArArrayHelper::populate($models, $indexBy);
return ArArrayHelper::index($models, $indexBy);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/ArArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@
}

if (property_exists($array, $key)) {
$values = get_object_vars($array);
return array_key_exists($key, $values) ? $values[$key] : $default;
return array_key_exists($key, get_object_vars($array)) ? $array->$key : $default;

Check warning on line 99 in src/ArArrayHelper.php

View check run for this annotation

Codecov / codecov/patch

src/ArArrayHelper.php#L99

Added line #L99 was not covered by tests
}

if ($array->isRelationPopulated($key)) {
Expand All @@ -118,7 +117,7 @@
}

/**
* Populates an array of rows with the specified column value as keys.
* Indexes an array of rows with the specified column value as keys.
*
* The input array should be multidimensional or an array of {@see ActiveRecordInterface} instances.
*
Expand All @@ -144,7 +143,7 @@
*
* @return array[]
*/
public static function populate(array $rows, Closure|string|null $indexBy = null): array
public static function index(array $rows, Closure|string|null $indexBy = null): array
{
if ($indexBy === null) {
return $rows;
Expand Down
Loading