Skip to content

refactor: safe PHP 7.4 modernization - #22

Open
somethingwithproof wants to merge 5 commits into
Cacti:developfrom
somethingwithproof:refactor/npc-modernization
Open

refactor: safe PHP 7.4 modernization#22
somethingwithproof wants to merge 5 commits into
Cacti:developfrom
somethingwithproof:refactor/npc-modernization

Conversation

@somethingwithproof

Copy link
Copy Markdown
Member

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:09

Copilot AI left a comment

Copy link
Copy Markdown

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 attempts to modernize the NPC plugin’s PHP code (strict typing, short array syntax, and use of null coalescing) and introduces test stubs to run the plugin in isolation.

Changes:

  • Added declare(strict_types=1); across plugin entrypoints, controllers, and Doctrine model files.
  • Refactored many array(...) usages to [...] and some ternary patterns to null coalescing.
  • Added tests/Helpers/CactiStubs.php to stub Cacti functions for isolated testing.

Reviewed changes

Copilot reviewed 151 out of 151 changed files in this pull request and generated 38 comments.

Show a summary per file
File Description
top_graph_header.php Add strict types; refactor request logic for tree view rendering
tests/Helpers/CactiStubs.php Add isolated-test stubs for Cacti functions
setup.php Add strict types; refactor config arrays and defaults
npc.php Add strict types; refactor request-parameter handling
models/NpcTimeperiodTimeranges.php Add strict types to Doctrine model
models/NpcTimeperiods.php Add strict types to Doctrine model
models/NpcTimedevents.php Add strict types to Doctrine model
models/NpcTimedeventqueue.php Add strict types to Doctrine model
models/NpcSystemcommands.php Add strict types to Doctrine model
models/NpcStatehistory.php Add strict types; refactor Doctrine relations
models/NpcSettings.php Add strict types to Doctrine model
models/NpcServicestatus.php Add strict types; refactor Doctrine relations
models/NpcServices.php Add strict types; refactor Doctrine relations
models/NpcServicegroups.php Add strict types; refactor Doctrine relations
models/NpcServicegroupMembers.php Add strict types; refactor Doctrine relations
models/NpcServiceGraphs.php Add strict types to Doctrine model
models/NpcServiceescalations.php Add strict types to Doctrine model
models/NpcServiceescalationContacts.php Add strict types to Doctrine model
models/NpcServiceescalationContactgroups.php Add strict types to Doctrine model
models/NpcServicedependencies.php Add strict types to Doctrine model
models/NpcServiceContacts.php Add strict types to Doctrine model
models/NpcServiceContactgroups.php Add strict types to Doctrine model
models/NpcServicechecks.php Add strict types to Doctrine model
models/NpcScheduleddowntime.php Add strict types; refactor Doctrine relations
models/NpcRuntimevariables.php Add strict types to Doctrine model
models/NpcProgramstatus.php Add strict types to Doctrine model
models/NpcProcessevents.php Add strict types to Doctrine model
models/NpcObjects.php Add strict types; refactor commented relation examples
models/NpcNotifications.php Add strict types; refactor Doctrine relations
models/NpcLogentries.php Add strict types; refactor Doctrine relations
models/NpcInstances.php Add strict types to Doctrine model
models/NpcHoststatus.php Add strict types; refactor Doctrine relations
models/NpcHosts.php Add strict types; refactor Doctrine relations
models/NpcHostParenthosts.php Add strict types to Doctrine model
models/NpcHostgroups.php Add strict types; refactor Doctrine relations
models/NpcHostgroupMembers.php Add strict types; refactor Doctrine relations
models/NpcHostGraphs.php Add strict types to Doctrine model
models/NpcHostescalations.php Add strict types to Doctrine model
models/NpcHostescalationContacts.php Add strict types to Doctrine model
models/NpcHostescalationContactgroups.php Add strict types to Doctrine model
models/NpcHostdependencies.php Add strict types to Doctrine model
models/NpcHostContacts.php Add strict types to Doctrine model
models/NpcHostContactgroups.php Add strict types to Doctrine model
models/NpcHostchecks.php Add strict types; refactor Doctrine relations
models/NpcFlappinghistory.php Add strict types to Doctrine model
models/NpcExternalcommands.php Add strict types to Doctrine model
models/NpcEventhandlers.php Add strict types to Doctrine model
models/NpcDowntimehistory.php Add strict types; refactor Doctrine relations
models/NpcDbversion.php Add strict types to Doctrine model
models/NpcCustomvariablestatus.php Add strict types to Doctrine model
models/NpcCustomvariables.php Add strict types to Doctrine model
models/NpcContactstatus.php Add strict types to Doctrine model
models/NpcContacts.php Add strict types to Doctrine model
models/NpcContactnotifications.php Add strict types to Doctrine model
models/NpcContactnotificationmethods.php Add strict types to Doctrine model
models/NpcContactNotificationcommands.php Add strict types to Doctrine model
models/NpcContactgroups.php Add strict types to Doctrine model
models/NpcContactgroupMembers.php Add strict types to Doctrine model
models/NpcContactAddresses.php Add strict types to Doctrine model
models/NpcConninfo.php Add strict types to Doctrine model
models/NpcConfigfilevariables.php Add strict types to Doctrine model
models/NpcConfigfiles.php Add strict types to Doctrine model
models/NpcComments.php Add strict types; refactor Doctrine relations
models/NpcCommenthistory.php Add strict types to Doctrine model
models/NpcCommands.php Add strict types to Doctrine model
models/NpcAcknowledgements.php Add strict types to Doctrine model
models/base/BaseNpcTimeperiodTimeranges.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcTimeperiods.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcTimedevents.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcTimedeventqueue.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcSystemcommands.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcStatehistory.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcSettings.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcServicegroups.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcServicegroupMembers.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcServiceGraphs.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcServiceescalations.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcServiceescalationContacts.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcServiceescalationContactgroups.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcServicedependencies.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcServiceContacts.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcServiceContactgroups.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcScheduleddowntime.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcRuntimevariables.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcProcessevents.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcObjects.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcNotifications.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcLogentries.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcInstances.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcHostParenthosts.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcHostgroups.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcHostgroupMembers.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcHostGraphs.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcHostescalations.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcHostescalationContacts.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcHostescalationContactgroups.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcHostdependencies.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcHostContacts.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcHostContactgroups.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcFlappinghistory.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcExternalcommands.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcDbversion.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcCustomvariablestatus.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcCustomvariables.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcContactstatus.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcContactnotifications.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcContactnotificationmethods.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcContactNotificationcommands.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcContactgroups.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcContactgroupMembers.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcContactAddresses.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcConninfo.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcConfigfilevariables.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcConfigfiles.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcComments.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcCommands.php Add strict types; refactor Doctrine column option arrays
models/base/BaseNpcAcknowledgements.php Add strict types; refactor Doctrine column option arrays
locales/po/index.php Add strict types to locale index guard
locales/LC_MESSAGES/index.php Add strict types to locale index guard
locales/index.php Add strict types to locale index guard
lib/Doctrine.php Add strict types; refactor internal arrays and defaults
index.php Add strict types to plugin entrypoint
controllers/sync.php Add strict types; refactor host import/sync logic
controllers/statehistory.php Add strict types; modernize execute() args
controllers/settings.php Add strict types
controllers/services.php Add strict types; refactor service output shaping
controllers/servicegroups.php Add strict types; refactor servicegroup aggregations
controllers/notifications.php Add strict types; modernize execute() args
controllers/nagios.php Add strict types; refactor command formatting and responses
controllers/logentries.php Add strict types; refactor search maps and execute() args
controllers/layoutDev.php Add strict types; refactor layout user lookups
controllers/layout.php Add strict types; refactor layout user/state lookups
controllers/hosts.php Add strict types; refactor host output shaping
controllers/hostgroups.php Add strict types; refactor hostgroup aggregations
controllers/downtime.php Add strict types; refactor combobox output and execute() args
controllers/comments.php Add strict types; refactor bulk-delete command dispatch
controllers/cacti.php Add strict types; refactor Cacti mapping and DIM creation
controllers/controller.php Add strict types; refactor shared controller helpers
config.php Add strict types; refactor autoload registration
nagioscmd.php Add strict types; refactor command-building checks
Comments suppressed due to low confidence (1)

controllers/controller.php:212

  • if (is_[]) is invalid PHP and will cause a parse error in flattenArray(). This should be an is_array($val) check so nested hydration arrays can be flattened correctly.
                if (is_[]) {
                    foreach ($val as $k => $v) {
                        $newArray[$i][$k] = $v;
                    }
                } else {

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

Comment thread top_graph_header.php Outdated
Comment thread npc.php Outdated
Comment thread config.php Outdated
Comment thread lib/Doctrine.php Outdated
Comment thread lib/Doctrine.php Outdated
Comment thread models/NpcServices.php Outdated
Comment thread models/NpcHoststatus.php Outdated
Comment thread models/NpcServicestatus.php Outdated
Comment thread models/NpcHosts.php Outdated
Comment thread controllers/controller.php
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:10
@somethingwithproof

Copy link
Copy Markdown
Member Author

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

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@somethingwithproof
somethingwithproof marked this pull request as ready for review August 29, 2026 05:54
@somethingwithproof somethingwithproof self-assigned this Sep 6, 2026
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