refactor: safe PHP 7.4 modernization#54
refactor: safe PHP 7.4 modernization#54somethingwithproof wants to merge 5 commits intoCacti:developfrom
Conversation
Guard against non-string $page and non-array $selected_items at the function boundary to prevent unexpected behavior from malformed caller data. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR modernizes the Cacti Audit plugin’s PHP sources by enabling strict typing and updating some legacy array syntax, with the goal of safer/cleaner PHP 7.4-era code.
Changes:
- Added
declare(strict_types=1);to multiple PHP entrypoint files. - Converted some
array(...)usages to short array syntax[...]. - Introduced additional input/type guarding in
audit_process_page_data().
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| setup.php | Adds strict types and short array syntax; currently contains a PHP parse error in audit_utilities_array declaration. |
| audit.php | Adds strict types and short array syntax; currently contains PHP parse errors in is_array checks. |
| audit_functions.php | Adds strict types, short array syntax, and new guard logic; currently contains a PHP parse error in the guard clause. |
| index.php | Adds strict types to plugin index redirect. |
| locales/index.php | Adds strict types to locales index redirect. |
| locales/LC_MESSAGES/index.php | Adds strict types to LC_MESSAGES index redirect. |
| .omc/sessions/*.json | Adds session metadata files that appear unrelated to plugin runtime and should not be committed. |
| } | ||
|
|
||
| function audit_utilities_array() { | ||
| function audit_utilities_[] { |
There was a problem hiding this comment.
audit_utilities_array is registered as a hook, but the function definition here is syntactically invalid (function audit_utilities_[] {). This will cause a PHP parse error and prevent the plugin from loading. Rename/restore the function declaration to audit_utilities_array() (and keep the audit_ prefix).
| function audit_utilities_[] { | |
| function audit_utilities_array() { |
| } | ||
|
|
||
| if (is_array($content)) { | ||
| if (is_[$content]) { |
There was a problem hiding this comment.
This condition is syntactically invalid: is_[$content] will cause a PHP parse error. It looks like this should be is_array($content) to match the previous behavior when rendering attribute values.
| if (is_[$content]) { | |
| if (is_array($content)) { |
| $poster = ''; | ||
| foreach($post as $var => $value) { | ||
| if (is_array($value)) { | ||
| if (is_[$value]) { |
There was a problem hiding this comment.
This condition is syntactically invalid: is_[$value] will cause a PHP parse error during CSV export. It appears the intent was to keep the prior is_array($value) check.
| if (is_[$value]) { | |
| if (is_array($value)) { |
| $objects = array(); | ||
| $objects = []; | ||
|
|
||
| if (!is_string($page) || $page === '' || !is_[$selected_items]) { |
There was a problem hiding this comment.
The new guard clause uses !is_[$selected_items], which is syntactically invalid and will cause a PHP parse error. This should be an array check (e.g., !is_array($selected_items)) so audit_process_page_data() can safely early-return when unserialize() fails.
| if (!is_string($page) || $page === '' || !is_[$selected_items]) { | |
| if (!is_string($page) || $page === '' || !is_array($selected_items)) { |
| { | ||
| "session_id": "e795e842-5b52-4c4f-a301-d0c076c145ec", | ||
| "ended_at": "2026-04-09T20:40:09.532Z", | ||
| "reason": "other", | ||
| "agents_spawned": 0, | ||
| "agents_completed": 0, | ||
| "modes_used": [] | ||
| } No newline at end of file |
There was a problem hiding this comment.
This .omc/sessions/*.json file appears to be an editor/automation session artifact, not part of the plugin runtime. It should not be committed; please remove it from the PR and add .omc/ (or at least .omc/sessions/) to .gitignore to prevent re-adding.
| { | |
| "session_id": "e795e842-5b52-4c4f-a301-d0c076c145ec", | |
| "ended_at": "2026-04-09T20:40:09.532Z", | |
| "reason": "other", | |
| "agents_spawned": 0, | |
| "agents_completed": 0, | |
| "modes_used": [] | |
| } |
| { | ||
| "session_id": "d67358a1-81fd-4c38-8750-7175bf018252", | ||
| "ended_at": "2026-04-09T20:46:21.611Z", | ||
| "reason": "other", | ||
| "agents_spawned": 0, | ||
| "agents_completed": 0, | ||
| "modes_used": [] | ||
| } No newline at end of file |
There was a problem hiding this comment.
This .omc/sessions/*.json file appears to be an editor/automation session artifact, not part of the plugin runtime. It should not be committed; please remove it from the PR and add .omc/ (or at least .omc/sessions/) to .gitignore to prevent re-adding.
| { | |
| "session_id": "d67358a1-81fd-4c38-8750-7175bf018252", | |
| "ended_at": "2026-04-09T20:46:21.611Z", | |
| "reason": "other", | |
| "agents_spawned": 0, | |
| "agents_completed": 0, | |
| "modes_used": [] | |
| } |
| { | ||
| "session_id": "865e7e69-4115-4c88-a9ea-8264b75b1cfc", | ||
| "ended_at": "2026-04-09T20:42:25.246Z", | ||
| "reason": "other", | ||
| "agents_spawned": 0, | ||
| "agents_completed": 0, | ||
| "modes_used": [] | ||
| } No newline at end of file |
There was a problem hiding this comment.
This .omc/sessions/*.json file appears to be an editor/automation session artifact, not part of the plugin runtime. It should not be committed; please remove it from the PR and add .omc/ (or at least .omc/sessions/) to .gitignore to prevent re-adding.
| { | |
| "session_id": "865e7e69-4115-4c88-a9ea-8264b75b1cfc", | |
| "ended_at": "2026-04-09T20:42:25.246Z", | |
| "reason": "other", | |
| "agents_spawned": 0, | |
| "agents_completed": 0, | |
| "modes_used": [] | |
| } |
| { | ||
| "session_id": "426d31d2-5007-4a69-94e9-7171c89be435", | ||
| "ended_at": "2026-04-09T20:39:23.599Z", | ||
| "reason": "other", | ||
| "agents_spawned": 0, | ||
| "agents_completed": 0, | ||
| "modes_used": [] | ||
| } No newline at end of file |
There was a problem hiding this comment.
This .omc/sessions/*.json file appears to be an editor/automation session artifact, not part of the plugin runtime. It should not be committed; please remove it from the PR and add .omc/ (or at least .omc/sessions/) to .gitignore to prevent re-adding.
| { | |
| "session_id": "426d31d2-5007-4a69-94e9-7171c89be435", | |
| "ended_at": "2026-04-09T20:39:23.599Z", | |
| "reason": "other", | |
| "agents_spawned": 0, | |
| "agents_completed": 0, | |
| "modes_used": [] | |
| } |
| { | ||
| "session_id": "0ad57977-0b9b-4712-bf0c-d8591161a6c5", | ||
| "ended_at": "2026-04-09T20:58:25.835Z", | ||
| "reason": "other", | ||
| "agents_spawned": 0, | ||
| "agents_completed": 0, | ||
| "modes_used": [] | ||
| } No newline at end of file |
There was a problem hiding this comment.
This .omc/sessions/*.json file appears to be an editor/automation session artifact, not part of the plugin runtime. It should not be committed; please remove it from the PR and add .omc/ (or at least .omc/sessions/) to .gitignore to prevent re-adding.
| { | |
| "session_id": "0ad57977-0b9b-4712-bf0c-d8591161a6c5", | |
| "ended_at": "2026-04-09T20:58:25.835Z", | |
| "reason": "other", | |
| "agents_spawned": 0, | |
| "agents_completed": 0, | |
| "modes_used": [] | |
| } |
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>
|
Converted to draft to serialize the stack in this repo. Blocked by #51; will un-draft after that merges to avoid cross-PR merge conflicts. |
This PR adds strict typing, short array syntax, and null coalescing operators across the plugin. Standalone infrastructure files were removed per architectural mandate.