refactor: safe PHP 7.4 modernization#88
refactor: safe PHP 7.4 modernization#88somethingwithproof wants to merge 5 commits intoCacti:developfrom
Conversation
There was a problem hiding this comment.
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. |
| plugin_servcheck_debug('cURL options: ' . clean_up_lines(var_export($options, true))); | ||
|
|
||
| curl_setopt_array($process,$options); | ||
| curl_setopt_[$process,$options]; |
There was a problem hiding this comment.
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.
| curl_setopt_[$process,$options]; | |
| curl_setopt_array($process, $options); |
| plugin_servcheck_debug('cURL options: ' . clean_up_lines(var_export($options, true))); | ||
|
|
||
| curl_setopt_array($process,$options); | ||
| curl_setopt_[$process,$options]; |
There was a problem hiding this comment.
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.
| curl_setopt_[$process,$options]; | |
| curl_setopt_array($process, $options); |
| plugin_servcheck_debug('cURL options: ' . clean_up_lines(var_export($options, true))); | ||
|
|
||
| curl_setopt_array($process,$options); | ||
| curl_setopt_[$process,$options]; |
There was a problem hiding this comment.
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).
| curl_setopt_[$process,$options]; | |
| curl_setopt_array($process, $options); |
| 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]) { |
There was a problem hiding this comment.
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.
| if (!in_[$c['user_id'], $u]) { | |
| if (!in_array($c['user_id'], $u)) { |
| { | ||
| "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 |
There was a problem hiding this comment.
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.
| { | |
| "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": [] | |
| } |
| { | ||
| "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 |
There was a problem hiding this comment.
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.
| { | |
| "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": [] | |
| } |
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>
This PR adds strict typing, short array syntax, and null coalescing operators across the plugin. Standalone infrastructure files were removed per architectural mandate.