refactor: safe PHP 7.4 modernization - #11
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to modernize the plugin’s PHP code by enabling strict typing and adopting newer syntax, while also introducing security documentation and a new security-focused test suite.
Changes:
- Added
declare(strict_types=1);across many PHP entrypoints and core plugin files. - Refactored multiple arrays to short array syntax (
[]) and updated some DB prepared-statement argument arrays. - Added security policy/audit documentation plus new Pest-based security tests, and introduced PHPStan + Infection config files.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| wmi_tools.php | Adds strict types + short array syntax refactors. |
| wmi_script.php | Adds strict types and refactors, but introduces an invalid function invocation. |
| wmi_queries.php | Short array syntax refactors and prepared statement arg updates. |
| wmi_accounts.php | Short array syntax refactors and prepared statement arg updates. |
| functions.php | Adds strict types and converts prepared-statement args to short arrays. |
| poller_wmi.php | Converts prepared-statement args to short arrays. |
| linux_wmi.php | Adds strict types and minor array refactors (no security behavior changes). |
| script/wmi-script.php | Adds strict types but introduces an invalid function invocation. |
| templates//index.php, locales//index.php, index.php, script/index.php | Adds strict types to redirect-only index files. |
| tests/Security/WmiSecurityTest.php | Adds new security tests, but currently contains PHP syntax errors and version mismatches. |
| tests/Security/ShellInjectionTest.php | Adds security tests, including an active regression assertion that will fail until implementation is updated. |
| SECURITY.md / SECURITY-AUDIT.md / BACKLOG.md | Adds security policy, audit findings, and remediation backlog documentation. |
| phpstan.neon | Adds PHPStan config but references a non-existent src/ directory and sets PHP version inconsistently with PR goal. |
| infection.json | Adds Infection config targeting src/ which does not exist in the repo. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - src | ||
| - tests | ||
| phpVersion: 80400 | ||
| treatPhpDocTypesAsCertain: false |
There was a problem hiding this comment.
phpVersion: 80400 (PHP 8.4) and the added code/tests using PHP 8+ features don’t align with the PR’s stated goal of “PHP 7.4 modernization”. Please clarify the supported PHP version for this plugin and set phpVersion (and any new syntax/features) accordingly.
|
Converted to draft to serialize the stack in this repo. Blocked by #8; will un-draft after that merges to avoid cross-PR merge conflicts. |
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>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
aaabf5a to
15d659e
Compare
phpstan.neon and infection.json referenced a src/ directory that doesn't exist in this plugin; both tools would fail to even start. Point them at the repo root instead, excluding tests/ from infection's mutation targets. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Same as hardening/comprehensive; this branch predates it, so no checks run on this PR at all. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…nversion ShellInjectionTest.php's FIND-001/002/003/005 blocks asserted against local literals, not the real Linux_WMI/functions.php code, and their docblocks described vulnerabilities (unescaped hostname, unserialize(), unparameterised id) that clean()/functions.php had already fixed earlier in this branch. Real hostname-escaping coverage already exists in WmiSecurityTest.php; drop the misleading duplicates and keep only the FIND-004 case, which does check the real file. Also convert the two remaining raw db_fetch_cell() hash lookups in setup.php to db_fetch_cell_prepared(), and use cacti_sizeof() instead of sizeof() in poller_wmi.php to match the rest of the codebase. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
|
Pushed two fixes:
Left one thread open: `phpstan.neon` still declares `phpVersion: 80400` while the PR title says "PHP 7.4 modernization" (CI itself only tests 8.1-8.4, so the mismatch is between the title and the two configs, not a functional bug). Didn't want to guess at intent there — worth a maintainer call on which target this plugin actually supports. Also worth noting for whoever picks up #10: the Pest suite added on this branch isn't invoked anywhere in the CI workflow (lint/syntax/poller-smoke-test only), so none of these security regression tests actually run in CI yet. |
This PR adds strict typing, short array syntax, and null coalescing operators across the plugin. Standalone infrastructure files were removed per architectural mandate.