Skip to content

Commit 9149af2

Browse files
committed
Extract $result->{$this->getCustomKey()} to variable
1 parent ad4ce0d commit 9149af2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/SelectTree.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,21 @@ private function buildTreeFromResults($results, $parent = null): Collection
183183

184184
private function buildNode($result, $resultMap, $disabledOptions, $hiddenOptions): array
185185
{
186+
$key = $result->{$this->getCustomKey()};
187+
186188
// Create a node with 'name' and 'value' attributes
187189
$node = [
188190
'name' => $result->{$this->getTitleAttribute()},
189-
'value' => $result->{$this->getCustomKey()},
190-
'disabled' => in_array($result->{$this->getCustomKey()}, $disabledOptions),
191-
'hidden' => in_array($result->{$this->getCustomKey()}, $hiddenOptions),
191+
'value' => $key,
192+
'disabled' => in_array($key, $disabledOptions),
193+
'hidden' => in_array($key, $hiddenOptions),
192194
];
193195

194196
// Check if the result has children
195-
if (isset($resultMap[$result->{$this->getCustomKey()}])) {
197+
if (isset($resultMap[$key])) {
196198
$children = collect();
197199
// Recursively build child nodes
198-
foreach ($resultMap[$result->{$this->getCustomKey()}] as $child) {
200+
foreach ($resultMap[$key] as $child) {
199201
// don't add the hidden ones
200202
if (in_array($child->{$this->getCustomKey()}, $hiddenOptions)) {
201203
continue;

0 commit comments

Comments
 (0)