Use null coalescing operator

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2023-02-06 12:43:00 -08:00
parent b25676c96b
commit 6dc89fc2b0
3 changed files with 25 additions and 25 deletions

View file

@ -197,18 +197,18 @@ class LdapSync extends Command
for ($i = 0; $i < $results['count']; $i++) { for ($i = 0; $i < $results['count']; $i++) {
$item = []; $item = [];
$item['username'] = isset($results[$i][$ldap_result_username][0]) ? $results[$i][$ldap_result_username][0] : ''; $item['username'] = $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['employee_number'] = $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['lastname'] = $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['firstname'] = $results[$i][$ldap_result_first_name][0] ?? '';
$item['email'] = isset($results[$i][$ldap_result_email][0]) ? $results[$i][$ldap_result_email][0] : ''; $item['email'] = $results[$i][$ldap_result_email][0] ?? '';
$item['ldap_location_override'] = isset($results[$i]['ldap_location_override']) ? $results[$i]['ldap_location_override'] : ''; $item['ldap_location_override'] = $results[$i]['ldap_location_override'] ?? '';
$item['location_id'] = isset($results[$i]['location_id']) ? $results[$i]['location_id'] : ''; $item['location_id'] = $results[$i]['location_id'] ?? '';
$item['telephone'] = isset($results[$i][$ldap_result_phone][0]) ? $results[$i][$ldap_result_phone][0] : ''; $item['telephone'] = $results[$i][$ldap_result_phone][0] ?? '';
$item['jobtitle'] = isset($results[$i][$ldap_result_jobtitle][0]) ? $results[$i][$ldap_result_jobtitle][0] : ''; $item['jobtitle'] = $results[$i][$ldap_result_jobtitle][0] ?? '';
$item['country'] = isset($results[$i][$ldap_result_country][0]) ? $results[$i][$ldap_result_country][0] : ''; $item['country'] = $results[$i][$ldap_result_country][0] ?? '';
$item['department'] = isset($results[$i][$ldap_result_dept][0]) ? $results[$i][$ldap_result_dept][0] : ''; $item['department'] = $results[$i][$ldap_result_dept][0] ?? '';
$item['manager'] = isset($results[$i][$ldap_result_manager][0]) ? $results[$i][$ldap_result_manager][0] : ''; $item['manager'] = $results[$i][$ldap_result_manager][0] ?? '';
$department = Department::firstOrCreate([ $department = Department::firstOrCreate([

View file

@ -217,16 +217,16 @@ class Ldap extends Model
$ldap_result_manager = Setting::getSettings()->ldap_manager; $ldap_result_manager = Setting::getSettings()->ldap_manager;
// Get LDAP user data // Get LDAP user data
$item = []; $item = [];
$item['username'] = isset($ldapattributes[$ldap_result_username][0]) ? $ldapattributes[$ldap_result_username][0] : ''; $item['username'] = $ldapattributes[$ldap_result_username][0] ?? '';
$item['employee_number'] = isset($ldapattributes[$ldap_result_emp_num][0]) ? $ldapattributes[$ldap_result_emp_num][0] : ''; $item['employee_number'] = $ldapattributes[$ldap_result_emp_num][0] ?? '';
$item['lastname'] = isset($ldapattributes[$ldap_result_last_name][0]) ? $ldapattributes[$ldap_result_last_name][0] : ''; $item['lastname'] = $ldapattributes[$ldap_result_last_name][0] ?? '';
$item['firstname'] = isset($ldapattributes[$ldap_result_first_name][0]) ? $ldapattributes[$ldap_result_first_name][0] : ''; $item['firstname'] = $ldapattributes[$ldap_result_first_name][0] ?? '';
$item['email'] = isset($ldapattributes[$ldap_result_email][0]) ? $ldapattributes[$ldap_result_email][0] : ''; $item['email'] = $ldapattributes[$ldap_result_email][0] ?? '';
$item['telephone'] = isset($ldapattributes[$ldap_result_phone][0]) ? $ldapattributes[$ldap_result_phone][0] : ''; $item['telephone'] = $ldapattributes[$ldap_result_phone][0] ?? '';
$item['jobtitle'] = isset($ldapattributes[$ldap_result_jobtitle][0]) ? $ldapattributes[$ldap_result_jobtitle][0] : ''; $item['jobtitle'] = $ldapattributes[$ldap_result_jobtitle][0] ?? '';
$item['country'] = isset($ldapattributes[$ldap_result_country][0]) ? $ldapattributes[$ldap_result_country][0] : ''; $item['country'] = $ldapattributes[$ldap_result_country][0] ?? '';
$item['department'] = isset($ldapattributes[$ldap_result_dept][0]) ? $ldapattributes[$ldap_result_dept][0] : ''; $item['department'] = $ldapattributes[$ldap_result_dept][0] ?? '';
$item['manager'] = isset($ldapattributes[$ldap_result_manager][0]) ? $ldapattributes[$ldap_result_manager][0] : ''; $item['manager'] = $ldapattributes[$ldap_result_manager][0] ?? '';
return $item; return $item;
} }

View file

@ -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 // 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') { 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() private function getSearchableAttributes()
{ {
return isset($this->searchableAttributes) ? $this->searchableAttributes : []; return $this->searchableAttributes ?? [];
} }
/** /**
@ -205,7 +205,7 @@ trait Searchable
*/ */
private function getSearchableRelations() private function getSearchableRelations()
{ {
return isset($this->searchableRelations) ? $this->searchableRelations : []; return $this->searchableRelations ?? [];
} }
/** /**