refactor: safe PHP 7.4 modernization#94
refactor: safe PHP 7.4 modernization#94somethingwithproof wants to merge 4 commits intoCacti:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes the MikroTik plugin’s PHP code toward PHP 7.4 by enabling strict typing and migrating many array() usages to short array syntax ([]), including RouterOS API examples and poller logic.
Changes:
- Added
declare(strict_types=1);to multiple entrypoint/utility PHP files. - Replaced
array(...)with[...]across setup, pollers, and UI pages. - Updated RouterOS API class and examples to use short array syntax.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| templates/index.php | Adds strict typing declaration to redirect stub. |
| setup.php | Adds strict typing and converts several arrays to short syntax. |
| RouterOS/routeros_api.class.php | Adds strict typing and refactors arrays (currently introduces syntax errors). |
| RouterOS/index.php | Adds strict typing declaration to redirect stub. |
| RouterOS/examples/index.php | Adds strict typing declaration to redirect stub. |
| RouterOS/examples/example1.php | Adds strict typing declaration. |
| RouterOS/examples/example2.php | Adds strict typing declaration. |
| RouterOS/examples/example3.php | Adds strict typing and converts comm params to short array syntax. |
| RouterOS/examples/example4.php | Adds strict typing and converts comm params to short array syntax. |
| RouterOS/examples/example5.php | Adds strict typing and converts comm params to short array syntax. |
| RouterOS/examples/example6.php | Adds strict typing and converts comm params to short array syntax. |
| poller_mikrotik.php | Converts prepared-statement parameter arrays and other arrays to short syntax. |
| poller_graphs.php | Converts prepared-statement parameter arrays and other arrays to short syntax. |
| mikrotik.php | Adds strict typing and converts filter/option arrays to short syntax in multiple views. |
| mikrotik_users.php | Adds strict typing and converts several arrays to short syntax. |
| locales/LC_MESSAGES/index.php | Adds strict typing declaration to redirect stub. |
| locales/index.php | Adds strict typing declaration to redirect stub. |
| index.php | Adds strict typing declaration to redirect stub. |
| .omc/sessions/bc7d4148-1a7f-4eab-8c95-384fbca2c233.json | Adds a tooling/session JSON artifact. |
| .omc/sessions/22aa0c8e-37fd-4815-aea8-fa5b27b61038.json | Adds a tooling/session JSON artifact. |
Comments suppressed due to low confidence (2)
RouterOS/routeros_api.class.php:40
isIterable()now containsis_[$var], which is invalid PHP syntax and will cause a parse error. Replace this with a valid check (e.g.,is_array($var)oris_iterable($var)on PHP 7.4+) to restore runtime behavior.
public function isIterable($var) {
return $var !== null
&& (is_[$var]
|| $var instanceof Traversable
|| $var instanceof Iterator
|| $var instanceof IteratorAggregate
);
RouterOS/routeros_api.class.php:250
arrayChangeKeyName()usesis_[$array](invalid PHP syntax). Also,$array_newis not initialized before being written to, which can trigger notices when the input array is empty; initialize it to[]before the loop.
public function arrayChangeKeyName(&$array) {
if (is_[$array]) {
foreach ($array as $k => $v) {
$tmp = str_replace("-", "_", $k);
$tmp = str_replace("/", "_", $tmp);
if ($tmp) {
$array_new[$tmp] = $v;
} else {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public function parseResponse($response) { | ||
| if (is_array($response)) { | ||
| $PARSED = array(); | ||
| if (is_[$response]) { |
There was a problem hiding this comment.
parseResponse() uses is_[$response], which is invalid PHP syntax and will fatally break this class file. This should be a valid type check such as is_array($response) (matching the previous behavior).
| if (is_[$response]) { | |
| if (is_array($response)) { |
| public function parseResponse4Smarty($response) { | ||
| if (is_array($response)) { | ||
| $PARSED = array(); | ||
| if (is_[$response]) { | ||
| $PARSED = []; | ||
| $CURRENT = null; |
There was a problem hiding this comment.
parseResponse4Smarty() uses is_[$response], which is invalid PHP syntax and will prevent the file from parsing. Replace with a valid check (e.g., is_array($response)).
| { | ||
| "session_id": "bc7d4148-1a7f-4eab-8c95-384fbca2c233", | ||
| "ended_at": "2026-04-09T11:39:19.019Z", | ||
| "reason": "other", | ||
| "agents_spawned": 0, | ||
| "agents_completed": 0, | ||
| "modes_used": [] | ||
| } No newline at end of file |
There was a problem hiding this comment.
These .omc/sessions/*.json files look like local tooling/session artifacts (timestamps, agent counts) and are unlikely to belong in the plugin source tree. Consider removing them from the PR and adding an ignore rule so they aren’t committed again.
| { | |
| "session_id": "bc7d4148-1a7f-4eab-8c95-384fbca2c233", | |
| "ended_at": "2026-04-09T11:39:19.019Z", | |
| "reason": "other", | |
| "agents_spawned": 0, | |
| "agents_completed": 0, | |
| "modes_used": [] | |
| } |
| { | ||
| "session_id": "22aa0c8e-37fd-4815-aea8-fa5b27b61038", | ||
| "ended_at": "2026-04-09T11:28:10.207Z", | ||
| "reason": "other", | ||
| "agents_spawned": 0, | ||
| "agents_completed": 0, | ||
| "modes_used": [] | ||
| } No newline at end of file |
There was a problem hiding this comment.
This .omc/sessions/*.json file appears to be a local session log artifact and is likely not intended for distribution/versioning. Please remove it from the PR (and ignore the directory) to keep the repo clean.
| { | |
| "session_id": "22aa0c8e-37fd-4815-aea8-fa5b27b61038", | |
| "ended_at": "2026-04-09T11:28:10.207Z", | |
| "reason": "other", | |
| "agents_spawned": 0, | |
| "agents_completed": 0, | |
| "modes_used": [] | |
| } |
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>
|
Converted to draft to serialize the stack in this repo. Blocked by #90; will un-draft after that merges to avoid cross-PR merge conflicts. |
This PR adds strict typing, short array syntax, and null coalescing operators across the plugin. Standalone infrastructure files were removed per architectural mandate.