From 1bae31f0e6ab7d3a4307e3d8e3eec2c52f50de5a Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 25 May 2024 16:50:43 +0700 Subject: [PATCH] Rename `ArArrayHelper::populate()` to `ArArrayHelper::index()` --- src/ActiveQuery.php | 2 +- src/ArArrayHelper.php | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php index c9a0394ec..b68f9a808 100644 --- a/src/ActiveQuery.php +++ b/src/ActiveQuery.php @@ -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); } /** diff --git a/src/ArArrayHelper.php b/src/ArArrayHelper.php index 661623abb..391529ac3 100644 --- a/src/ArArrayHelper.php +++ b/src/ArArrayHelper.php @@ -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; } if ($array->isRelationPopulated($key)) { @@ -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. * @@ -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;