Skip to content

Commit ad73d8f

Browse files
authored
Rename ArArrayHelper::populate() to ArArrayHelper::index() (#348)
1 parent 4d6bcaf commit ad73d8f

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

src/ActiveQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public function populate(array $rows, Closure|string|null $indexBy = null): arra
275275
$this->addInverseRelations($models);
276276
}
277277

278-
return ArArrayHelper::populate($models, $indexBy);
278+
return ArArrayHelper::index($models, $indexBy);
279279
}
280280

281281
/**

src/ArArrayHelper.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ public static function getValueByPath(ActiveRecordInterface|array $array, string
9696
}
9797

9898
if (property_exists($array, $key)) {
99-
$values = get_object_vars($array);
100-
return array_key_exists($key, $values) ? $values[$key] : $default;
99+
return array_key_exists($key, get_object_vars($array)) ? $array->$key : $default;
101100
}
102101

103102
if ($array->isRelationPopulated($key)) {
@@ -118,7 +117,7 @@ public static function getValueByPath(ActiveRecordInterface|array $array, string
118117
}
119118

120119
/**
121-
* Populates an array of rows with the specified column value as keys.
120+
* Indexes an array of rows with the specified column value as keys.
122121
*
123122
* The input array should be multidimensional or an array of {@see ActiveRecordInterface} instances.
124123
*
@@ -144,7 +143,7 @@ public static function getValueByPath(ActiveRecordInterface|array $array, string
144143
*
145144
* @return array[]
146145
*/
147-
public static function populate(array $rows, Closure|string|null $indexBy = null): array
146+
public static function index(array $rows, Closure|string|null $indexBy = null): array
148147
{
149148
if ($indexBy === null) {
150149
return $rows;

0 commit comments

Comments
 (0)