Skip to content

Commit

Permalink
Rename ArArrayHelper::populate() to ArArrayHelper::index()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed May 25, 2024
1 parent 4d6bcaf commit 1bae31f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
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 @@ public static function getValueByPath(ActiveRecordInterface|array $array, string
}

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 @@ public static function getValueByPath(ActiveRecordInterface|array $array, string
}

/**
* 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 @@ public static function getValueByPath(ActiveRecordInterface|array $array, string
*
* @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

0 comments on commit 1bae31f

Please sign in to comment.