Skip to content

refactor: safe PHP 7.4 modernization#88

Open
somethingwithproof wants to merge 5 commits intoCacti:developfrom
somethingwithproof:refactor/modernization
Open

refactor: safe PHP 7.4 modernization#88
somethingwithproof wants to merge 5 commits intoCacti:developfrom
somethingwithproof:refactor/modernization

Conversation

@somethingwithproof
Copy link
Copy Markdown

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:16
Copy link
Copy Markdown
Contributor

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 servcheck plugin’s PHP code for PHP 7.4 by enabling strict typing and refactoring legacy array() usage to short array syntax, and it adds a unit test covering static array definitions / notify account label building.

Changes:

  • Add declare(strict_types=1); across plugin entrypoints and includes.
  • Replace many array(...) constructs with [...] (and related small syntax modernizations).
  • Add a unit test validating key lookup arrays and notify account label-building behavior.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/Unit/ArraysDefinitionTest.php Adds unit coverage for static arrays and notify account label building logic.
setup.php Adds strict types and modernizes prepared statement argument arrays.
servcheck_test.php Adds strict types and modernizes multiple prepared statement argument arrays and filter config arrays.
servcheck_proxies.php Adds strict types and modernizes local arrays / prepared statement argument arrays.
servcheck_process.php Adds strict types and modernizes prepared statement argument arrays / local arrays.
servcheck_curl_code.php Adds strict types.
servcheck_ca.php Adds strict types and modernizes local arrays / prepared statement argument arrays.
poller_servcheck.php Adds strict types and modernizes prepared statement argument arrays.
locales/po/index.php Adds strict types.
locales/LC_MESSAGES/index.php Adds strict types.
locales/index.php Adds strict types.
index.php Adds strict types.
includes/tests.php Adds strict types and refactors arrays; currently introduces fatal syntax errors in cURL option application.
includes/mxlookup.php Adds strict types and modernizes array initializations.
includes/index.php Adds strict types.
includes/functions.php Adds strict types; currently introduces a fatal syntax error in membership check logic.
includes/constants.php Adds strict types.
includes/arrays.php Adds strict types and modernizes key static arrays / notify accounts initialization and some field definitions.
.omc/sessions/07529e04-df5c-47a5-9f2b-aa71b09610a4.json Adds a tool/session artifact file that likely shouldn’t be committed.
.omc/sessions/01068f21-52fc-4525-83a9-8d76d48b18d4.json Adds a tool/session artifact file that likely shouldn’t be committed.

Comment thread includes/tests.php Outdated
plugin_servcheck_debug('cURL options: ' . clean_up_lines(var_export($options, true)));

curl_setopt_array($process,$options);
curl_setopt_[$process,$options];
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.

curl_setopt_[$process,$options]; is invalid PHP syntax and will fatally error at runtime. This should call the cURL bulk setter (e.g., curl_setopt_array) with the handle and options array.

Suggested change
curl_setopt_[$process,$options];
curl_setopt_array($process, $options);

Copilot uses AI. Check for mistakes.
Comment thread includes/tests.php Outdated
plugin_servcheck_debug('cURL options: ' . clean_up_lines(var_export($options, true)));

curl_setopt_array($process,$options);
curl_setopt_[$process,$options];
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.

curl_setopt_[$process,$options]; is invalid PHP syntax and will fatally error at runtime. Use the proper cURL API for applying the options array to the handle.

Suggested change
curl_setopt_[$process,$options];
curl_setopt_array($process, $options);

Copilot uses AI. Check for mistakes.
Comment thread includes/tests.php Outdated
plugin_servcheck_debug('cURL options: ' . clean_up_lines(var_export($options, true)));

curl_setopt_array($process,$options);
curl_setopt_[$process,$options];
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.

curl_setopt_[$process,$options]; is invalid PHP syntax and will fatally error at runtime. Use the correct cURL option application call (e.g., curl_setopt_array).

Suggested change
curl_setopt_[$process,$options];
curl_setopt_array($process, $options);

Copilot uses AI. Check for mistakes.
Comment thread includes/functions.php Outdated
foreach ($contacts as $c) {
if (!in_array($c['user_id'], $u)) {
db_execute_prepared('DELETE FROM plugin_servcheck_contacts WHERE user_id = ?', array($c['user_id']));
if (!in_[$c['user_id'], $u]) {
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_[$c['user_id'], $u] is not a valid PHP function call and will cause a parse error. This should be the standard membership check against $u (e.g., in_array($c['user_id'], $u)), preserving the original behavior.

Suggested change
if (!in_[$c['user_id'], $u]) {
if (!in_array($c['user_id'], $u)) {

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +8
{
"session_id": "07529e04-df5c-47a5-9f2b-aa71b09610a4",
"ended_at": "2026-04-09T12:25:52.085Z",
"reason": "other",
"agents_spawned": 0,
"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 (under .omc/sessions) being committed into the repository. These files are typically ephemeral; consider removing them from the PR and adding .omc/ (or at least .omc/sessions/) to .gitignore to avoid future accidental commits.

Suggested change
{
"session_id": "07529e04-df5c-47a5-9f2b-aa71b09610a4",
"ended_at": "2026-04-09T12:25:52.085Z",
"reason": "other",
"agents_spawned": 0,
"agents_completed": 0,
"modes_used": []
}

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +8
{
"session_id": "01068f21-52fc-4525-83a9-8d76d48b18d4",
"ended_at": "2026-04-09T12:37:16.929Z",
"reason": "other",
"agents_spawned": 0,
"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 (under .omc/sessions) being committed into the repository. These files are typically ephemeral; consider removing them from the PR and adding .omc/ (or at least .omc/sessions/) to .gitignore to avoid future accidental commits.

Suggested change
{
"session_id": "01068f21-52fc-4525-83a9-8d76d48b18d4",
"ended_at": "2026-04-09T12:37:16.929Z",
"reason": "other",
"agents_spawned": 0,
"agents_completed": 0,
"modes_used": []
}

Copilot uses AI. Check for mistakes.
Revert bulk array()->[] rewrite damage affecting:
- is_array, in_array, xml2array
- call_user_func_array, filter_var_array
- Function declarations with _array suffix

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…ction declarations

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
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