From 2706fa7a451afe48bd4dc240d72d23fdcec0d9ef Mon Sep 17 00:00:00 2001 From: tsadpbb <90269351+tsadpbb@users.noreply.github.com> Date: Mon, 3 Feb 2025 09:49:05 -0600 Subject: [PATCH] Remove null coalescing operators (#1020) * Remove null coalescing operators * Add credit where credit is due --- Changelog | 1 + THANKS | 1 + html/includes/utils.inc.php | 60 ++++++++++++++----------------------- html/main.php | 2 +- html/side.php | 2 +- 5 files changed, 26 insertions(+), 40 deletions(-) diff --git a/Changelog b/Changelog index e72ec04aa..01c64eb65 100644 --- a/Changelog +++ b/Changelog @@ -5,6 +5,7 @@ Nagios Core 4 Change Log 4.5.10 - 2025-XX-XX ------------------- * Update quickstart and documentations links (Aaron Cieslicki) +* Remove null coalescing operators and fix some php errors (Dylan Anderson and Robert Högberg) 4.5.9 - 2024-12-19 ------------------ diff --git a/THANKS b/THANKS index bc71a82c1..a96a92cdd 100644 --- a/THANKS +++ b/THANKS @@ -291,6 +291,7 @@ wrong, please let me know. * Rob Remus * Robert August Vincent II * Robert Gash +* Robert Högberg * Robert Thompson * Roberto Marrodan * Robin Kearney diff --git a/html/includes/utils.inc.php b/html/includes/utils.inc.php index 6e7e6417c..3df459819 100644 --- a/html/includes/utils.inc.php +++ b/html/includes/utils.inc.php @@ -24,26 +24,18 @@ function get_update_information(){ ); // first read CGI config file to determine main file location - $ccfc=read_cgi_config_file(); - //print_r($ccfc); + $ccf=read_cgi_config_file(); + //print_r($ccf); // read main config file to determine file locations - if(isset($ccf['main_config_file'])) - $mcf=$ccf['main_config_file']; - else - $mcf=""; - $mcfc=read_main_config_file($mcf); - //print_r($mcfc); + $mcf = isset($ccf['main_config_file']) ? $ccf['main_config_file'] : ""; - if(isset($mcf['status_file'])) - $sf=$mcf['status_file']; - else - $sf=""; + $mcf=read_main_config_file($mcf); + //print_r($mcf); - if(isset($mcf['state_retention_file'])) - $rf=$mcf['state_retention_file']; - else - $rf=""; + $sf = isset($mcf['status_file']) ? $mcf['status_file'] : ""; + + $rf = isset($mcf['state_retention_file']) ? $mcf['state_retention_file'] : ""; /////////////////////////////////////////////// @@ -51,7 +43,7 @@ function get_update_information(){ /////////////////////////////////////////////// // are update checks enabled? - if(isset($mcfc['check_for_updates']) && $mcfc['check_for_updates']=="0") + if(isset($mcf['check_for_updates']) && $mcf['check_for_updates'] == "0") $updateinfo["update_checks_enabled"]=false; @@ -68,20 +60,17 @@ function get_update_information(){ if(isset($sfc['info']['last_update_check'])){ $updateinfo["last_update_check"]=$sfc['info']['last_update_check']; $updateinfo["found_update_info"]=true; - } + } // update available if(isset($sfc['info']['update_available'])){ - if($sfc['info']['update_available']=="1") - $updateinfo["update_available"]=true; - else - $updateinfo["update_available"]=false; - } + $updateinfo["update_available"] = $sfc['info']['update_available'] == "1"; + } // update version if(isset($sfc['info']['new_version'])){ $updateinfo["update_version"]=$sfc['info']['new_version']; - } + } // did we find update information in the status file? if so, we're done if($updateinfo["found_update_info"]==true) @@ -100,29 +89,24 @@ function get_update_information(){ //exit(); // last update time - if(isset($rfc['info']['last_update_check'])){ - $updateinfo["last_update_check"]=$rfc['info']['last_update_check']; - $updateinfo["found_update_info"]=true; - } + if(isset($rfc['info']['last_update_check'])) { + $updateinfo["last_update_check"] = $rfc['info']['last_update_check']; + $updateinfo["found_update_info"] = true; + } // update available - if(isset($rfc['info']['update_available'])){ - if($rfc['info']['update_available']=="1") - $updateinfo["update_available"]=true; - else - $updateinfo["update_available"]=false; - } + if(isset($rfc['info']['update_available'])) { + $updateinfo["update_available"] = $rfc['info']['update_available'] == "1"; + } // update version if(isset($rfc['info']['new_version'])){ $updateinfo["update_version"]=$rfc['info']['new_version']; - } + } return $updateinfo; - } - - +} //////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/html/main.php b/html/main.php index 15713f8d8..11df7d307 100644 --- a/html/main.php +++ b/html/main.php @@ -3,7 +3,7 @@ $this_version = '4.5.9'; $this_year = '2024'; -$theme = $cfg['theme'] ?? 'dark'; +$theme = isset($cfg['theme']) ? $cfg['theme'] : 'dark'; if ($theme != 'dark' && $theme != 'light') { $theme = 'dark'; } diff --git a/html/side.php b/html/side.php index 52f4bea6a..726e752f0 100644 --- a/html/side.php +++ b/html/side.php @@ -3,7 +3,7 @@ $this_version = '4.5.9'; $link_target = 'main'; -$theme = $cfg['theme'] ?? 'dark'; +$theme = isset($cfg['theme']) ? $cfg['theme'] : 'dark'; if ($theme != 'dark' && $theme != 'light') { $theme = 'dark'; }