refactor: safe PHP 7.4 modernization - #132
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to modernize the ReportIt (Cacti) PHP plugin by enabling strict typing and refactoring legacy array syntax/usages across the codebase.
Changes:
- Added
declare(strict_types=1);to many plugin entrypoints and library/constant files. - Converted many
array(...)literals to short array syntax[...](including prepared-statement parameter arrays). - Refactored various helper usages, but introduced multiple invalid replacements (notably
is_[...],in_[...], andxml_to_[...]) that will break runtime/parse.
Reviewed changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated 38 comments.
Show a summary per file
| File | Description |
|---|---|
| view.php | Adds strict types and array syntax refactors; currently contains invalid is_[...] checks. |
| tmp/index.php | Adds strict types declaration. |
| templates.php | Array syntax refactors; currently contains invalid xml_to_[...] and is_[...] usages that will crash. |
| system/upgrade.php | Array syntax refactors in upgrade routines. |
| system/install.php | Array syntax refactors; unique key column string formatting looks incorrect. |
| setup.php | Array syntax refactors; currently contains an invalid function declaration (reportit_clog_regex_[...]). |
| reportit.php | Array syntax refactors; currently contains invalid in_[...] / is_[...] usages. |
| poller_reportit.php | Array syntax refactors; currently contains invalid in_[...] / is_[...] usages. |
| locales/LC_MESSAGES/index.php | Adds strict types declaration. |
| locales/index.php | Adds strict types declaration. |
| lib/index.php | Adds strict types declaration. |
| lib/funct_validate.php | Array syntax refactors; currently contains invalid in_[...] usages in validation logic. |
| lib/funct_shared.php | Array syntax refactors; currently contains invalid function declarations and many invalid is_[...] / xml_to_[...] usages. |
| lib/funct_runtime.php | Array syntax refactors; currently contains invalid db_custom_fetch_flat_[...] and in_[...] usage. |
| lib/funct_reports.php | Array syntax refactors (incl. prepared params / unserialize options). |
| lib/funct_online.php | Array syntax refactors; currently contains invalid in_[...] usage. |
| lib/funct_html.php | Array syntax refactors; currently contains invalid is_[...] usage. |
| lib/funct_export.php | Array syntax refactors; currently contains invalid in_[...] / is_[...] usages in export paths. |
| lib/funct_calculate.php | Array syntax refactors. |
| lib/const_view.php | Adds strict types + short array syntax in constants. |
| lib/const_variables.php | Adds strict types + short array syntax in constants. |
| lib/const_templates.php | Adds strict types + short array syntax in constants. |
| lib/const_runtime.php | Adds strict types + short array syntax in constants. |
| lib/const_rrdlist.php | Adds strict types + short array syntax in constants. |
| lib/const_reports.php | Adds strict types + short array syntax in constants/forms arrays. |
| lib/const_measurands.php | Adds strict types declaration. |
| lib/const_items.php | Adds strict types + short array syntax in constants. |
| lib/const_graphs.php | Adds strict types + short array syntax in constants. |
| index.php | Adds strict types declaration. |
| include/index.php | Adds strict types declaration. |
| include/global_forms.php | Adds strict types + short array syntax in form field definitions. |
| include/global_arrays.php | Adds strict types declaration. |
| images/index.php | Adds strict types declaration. |
| cache/index.php | Adds strict types declaration. |
| .omc/sessions/ff0c1a6a-cc9f-4db8-b7c4-2fb53b2b07bb.json | New session artifact file added; should not be committed. |
| .omc/sessions/fa94e8de-1fa9-4329-8283-36f9ae53039c.json | New session artifact file added; should not be committed. |
💡 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>
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>
…uble semicolons Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
|
Converted to draft to serialize the stack in this repo. Blocked by #128; will un-draft after that merges to avoid cross-PR merge conflicts. |
Legacy call sites pass DB/request strings into scalar-typed parameters (html_start_box(..., '', '3', ...), checkdate() on exploded date parts), which strict mode turns into fatal TypeErrors. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
|
Copilot feedback addressed. 37 of 38 threads resolved. The bulk of the review (35 threads) was the Also dropped Deliberately not applied:
Left open for a maintainer: the second half of the funct_validate.php:357 comment. Separately, No PHP 8.0-only constructs were introduced anywhere in the diff. |
This PR adds strict typing, short array syntax, and null coalescing operators across the plugin. Standalone infrastructure files were removed per architectural mandate.