Skip to content

Commit b345882

Browse files
committed
php8.5 - fix deprecated null array offset
1 parent 4a3622d commit b345882

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/SelectTree.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,8 @@ protected function buildTree(): Collection
206206

207207
private function buildTreeFromResults($results, $parent = null): Collection
208208
{
209-
// Assign the parent's null value to the $parent variable if it's not null
210-
if ($parent == null || $parent == $this->getParentNullValue()) {
211-
$parent = $this->getParentNullValue() ?? $parent;
212-
}
209+
// Assign the parent's null value to the $parent variable if it's not null or default to empty string
210+
$parent ??= $this->getParentNullValue() ?? '';
213211

214212
// Create a collection to store the tree
215213
$tree = collect();
@@ -232,7 +230,8 @@ private function buildTreeFromResults($results, $parent = null): Collection
232230
$resultMap[$resultKey] = $resultCache[$resultKey]['children'];
233231
unset($resultCache[$resultKey]['children']);
234232
}
235-
$parentKey = $result->{$this->getParentAttribute()};
233+
// Get the result's parent's key, defaulting to empty string for no parent
234+
$parentKey = $result->{$this->getParentAttribute()} ?? '';
236235
if (! isset($resultCache[$parentKey])) {
237236
// Before adding results to the map, cache the parentId to hold until the parent is confirmed to be in the result set
238237
$resultCache[$parentKey]['in_set'] = 0;

0 commit comments

Comments
 (0)