Skip to content

Commit cdf0d5f

Browse files
committed
Fixing more PHPStan Issues
1 parent 685d4b9 commit cdf0d5f

File tree

8 files changed

+63
-31
lines changed

8 files changed

+63
-31
lines changed

.phpstan.neon

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
parameters:
2+
excludePaths:
3+
analyse:
4+
- vendor/*
5+
- include/vendor/*
6+
paths:
7+
- lib
8+
- include
9+
- install
10+
- .
11+
reportUnmatchedIgnoredErrors: false
12+
ignoreErrors:
13+
- identifier: missingType.iterableValue
14+
# PHPStan gets confused about dynamic constants
15+
- identifier: if.alwaysFalse
16+
- identifier: notEqual.alwaysFalse
17+
- identifier: notEqual.alwaysTrue
18+
- identifier: if.alwaysTrue
19+
- identifier: identical.alwaysTrue
20+
- identifier: identical.alwaysFalse
21+
- identifier: booleanAnd.leftAlwaysTrue
22+
- identifier: booleanAnd.leftAlwaysFalse
23+
# L9 - '/^Parameter #1 \$value of function strval expects bool\|float\|int\|resource\|string\|null, mixed given.$/'
24+
# L9 - '/^Parameter #1 \$value of function intval expects array\|bool\|float\|int\|resource\|string\|null, mixed given.$/'
25+
26+
27+
parallel:
28+
maximumNumberOfProcesses: 8

include/global_languages.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,12 +1021,12 @@ function read_user_i18n_setting(string $config_name): string|false {
10211021
* This function attempts to use the `NumberFormatter` class if available,
10221022
* otherwise it falls back to using PHP's `number_format` function with locale settings.
10231023
*
1024-
* @param float|int $number The number to format.
1024+
* @param mixed $number The number to format.
10251025
* @param int|null $decimals The number of decimal points. If null, defaults to 0.
1026-
* @param int $baseu The base unit for formatting large numbers (default is 1024).
1026+
* @param int|null $baseu The base unit for formatting large numbers (default is 1024).
10271027
* @return string The formatted number.
10281028
*/
1029-
function number_format_i18n(float|int $number, ?int $decimals = null, int $baseu = 1024): string {
1029+
function number_format_i18n(mixed $number, int $decimals = null, int $baseu = 1024): string {
10301030
global $cacti_locale, $cacti_country;
10311031

10321032
$country = strtoupper($cacti_country);

lib/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ function cache_common_config_settings():array {
681681
*
682682
* @return string|false|null The current value of the configuration option
683683
*/
684-
function read_config_option(string $config_name, bool $force = false):string|false|null {
684+
function read_config_option(string $config_name, bool $force = false): string|bool|null {
685685
global $config, $database_hostname, $database_default, $database_port, $database_sessions;
686686

687687
$loaded = false;

lib/html_form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ function form_callback($form_name, $classic_sql, $column_display, $column_id, $a
10631063
* @param string $form_caption - the text to display to the right of the checkbox
10641064
* @param string $form_default_value - the value of this form element to use if there is
10651065
* no current value available
1066-
* @param int $current_id - used to determine if a current value for this form element
1066+
* @param string|int $current_id - used to determine if a current value for this form element
10671067
* exists or not. a $current_id of '0' indicates that no current value exists,
10681068
* a non-zero value indicates that a current value does exist
10691069
* @param string $class - specify a css class

lib/html_utility.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ function form_selectable_cell(string $contents, int|string $id, string $width =
322322
}
323323

324324
print "\t<td " . $output . '>' . $wrapper . "</td>\n";
325+
326+
return true;
325327
}
326328

327329
function form_get_table_id(?bool $increment = false) {

user_admin.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ function user_realms_edit($header_label) {
15701570
unset($all_realms[$realm]);
15711571

15721572
print '<div class="flexChild">';
1573-
form_checkbox('section' . $realm, $old_value, $display, '', '', '', (!isempty_request_var('id') ? 1 : 0), $display, true);
1573+
form_checkbox('section' . $realm, $old_value, $display, '', '', '', '', $display, true);
15741574
print '</div>';
15751575
}
15761576
}
@@ -1621,7 +1621,7 @@ function user_realms_edit($header_label) {
16211621
}
16221622

16231623
print '<div class="flexChild">';
1624-
form_checkbox('section' . $realm, $old_value, $description, '', '', '', (!isempty_request_var('id') ? 1 : 0), $description, true);
1624+
form_checkbox('section' . $realm, $old_value, $description, '', '', '', '', $description, true);
16251625
print '</div>';
16261626
}
16271627

@@ -1677,7 +1677,7 @@ function user_realms_edit($header_label) {
16771677
}
16781678

16791679
print '<div class="flexChild">';
1680-
form_checkbox('section' . $realm, $old_value, trim(substr($local_user_auth_realms, $pos)), '', '', '', (!isempty_request_var('id') ? 1 : 0), $r['display'], true);
1680+
form_checkbox('section' . $realm, $old_value, trim(substr($local_user_auth_realms, $pos)), '', '', '', '', $r['display'], true);
16811681
print '</div>';
16821682
}
16831683

@@ -1706,7 +1706,7 @@ function user_realms_edit($header_label) {
17061706
$pos = (strpos($user_auth_realms[$realm], '->') !== false ? strpos($user_auth_realms[$realm], '->') + 2:0);
17071707

17081708
print '<div class="flexChild">';
1709-
form_checkbox('section' . $realm, $old_value, substr($user_auth_realms[$realm], $pos), '', '', '', (!isempty_request_var('id') ? 1 : 0), $r['display'], true);
1709+
form_checkbox('section' . $realm, $old_value, substr($user_auth_realms[$realm], $pos), '', '', '', '', $r['display'], true);
17101710
print '</div>';
17111711
}
17121712

user_group_admin.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@ function user_group_graph_perms_edit($tab, $header_label) {
721721
2 => __('Deny')
722722
];
723723

724+
$policy = [];
725+
724726
if (!isempty_request_var('id')) {
725727
$policy = db_fetch_row_prepared('SELECT policy_graphs, policy_trees, policy_hosts, policy_graph_templates
726728
FROM user_auth_group
@@ -1440,7 +1442,7 @@ function user_group_realms_edit($header_label) {
14401442
unset($all_realms[$realm]);
14411443

14421444
print '<div class="flexChild">';
1443-
form_checkbox('section' . $realm, $old_value, $display, '', '', '', (!isempty_request_var('id') ? 1 : 0), $display, true);
1445+
form_checkbox('section' . $realm, $old_value, $display, '', '', '', '', $display, true);
14441446
print '</div>';
14451447
}
14461448
}
@@ -1491,7 +1493,7 @@ function user_group_realms_edit($header_label) {
14911493
}
14921494

14931495
print '<div class="flexChild">';
1494-
form_checkbox('section' . $realm, $old_value, $description, '', '', '', (!isempty_request_var('id') ? 1 : 0), $description, true);
1496+
form_checkbox('section' . $realm, $old_value, $description, '', '', '', '', $description, true);
14951497
print '</div>';
14961498
}
14971499

@@ -1545,7 +1547,7 @@ function user_group_realms_edit($header_label) {
15451547
}
15461548

15471549
print '<div class="flexChild">';
1548-
form_checkbox('section' . $realm, $old_value, substr($user_auth_realms[$realm], $pos), '', '', '', (!isempty_request_var('id') ? 1 : 0), $r['display'], true);
1550+
form_checkbox('section' . $realm, $old_value, substr($user_auth_realms[$realm], $pos), '', '', '', '', $r['display'], true);
15491551
print '</div>';
15501552
}
15511553

@@ -1575,7 +1577,7 @@ function user_group_realms_edit($header_label) {
15751577
$pos = (strpos($user_auth_realms[$realm], '->') !== false ? strpos($user_auth_realms[$realm], '->') + 2:0);
15761578

15771579
print '<div class="flexChild">';
1578-
form_checkbox('section' . $realm, $old_value, substr($user_auth_realms[$realm], $pos), '', '', '', (!isempty_request_var('id') ? 1 : 0), $r['display'], true);
1580+
form_checkbox('section' . $realm, $old_value, substr($user_auth_realms[$realm], $pos), '', '', '', '', $r['display'], true);
15791581
print '</div>';
15801582
}
15811583

utilities.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,11 @@
5353
header('Location: utilities.php?action=view_poller_cache');
5454

5555
exit;
56-
57-
break;
5856
case 'rebuild_resource_cache':
5957
rebuild_resource_cache();
6058
header('Location: utilities.php');
6159

6260
exit;
63-
64-
break;
6561
case 'view_snmp_cache':
6662
top_header();
6763
utilities_view_snmp_cache();
@@ -127,8 +123,6 @@
127123
header('Location: utilities.php?action=view_snmpagent_cache');
128124

129125
exit;
130-
131-
break;
132126
case 'view_snmpagent_events':
133127
top_header();
134128
snmpagent_utilities_run_eventlog();
@@ -249,7 +243,7 @@ function create_data_query_filter($session_var) {
249243

250244
if ($host_id > 0) {
251245
/* for the templates dropdown */
252-
$sql_where = ($sql_where != '' ? ' AND ':'WHERE ') . 'h.id = ?';
246+
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . 'h.id = ?';
253247
$sql_params[] = $host_id;
254248

255249
$hostname = db_fetch_cell_prepared('SELECT description
@@ -265,7 +259,7 @@ function create_data_query_filter($session_var) {
265259
}
266260

267261
if (get_request_var('site_id') >= 0) {
268-
$sql_where = ($sql_where != '' ? ' AND ':'WHERE ') . 'site_id = ?';
262+
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . 'site_id = ?';
269263
$sql_params[] = get_filter_request_var('site_id');
270264
}
271265

@@ -1305,11 +1299,13 @@ function applyFilter() {
13051299
if (strcmp($engine, 'MEMORY') == 0) {
13061300
$max_length = db_fetch_cell('SELECT MAX(LENGTH(output)) FROM poller_output_boost');
13071301
} else {
1308-
$max_length = '0';
1302+
$max_length = 0;
13091303
}
13101304
db_execute("REPLACE INTO settings (name, value) VALUES ('boost_max_output_length', '" . time() . ':' . $max_length . "')");
1311-
} else {
1305+
} elseif (isset($parts[1])) {
13121306
$max_length = $parts[1];
1307+
} else {
1308+
$max_length = 0;
13131309
}
13141310

13151311
if ($max_length != 0) {
@@ -1338,13 +1334,17 @@ function applyFilter() {
13381334
html_section_header(__('Previous Runtime Statistics'), 2);
13391335

13401336
form_alternate_row();
1341-
print '<td class="utilityPick">' . __('Last Start Time:') . '</td><td>' . (is_numeric($last_run_time) ? date('Y-m-d H:i:s', $last_run_time):$last_run_time) . '</td>';
1337+
if (is_numeric($last_run_time)) {
1338+
print '<td class="utilityPick">' . __('Last Start Time:') . '</td><td>' . date('Y-m-d H:i:s', (int) $last_run_time) . '</td>';
1339+
} else {
1340+
print '<td class="utilityPick">' . __('Last Start Time:') . '</td><td>' . $last_run_time . '</td>';
1341+
}
13421342

13431343
/* get the last end time */
13441344
$last_end_time = read_config_option('boost_last_end_time', true);
13451345

13461346
form_alternate_row();
1347-
print '<td class="utilityPick">' . __('Last End Time:') . '</td><td>' . ($last_end_time != '' ? date('Y-m-d H:i:s', $last_end_time):__('Never Run')) . '</td>';
1347+
print '<td class="utilityPick">' . __('Last End Time:') . '</td><td>' . ($last_end_time != '' ? date('Y-m-d H:i:s', (int) $last_end_time):__('Never Run')) . '</td>';
13481348

13491349
form_alternate_row();
13501350
print '<td class="utilityPick">' . __('Last Run Duration:') . '</td><td>';
@@ -1353,7 +1353,7 @@ function applyFilter() {
13531353
print ($boost_last_run_duration > 60 ? __('%d minutes', (int)$boost_last_run_duration / 60) . ', ': '') . __('%d seconds', (int) $boost_last_run_duration % 60);
13541354

13551355
if ($rrd_updates != '') {
1356-
print ' (' . __('%0.2f percent of update frequency)', round(100 * $boost_last_run_duration / $update_interval / 60));
1356+
print ' (' . __('%0.2f percent of update frequency)', round(100 * (float) $boost_last_run_duration / (float) $update_interval / 60));
13571357
}
13581358
} else {
13591359
print __('N/A');
@@ -1461,7 +1461,7 @@ function applyFilter() {
14611461
print '<td class="utilityPick">' . __('Concurrent Processes:') . '</td><td>' . read_config_option('boost_parallel') . '</td>';
14621462

14631463
form_alternate_row();
1464-
print '<td class="utilityPick">' . __('Next Start Time:') . '</td><td>' . (is_numeric($next_run_time) ? date('Y-m-d H:i:s', $next_run_time):$next_run_time) . '</td>';
1464+
print '<td class="utilityPick">' . __('Next Start Time:') . '</td><td>' . (is_numeric($next_run_time) ? date('Y-m-d H:i:s', (int) $next_run_time):$next_run_time) . '</td>';
14651465

14661466
form_alternate_row();
14671467
print '<td class="utilityPick">' . __('Maximum Records:') . '</td><td>' . number_format_i18n($max_records) . ' ' . __('Records') . '</td>';
@@ -1565,14 +1565,14 @@ function draw_snmp_agent_cache_filter($render = false) {
15651565
/**
15661566
* snmpagent_utilities_run_cache()
15671567
*
1568-
* @param mixed
1569-
* @return
1568+
* @return void
15701569
*/
15711570
function snmpagent_utilities_run_cache() {
1572-
$mibs = db_fetch_assoc('SELECT DISTINCT mib FROM snmpagent_cache');
1571+
$mibs = db_fetch_assoc('SELECT DISTINCT mib FROM snmpagent_cache');
1572+
15731573
$registered_mibs = [];
15741574

1575-
if ($mibs && $mibs > 0) {
1575+
if (cacti_sizeof($mibs)) {
15761576
foreach ($mibs as $mib) {
15771577
$registered_mibs[] = $mib['mib'];
15781578
}

0 commit comments

Comments
 (0)