Skip to content

A free open source IT asset/license management system

Fix Codacy warnings II

Lukas Kraicea447365fab0
diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php
index 49503f370f..d73068afe7 100755
--- a/app/Http/Controllers/ViewAssetsController.php
+++ b/app/Http/Controllers/ViewAssetsController.php
@@ -41,9 +41,9 @@ class ViewAssetsController extends Controller
if ($field->display_in_user_view == '1') {
$fieldArray[$field->db_column] = $field->name;
}
- } //end foreach
+ }//end foreach
}
- } //end foreach
+ }//end foreach
return array_unique($fieldArray);
}
@@ -70,7 +70,7 @@ class ViewAssetsController extends Controller
->get();
} else {
// Regular manager sees only their subordinates + self (recursive)
- $managedUsers = $authUser->getAllSubordinates(false); // Don't include self yet
+ $managedUsers = $authUser->getAllSubordinates();
// Only show dropdown if user actually has subordinates
if ($managedUsers->count() > 0) {
@@ -80,7 +80,7 @@ class ViewAssetsController extends Controller
} else {
// User has no subordinates, so they only see themselves
$subordinates = collect([$authUser]);
- } //end if
+ }//end if
}
// If the user has subordinates and a user_id is provided in the request
diff --git a/app/Models/User.php b/app/Models/User.php
index 43ff8fdf1f..affd76a729 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -961,20 +961,25 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
/**
* Get all direct and indirect subordinates for this user.
*
- * @param bool $includeSelf Include the current user in the results
* @return \Illuminate\Support\Collection
*/
- public function getAllSubordinates($includeSelf=false)
+ public function getAllSubordinates()
{
$subordinates = collect();
- if ($includeSelf) {
- $subordinates->push($this);
- }
-
- // Use a recursive helper function to avoid scope issues
$this->fetchSubordinatesRecursive($this, $subordinates);
+ return $subordinates->unique('id');
+ }
- return $subordinates->unique('id'); // Ensure uniqueness
+ /**
+ * Get all direct and indirect subordinates for this user, including self.
+ *
+ * @return \Illuminate\Support\Collection
+ */
+ public function getAllSubordinatesIncludingSelf()
+ {
+ $subordinates = collect([$this]);
+ $this->fetchSubordinatesRecursive($this, $subordinates);
+ return $subordinates->unique('id');
}
/**
@@ -995,7 +1000,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
// Recursive call for this subordinate's subordinates
$this->fetchSubordinatesRecursive($directSubordinate, $subs);
}
- } //end foreach
+ }//end foreach
}
/**