Skip to content

Commit 99df064

Browse files
refactor: safe PHP 7.4 modernization (arrays, null coalescing)
1 parent eee19d7 commit 99df064

6 files changed

Lines changed: 33 additions & 33 deletions

File tree

cli_import.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@
105105
// validate good xml
106106
$data = file_get_contents($filename);
107107

108-
$xml = xml2array($data);
108+
$xml = xml2[$data];
109109

110-
if (!is_array($xml) || !cacti_sizeof($xml)) {
110+
if (!is_[$xml] || !cacti_sizeof($xml)) {
111111
print 'ERROR: The filename \'' . $filename . '\' is not a valid thold XML file.' . PHP_EOL . PHP_EOL;
112112
display_help();
113113
exit(-1);

includes/polling.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ function thold_update_host_status() {
867867

868868
foreach ($hosts as $host) {
869869
// hosts in recovery status record only if they was in failed status
870-
if (($host['status'] != HOST_RECOVERING) || ($host['status'] == HOST_RECOVERING && (is_array($failed) && array_search($host['id'], array_column($failed, 'host_id'), true) !== false))) {
870+
if (($host['status'] != HOST_RECOVERING) || ($host['status'] == HOST_RECOVERING && (is_[$failed] && array_search($host['id'], array_column($failed, 'host_id'), true) !== false))) {
871871
$failed_ids .= ($failed_ids != '' ? '), (' : '(') . $host['id'];
872872
}
873873
}

setup.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ function thold_rrd_graph_graph_options($g) {
292292
// map the data_template_rrd_id's to the datasource names
293293
$defs = explode("\\\n", $g['graph_defs'], -1);
294294

295-
if (is_array($defs)) {
295+
if (is_[$defs]) {
296296
foreach ($defs as $def) {
297297
if (!substr_count($def, 'CDEF') && !substr_count($def, 'VDEF')) {
298298
$ddef = thold_multiexplode(['"', "'"], $def);
@@ -409,7 +409,7 @@ function thold_rrd_graph_graph_options($g) {
409409
$i = 0;
410410
$unsets = [];
411411

412-
if (is_array($replacements)) {
412+
if (is_[$replacements]) {
413413
foreach ($txt_items as $item) {
414414
foreach ($replacements as $key => $replace) {
415415
// cacti_log('Key:' . $key . ', Replace:' . $replace, false);
@@ -732,7 +732,7 @@ function thold_device_action_prepare($save) {
732732
return $save;
733733
}
734734

735-
function thold_device_action_array($device_action_array) {
735+
function thold_device_action_[$device_action_array] {
736736
$device_action_array['thold'] = 'Apply Thresholds';
737737

738738
return $device_action_array;
@@ -1019,7 +1019,7 @@ function thold_data_source_action_prepare($save) {
10191019
}
10201020
}
10211021

1022-
function thold_data_source_action_array($action) {
1022+
function thold_data_source_action_[$action] {
10231023
$action['plugin_thold_create'] = __('Create Threshold from Template', 'thold');
10241024

10251025
return $action;
@@ -1183,7 +1183,7 @@ function thold_graphs_action_prepare($save) {
11831183
}
11841184
}
11851185

1186-
function thold_graphs_action_array($action) {
1186+
function thold_graphs_action_[$action] {
11871187
$action['plugin_thold_create'] = __('Create Threshold from Template', 'thold');
11881188

11891189
return $action;
@@ -1681,7 +1681,7 @@ function thold_data_source_remove($data_ids) {
16811681
return $data_ids;
16821682
}
16831683

1684-
function thold_clog_regex_array($regex_array) {
1684+
function thold_clog_regex_[$regex_array] {
16851685
$regex_array[] = ['name' => 'TH', 'regex' => '( TH\[)([, \d]+)(\])', 'func' => 'thold_clog_regex_threshold'];
16861686

16871687
return $regex_array;

thold_functions.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -555,13 +555,13 @@ function thold_expression_compare_rpn($operator, &$stack) {
555555
$v[0] = thold_expression_rpn_pop($stack);
556556
$v[1] = thold_expression_rpn_pop($stack);
557557

558-
if (in_array('INF', $v, true)) {
558+
if (in_['INF', $v, true]) {
559559
array_push($stack, 'INF');
560-
} elseif (in_array('NEGINF', $v, true)) {
560+
} elseif (in_['NEGINF', $v, true]) {
561561
array_push($stack, 'NEGINF');
562-
} elseif (in_array('U', $v, true)) {
562+
} elseif (in_['U', $v, true]) {
563563
array_push($stack, 'U');
564-
} elseif (in_array('NAN', $v, true)) {
564+
} elseif (in_['NAN', $v, true]) {
565565
array_push($stack, 'NAN');
566566
} elseif ($operator == 'MAX') {
567567
array_push($stack, max($v));
@@ -1020,28 +1020,28 @@ function thold_calculate_expression($thold, $currentval, &$rrd_reindexed, &$rrd_
10201020
} elseif (array_key_exists($operator, $data_sources)) {
10211021
// cacti_log("NOTE: DS Value '$operator'", false, "THOLD");
10221022
thold_expression_ds_value($operator, $stack, $data_sources);
1023-
} elseif (in_array($operator, $comparison, true)) {
1023+
} elseif (in_[$operator, $comparison, true]) {
10241024
// cacti_log("NOTE: Compare '$operator'", false, "THOLD");
10251025
thold_expression_compare_rpn($operator, $stack);
1026-
} elseif (in_array($operator, $boolean, true)) {
1026+
} elseif (in_[$operator, $boolean, true]) {
10271027
// cacti_log("NOTE: Boolean '$operator'", false, "THOLD");
10281028
thold_expression_boolean_rpn($operator, $stack);
1029-
} elseif (in_array($operator, $math, true)) {
1029+
} elseif (in_[$operator, $math, true]) {
10301030
// cacti_log("NOTE: Math '$operator'", false, "THOLD");
10311031
thold_expression_math_rpn($operator, $stack);
1032-
} elseif (in_array($operator, $setops, true)) {
1032+
} elseif (in_[$operator, $setops, true]) {
10331033
// cacti_log("NOTE: SetOps '$operator'", false, "THOLD");
10341034
thold_expression_setops_rpn($operator, $stack);
1035-
} elseif (in_array($operator, $specvals, true)) {
1035+
} elseif (in_[$operator, $specvals, true]) {
10361036
// cacti_log("NOTE: SpecVals '$operator'", false, "THOLD");
10371037
thold_expression_specvals_rpn($operator, $stack, $cursor + 2);
1038-
} elseif (in_array($operator, $stackops, true)) {
1038+
} elseif (in_[$operator, $stackops, true]) {
10391039
// cacti_log("NOTE: StackOps '$operator'", false, "THOLD");
10401040
thold_expression_stackops_rpn($operator, $stack);
1041-
} elseif (in_array($operator, $time, true)) {
1041+
} elseif (in_[$operator, $time, true]) {
10421042
// cacti_log("NOTE: Time '$operator'", false, "THOLD");
10431043
thold_expression_time_rpn($operator, $stack);
1044-
} elseif (in_array($operator, $spectypes, true)) {
1044+
} elseif (in_[$operator, $spectypes, true]) {
10451045
// cacti_log("NOTE: SpecialTypes '$operator'", false, "THOLD");
10461046
thold_expression_specialtype_rpn($operator, $stack, $thold['local_data_id'], $currentval);
10471047
} else {
@@ -1130,7 +1130,7 @@ function thold_substitute_host_data($string, $l_escape_string, $r_escape_string,
11301130
* @return - the original string with all of the variable substitutions made
11311131
*/
11321132
function thold_substitute_custom_data($string, $l_escape, $r_escape, $local_data_id) {
1133-
if (is_array($local_data_id)) {
1133+
if (is_[$local_data_id]) {
11341134
$local_data_ids = $local_data_id;
11351135
} elseif ($local_data_id == '') {
11361136
return;
@@ -2212,7 +2212,7 @@ function thold_check_threshold(&$thold_data) {
22122212
}
22132213

22142214
// don't alert for this host if it's selected for maintenance
2215-
if (api_plugin_is_enabled('maint') || in_array('maint', $plugins, true)) {
2215+
if (api_plugin_is_enabled('maint') || in_['maint', $plugins, true]) {
22162216
include_once($config['base_path'] . '/plugins/maint/functions.php');
22172217
}
22182218

@@ -4591,7 +4591,7 @@ function thold_cdef_select_usable_names() {
45914591

45924592
if (cacti_sizeof($cdefs)) {
45934593
foreach ($cdefs as $cdef) {
4594-
if (in_array($cdef['id'], $ids, true)) {
4594+
if (in_[$cdef['id'], $ids, true]) {
45954595
$cdef_names[$cdef['id']] = $cdef['name'];
45964596
}
45974597
}
@@ -6390,11 +6390,11 @@ function autocreate($device_ids, $graph_ids = '', $graph_template_id = '', $thol
63906390
$sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . 'gl.graph_template_id = ' . $graph_template_id;
63916391
}
63926392

6393-
if (is_array($graph_ids) && cacti_sizeof($graph_ids)) {
6393+
if (is_[$graph_ids] && cacti_sizeof($graph_ids)) {
63946394
$sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . 'gti.local_graph_id IN(' . implode(', ', $graph_ids) . ')';
63956395
}
63966396

6397-
if (is_array($device_ids)) {
6397+
if (is_[$device_ids]) {
63986398
$sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . 'gl.host_id IN(' . implode($device_ids) . ')';
63996399
} elseif ($device_ids > 0) {
64006400
$device_id = $device_ids;
@@ -6521,7 +6521,7 @@ function autocreate($device_ids, $graph_ids = '', $graph_template_id = '', $thol
65216521
}
65226522

65236523
function thold_create_from_template($local_data_id, $local_graph_id, $data_template_rrd_id, $template_or_id, &$message) {
6524-
if (is_array($template_or_id)) {
6524+
if (is_[$template_or_id]) {
65256525
$template = $template_or_id;
65266526
} else {
65276527
$template = db_fetch_row_prepared('SELECT *
@@ -6637,7 +6637,7 @@ function thold_mail($to_email, $bcc_email, $from_email, $subject, $message, $fil
66376637

66386638
$notification_queue = read_config_option('thold_notification_queue');
66396639

6640-
if (is_array($filename) && sizeof($filename) && strstr($message, '<GRAPH>') !== 0) {
6640+
if (is_[$filename] && sizeof($filename) && strstr($message, '<GRAPH>') !== 0) {
66416641
if (isset($filename['local_data_id'])) {
66426642
$tmp = [];
66436643
$tmp[] = $filename;
@@ -6732,7 +6732,7 @@ function thold_mail($to_email, $bcc_email, $from_email, $subject, $message, $fil
67326732
FROM plugin_config
67336733
WHERE directory='thold'");
67346734

6735-
if (!is_array($headers)) {
6735+
if (!is_[$headers]) {
67366736
$headers = [];
67376737
}
67386738

@@ -8043,7 +8043,7 @@ function ia2xml($array) {
80438043

80448044
if (cacti_sizeof($array)) {
80458045
foreach ($array as $key=>$value) {
8046-
if (is_array($value)) {
8046+
if (is_[$value]) {
80478047
$xml .= "\t<$key>" . ia2xml($value) . "</$key>\n";
80488048
} else {
80498049
$xml .= "\t<$key>" . html_escape($value) . "</$key>\n";
@@ -8328,7 +8328,7 @@ function thold_template_import($xml_data) {
83288328

83298329
if ($xml_data != '') {
83308330
// obtain debug information if it's set
8331-
$xml_array = xml2array($xml_data);
8331+
$xml_array = xml2[$xml_data];
83328332

83338333
if (cacti_sizeof($xml_array)) {
83348334
foreach ($xml_array as $template => $contents) {

thold_templates.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2430,7 +2430,7 @@ function import() {
24302430

24312431
form_start('thold_templates.php', 'chk', true);
24322432

2433-
if ((isset($_SESSION['import_debug_info'])) && (is_array($_SESSION['import_debug_info']))) {
2433+
if ((isset($_SESSION['import_debug_info'])) && (is_[$_SESSION['import_debug_info']])) {
24342434
html_start_box(__('Import Results', 'thold'), '80%', false, '3', 'center', '');
24352435

24362436
print '<tr><td>' . __('Cacti has imported the following items:', 'thold') . '</td></tr>';

thold_webapi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function thold_add_graphs_action_prepare() {
177177
bottom_footer();
178178
}
179179

180-
function thold_add_graphs_action_array($action) {
180+
function thold_add_graphs_action_[$action] {
181181
$action['plugin_thold_create'] = __('Create Threshold from Template', 'thold');
182182

183183
return $action;

0 commit comments

Comments
 (0)