refactor: safe PHP 7.4 modernization - #22
Open
somethingwithproof wants to merge 5 commits into
Open
Conversation
There was a problem hiding this comment.
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.phpto 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 inflattenArray(). This should be anis_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.
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
marked this pull request as draft
April 11, 2026 00:10
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds strict typing, short array syntax, and null coalescing operators across the plugin. Standalone infrastructure files were removed per architectural mandate.