Skip to content

A free open source IT asset/license management system

Use null coalescing operator

snipe1651dbb68d52
diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php
index c2d7446934..13a1ee2d3f 100755
--- a/app/Console/Commands/LdapSync.php
+++ b/app/Console/Commands/LdapSync.php
@@ -197,18 +197,18 @@ class LdapSync extends Command
for ($i = 0; $i < $results['count']; $i++) {
$item = [];
- $item['username'] = isset($results[$i][$ldap_result_username][0]) ? $results[$i][$ldap_result_username][0] : '';
- $item['employee_number'] = isset($results[$i][$ldap_result_emp_num][0]) ? $results[$i][$ldap_result_emp_num][0] : '';
- $item['lastname'] = isset($results[$i][$ldap_result_last_name][0]) ? $results[$i][$ldap_result_last_name][0] : '';
- $item['firstname'] = isset($results[$i][$ldap_result_first_name][0]) ? $results[$i][$ldap_result_first_name][0] : '';
- $item['email'] = isset($results[$i][$ldap_result_email][0]) ? $results[$i][$ldap_result_email][0] : '';
- $item['ldap_location_override'] = isset($results[$i]['ldap_location_override']) ? $results[$i]['ldap_location_override'] : '';
- $item['location_id'] = isset($results[$i]['location_id']) ? $results[$i]['location_id'] : '';
- $item['telephone'] = isset($results[$i][$ldap_result_phone][0]) ? $results[$i][$ldap_result_phone][0] : '';
- $item['jobtitle'] = isset($results[$i][$ldap_result_jobtitle][0]) ? $results[$i][$ldap_result_jobtitle][0] : '';
- $item['country'] = isset($results[$i][$ldap_result_country][0]) ? $results[$i][$ldap_result_country][0] : '';
- $item['department'] = isset($results[$i][$ldap_result_dept][0]) ? $results[$i][$ldap_result_dept][0] : '';
- $item['manager'] = isset($results[$i][$ldap_result_manager][0]) ? $results[$i][$ldap_result_manager][0] : '';
+ $item['username'] = $results[$i][$ldap_result_username][0] ?? '';
+ $item['employee_number'] = $results[$i][$ldap_result_emp_num][0] ?? '';
+ $item['lastname'] = $results[$i][$ldap_result_last_name][0] ?? '';
+ $item['firstname'] = $results[$i][$ldap_result_first_name][0] ?? '';
+ $item['email'] = $results[$i][$ldap_result_email][0] ?? '';
+ $item['ldap_location_override'] = $results[$i]['ldap_location_override'] ?? '';
+ $item['location_id'] = $results[$i]['location_id'] ?? '';
+ $item['telephone'] = $results[$i][$ldap_result_phone][0] ?? '';
+ $item['jobtitle'] = $results[$i][$ldap_result_jobtitle][0] ?? '';
+ $item['country'] = $results[$i][$ldap_result_country][0] ?? '';
+ $item['department'] = $results[$i][$ldap_result_dept][0] ?? '';
+ $item['manager'] = $results[$i][$ldap_result_manager][0] ?? '';
$department = Department::firstOrCreate([
diff --git a/app/Models/Ldap.php b/app/Models/Ldap.php
index 4c47147625..a29581bf97 100644
--- a/app/Models/Ldap.php
+++ b/app/Models/Ldap.php
@@ -217,16 +217,16 @@ class Ldap extends Model
$ldap_result_manager = Setting::getSettings()->ldap_manager;
// Get LDAP user data
$item = [];
- $item['username'] = isset($ldapattributes[$ldap_result_username][0]) ? $ldapattributes[$ldap_result_username][0] : '';
- $item['employee_number'] = isset($ldapattributes[$ldap_result_emp_num][0]) ? $ldapattributes[$ldap_result_emp_num][0] : '';
- $item['lastname'] = isset($ldapattributes[$ldap_result_last_name][0]) ? $ldapattributes[$ldap_result_last_name][0] : '';
- $item['firstname'] = isset($ldapattributes[$ldap_result_first_name][0]) ? $ldapattributes[$ldap_result_first_name][0] : '';
- $item['email'] = isset($ldapattributes[$ldap_result_email][0]) ? $ldapattributes[$ldap_result_email][0] : '';
- $item['telephone'] = isset($ldapattributes[$ldap_result_phone][0]) ? $ldapattributes[$ldap_result_phone][0] : '';
- $item['jobtitle'] = isset($ldapattributes[$ldap_result_jobtitle][0]) ? $ldapattributes[$ldap_result_jobtitle][0] : '';
- $item['country'] = isset($ldapattributes[$ldap_result_country][0]) ? $ldapattributes[$ldap_result_country][0] : '';
- $item['department'] = isset($ldapattributes[$ldap_result_dept][0]) ? $ldapattributes[$ldap_result_dept][0] : '';
- $item['manager'] = isset($ldapattributes[$ldap_result_manager][0]) ? $ldapattributes[$ldap_result_manager][0] : '';
+ $item['username'] = $ldapattributes[$ldap_result_username][0] ?? '';
+ $item['employee_number'] = $ldapattributes[$ldap_result_emp_num][0] ?? '';
+ $item['lastname'] = $ldapattributes[$ldap_result_last_name][0] ?? '';
+ $item['firstname'] = $ldapattributes[$ldap_result_first_name][0] ?? '';
+ $item['email'] = $ldapattributes[$ldap_result_email][0] ?? '';
+ $item['telephone'] = $ldapattributes[$ldap_result_phone][0] ?? '';
+ $item['jobtitle'] = $ldapattributes[$ldap_result_jobtitle][0] ?? '';
+ $item['country'] = $ldapattributes[$ldap_result_country][0] ?? '';
+ $item['department'] = $ldapattributes[$ldap_result_dept][0] ?? '';
+ $item['manager'] = $ldapattributes[$ldap_result_manager][0] ?? '';
return $item;
}
diff --git a/app/Models/Traits/Searchable.php b/app/Models/Traits/Searchable.php
index db46e305df..a7feb62957 100644
--- a/app/Models/Traits/Searchable.php
+++ b/app/Models/Traits/Searchable.php
@@ -164,7 +164,7 @@ trait Searchable
}
// I put this here because I only want to add the concat one time in the end of the user relation search
if($relation == 'user') {
- $query->orWhereRaw('CONCAT (users.first_name, " ", users.last_name) LIKE ?', ["%$term%"]);
+ $query->orWhereRaw('CONCAT (users.first_name, " ", users.last_name) LIKE ?', ["%{$term}%"]);
}
});
}
@@ -195,7 +195,7 @@ trait Searchable
*/
private function getSearchableAttributes()
{
- return isset($this->searchableAttributes) ? $this->searchableAttributes : [];
+ return $this->searchableAttributes ?? [];
}
/**
@@ -205,7 +205,7 @@ trait Searchable
*/
private function getSearchableRelations()
{
- return isset($this->searchableRelations) ? $this->searchableRelations : [];
+ return $this->searchableRelations ?? [];
}
/**