Skip to content

refactor: safe PHP 7.4 modernization#91

Draft
somethingwithproof wants to merge 4 commits into
Cacti:developfrom
somethingwithproof:refactor/modernization
Draft

refactor: safe PHP 7.4 modernization#91
somethingwithproof wants to merge 4 commits into
Cacti:developfrom
somethingwithproof:refactor/modernization

Conversation

@somethingwithproof
Copy link
Copy Markdown
Contributor

This PR adds strict typing, short array syntax, and null coalescing operators across the plugin. Standalone infrastructure files were removed per architectural mandate.

Copilot AI review requested due to automatic review settings April 9, 2026 21:15
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes the GPSMap plugin’s PHP codebase for PHP 7.4 by enabling strict typing and updating older PHP syntax (notably array literals) across runtime and setup/polling/test entrypoints.

Changes:

  • Added declare(strict_types=1); across many plugin PHP files.
  • Replaced long array(...) syntax with short [...] syntax in several code paths.
  • Updated miscellaneous scaffolding/redirect index.php files and added a new .omc session file.

Reviewed changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
XML/index.php Add strict_types to redirect stub.
tests/test_functions.php Add strict_types and modernize stubbed return arrays.
setup.php Add strict_types and convert several arrays to [...].
print.php Add strict_types.
locales/po/index.php Add strict_types to redirect stub.
locales/LC_MESSAGES/index.php Add strict_types to redirect stub.
locales/index.php Add strict_types to redirect stub.
js/index.php Add strict_types to redirect stub.
index.php Add strict_types to redirect stub.
includes/towerSelect.php Add strict_types.
includes/setup/tabs.php Add strict_types.
includes/setup/show.php Add strict_types.
includes/setup/settings.php Add strict_types.
includes/setup/index.php Add strict_types to redirect stub.
includes/setup/gpsmapinitial.php Add strict_types.
includes/setup/database.php Add strict_types and modernize arrays to [...].
includes/polling/processregion.php Add strict_types and modernize arrays to [...].
includes/polling/pollinginitial.php Add strict_types.
includes/polling/kmlcreation.php Add strict_types and convert array initialization to [].
includes/polling/index.php Add strict_types to redirect stub.
includes/polling/iconskml.php Add strict_types.
includes/polling/functions.php Add strict_types and convert array initialization to [].
includes/polling/coveragexml.php Add strict_types.
includes/polling.php Add strict_types and modernize arrays to [...].
includes/index.php Add strict_types to redirect stub.
includes/icons.php Add strict_types.
includes/customicons.php Add strict_types and convert array initialization to [].
images/index.php Add strict_types to redirect stub.
images/icons/index.php Add strict_types to redirect stub.
gpstemplates.php Add strict_types and modernize several arrays to [...].
gpsmap.php Add strict_types.
class/index.php Add strict_types to redirect stub.
class/hosts_class.php Add strict_types.
.omc/sessions/4ee8eaf0-d41c-4923-be60-f215905313bd.json New session metadata file added to repo.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_functions.php
Comment on lines 25 to 27
if (!function_exists('cacti_sizeof')) {
function cacti_sizeof($var) { return is_array($var) ? count($var) : 0; }
function cacti_sizeof($var) { return is_[$var] ? count($var) : 0; }
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cacti_sizeof() stub uses is_[$var], which is invalid PHP and will cause a parse error when running the tests. This should be is_array($var) (and consider returning count($var) only for arrays).

Copilot uses AI. Check for mistakes.
Comment thread includes/polling/processregion.php Outdated
$group = $row['groupnum'];

if (in_array($row['host_template_id'], $towerIds)) {
if (in_[$row['host_template_id'], $towerIds]) {
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in_[$row['host_template_id'], $towerIds] is invalid PHP syntax and will cause a parse error. Replace with in_array($row['host_template_id'], $towerIds, true) (or non-strict if required by existing data types).

Suggested change
if (in_[$row['host_template_id'], $towerIds]) {
if (in_array($row['host_template_id'], $towerIds, true)) {

Copilot uses AI. Check for mistakes.
Comment on lines 181 to 184
switch ($preempt) {
case 0:
if (!in_array($first . '.', $iparray)) {
if (!in_[$first . '.', $iparray]) {
$iparray[] = $first.'.';
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!in_[$first . '.', $iparray]) is invalid PHP syntax and will fail at runtime. Use in_array($first . '.', $iparray, true) instead.

Copilot uses AI. Check for mistakes.
Comment on lines 188 to 192
case 1:
if (!strcasecmp($subnet, $first . '.')) {
if (!in_array($first . '.' . $second . '.', $iparray)) {
if (!in_[$first . '.' . $second . '.', $iparray]) {
$iparray[] = $first . '.' . $second . '.';
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!in_[$first . '.' . $second . '.', $iparray]) is invalid PHP syntax and will cause a parse error. Replace with in_array($first . '.' . $second . '.', $iparray, true).

Copilot uses AI. Check for mistakes.
Comment on lines 199 to 203
case 2:
if (!strcasecmp($subnet, $first . '.' . $second . '.')) {
if (!in_array($first . '.' . $second . '.' . $third . '.', $iparray)) {
if (!in_[$first . '.' . $second . '.' . $third . '.', $iparray]) {
$iparray[] = $first . '.' . $second . '.' . $third . '.';
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!in_[$first . '.' . $second . '.' . $third . '.', $iparray]) is invalid PHP syntax and will not parse. Use in_array($first . '.' . $second . '.' . $third . '.', $iparray, true).

Copilot uses AI. Check for mistakes.
Comment on lines 208 to 213
break;
case 3:
if (!strcasecmp($subnet, $first . '.' . $second . '.' . $third . '.')) {
if (!in_array($first . '.' . $second . '.' . $third . '.' . $fourth . '.' , $iparray)) {
if (!in_[$first . '.' . $second . '.' . $third . '.' . $fourth . '.' , $iparray]) {
$iparray[] = $first . '.' . $second . '.' . $third . '.' . $fourth;
$ipwriteout[] = '<a href="' . $config['url_path'] . 'graph_view.php?action=preview&reset=1&host_id=' . $host->id. '">' . __('IP %s', $first . '.' . $second . '.' . $third . '.' . $fourth) . '</a><br/>';
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!in_[$first . '.' . $second . '.' . $third . '.' . $fourth . '.' , $iparray]) is invalid PHP syntax and will cause a parse error. Replace with in_array($first . '.' . $second . '.' . $third . '.' . $fourth . '.', $iparray, true) (note consistent trailing dot handling).

Copilot uses AI. Check for mistakes.
Comment thread includes/polling.php
Comment on lines 75 to 78

if (!in_array($first . '.', $firstArray)){
if (!in_[$first . '.', $firstArray]){
$firstArray[] = $first . '.';
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!in_[$first . '.', $firstArray]) is invalid PHP syntax and will cause a parse error. Replace with in_array($first . '.', $firstArray, true) (or non-strict if needed).

Copilot uses AI. Check for mistakes.
Comment thread includes/polling.php
Comment on lines 79 to 82

if (!in_array($first . '.' . $second . '.', $secondArray)){
if (!in_[$first . '.' . $second . '.', $secondArray]){
$secondArray[] = $first . '.' . $second . '.';
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!in_[$first . '.' . $second . '.', $secondArray]) is invalid PHP syntax and will not parse. Replace with in_array($first . '.' . $second . '.', $secondArray, true).

Copilot uses AI. Check for mistakes.
Comment thread includes/polling.php
Comment on lines 83 to 86

if (!in_array($first . '.' . $second . '.' . $third . '.', $thirdArray)){
if (!in_[$first . '.' . $second . '.' . $third . '.', $thirdArray]){
$thirdArray[] = $first . '.' . $second . '.' . $third . '.';
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!in_[$first . '.' . $second . '.' . $third . '.', $thirdArray]) is invalid PHP syntax and will cause a parse error. Replace with in_array($first . '.' . $second . '.' . $third . '.', $thirdArray, true).

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +8
{
"session_id": "4ee8eaf0-d41c-4923-be60-f215905313bd",
"ended_at": "2026-04-09T20:28:55.668Z",
"reason": "other",
"agents_spawned": 1,
"agents_completed": 0,
"modes_used": []
} No newline at end of file
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a local tooling/session artifact (.omc/sessions/...json) and likely shouldn’t be committed. Please remove it from the PR and add .omc/ (or at least .omc/sessions/) to the project’s ignore rules so it doesn’t get re-added.

Suggested change
{
"session_id": "4ee8eaf0-d41c-4923-be60-f215905313bd",
"ended_at": "2026-04-09T20:28:55.668Z",
"reason": "other",
"agents_spawned": 1,
"agents_completed": 0,
"modes_used": []
}

Copilot uses AI. Check for mistakes.
Revert corrupted function calls introduced by refactoring tool:
- is_[$x] -> is_array($x)
- in_[$x, ...] -> in_array($x, ...)
- xml2[$x] -> xml2array($x)

Also remove accidentally committed .omc session files and add
.omc/ to .gitignore.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@somethingwithproof somethingwithproof marked this pull request as draft April 11, 2026 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants