Skip to content

refactor: safe PHP 7.4 modernization#53

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

refactor: safe PHP 7.4 modernization#53
somethingwithproof wants to merge 4 commits into
Cacti: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:15
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 Cacti “maint” plugin PHP files by enabling strict typing across key entry points, aiming to improve type safety and consistency within the plugin.

Changes:

  • Added declare(strict_types=1); to multiple plugin PHP entry points.
  • (Unintended) Introduced PHP syntax errors in setup.php affecting device maintenance actions.
  • Added .omc/sessions/*.json session metadata files to the repo.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
setup.php Adds strict typing but currently contains syntax-breaking changes in device action hooks/handlers.
maint.php Adds strict typing declaration.
functions.php Adds strict typing declaration.
index.php Adds strict typing declaration to the redirect stub.
locales/index.php Adds strict typing declaration to the redirect stub.
locales/LC_MESSAGES/index.php Adds strict typing declaration to the redirect stub.
locales/po/index.php Adds strict typing declaration to the redirect stub.
.omc/sessions/fc9af2ff-7ef1-4e14-af43-2eb9d4741f10.json New session artifact file committed (likely accidental).
.omc/sessions/76281449-e05c-4ccd-a666-0e5c56e6d38b.json New session artifact file committed (likely accidental).

Comment thread setup.php Outdated
* @return array<string, string> Modified actions array with maintenance options
*/
function maint_device_action_array(array $actions): array {
function maint_device_action_[array $actions]: array {
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.

Function name/syntax is invalid (maint_device_action_[array ...) and no longer matches the registered hook (maint_device_action_array). This will cause a PHP parse error and break the device action dropdown hook; restore the correct function declaration/name.

Suggested change
function maint_device_action_[array $actions]: array {
function maint_device_action_array(array $actions): array {

Copilot uses AI. Check for mistakes.
Comment thread setup.php Outdated
$host_list = '';

if (!empty($save['host_array']) && is_array($save['host_array'])) {
if (!empty($save['host_array']) && is_[$save['host_array']]) {
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.

is_[$save['host_array']] is invalid PHP and will trigger a parse error. This should be the standard array type check (e.g., is_array(...)) used elsewhere in Cacti.

Suggested change
if (!empty($save['host_array']) && is_[$save['host_array']]) {
if (!empty($save['host_array']) && is_array($save['host_array'])) {

Copilot uses AI. Check for mistakes.
Comment thread setup.php Outdated
$host_list = '';

if (!empty($save['host_array']) && is_array($save['host_array'])) {
if (!empty($save['host_array']) && is_[$save['host_array']]) {
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.

is_[$save['host_array']] is invalid PHP and will trigger a parse error. Replace with the correct array type check (e.g., is_array(...)).

Suggested change
if (!empty($save['host_array']) && is_[$save['host_array']]) {
if (!empty($save['host_array']) && is_array($save['host_array'])) {

Copilot uses AI. Check for mistakes.
Comment thread setup.php Outdated
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));

if (is_array($selected_items)) {
if (is_[$selected_items]) {
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.

is_[$selected_items] is invalid PHP and will trigger a parse error, preventing maintenance actions from executing. Replace with the correct array type check (e.g., is_array(...)).

Suggested change
if (is_[$selected_items]) {
if (is_array($selected_items)) {

Copilot uses AI. Check for mistakes.
Comment thread setup.php Outdated
Comment on lines 410 to 412
if (is_[$selected_items]) {
foreach ($selected_items as $host_id) {
db_execute_prepared('REPLACE INTO plugin_maint_hosts (type, host, schedule) VALUES (1, ?, ?)', [(int) $host_id, $schedule_id]);
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.

is_[$selected_items] is invalid PHP and will trigger a parse error. Replace with the correct array type check (e.g., is_array(...)) so adding devices to an existing schedule works.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +8
{
"session_id": "fc9af2ff-7ef1-4e14-af43-2eb9d4741f10",
"ended_at": "2026-04-09T11:14:41.971Z",
"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.

These .omc/sessions/*.json files look like local tooling/session artifacts and are not used by the plugin. They should be removed from the repository (and ideally ignored via .gitignore) to avoid committing machine-specific state.

Suggested change
{
"session_id": "fc9af2ff-7ef1-4e14-af43-2eb9d4741f10",
"ended_at": "2026-04-09T11:14:41.971Z",
"reason": "other",
"agents_spawned": 0,
"agents_completed": 0,
"modes_used": []
}

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +8
{
"session_id": "76281449-e05c-4ccd-a666-0e5c56e6d38b",
"ended_at": "2026-04-09T11:25:28.665Z",
"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 .omc/sessions/*.json file appears to be local session metadata rather than source code. Please remove it from the PR (and consider adding an ignore rule) to keep the repo clean and deterministic.

Suggested change
{
"session_id": "76281449-e05c-4ccd-a666-0e5c56e6d38b",
"ended_at": "2026-04-09T11:25:28.665Z",
"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>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@somethingwithproof somethingwithproof marked this pull request as draft April 11, 2026 00:10
@somethingwithproof
Copy link
Copy Markdown
Author

Converted to draft to serialize the stack in this repo. Blocked by #49; will un-draft after that merges to avoid cross-PR merge conflicts.

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