Skip to content

refactor: safe PHP 7.4 modernization#94

Draft
somethingwithproof wants to merge 4 commits intoCacti:developfrom
somethingwithproof:refactor/modernization
Draft

refactor: safe PHP 7.4 modernization#94
somethingwithproof wants to merge 4 commits intoCacti:developfrom
somethingwithproof:refactor/modernization

Conversation

@somethingwithproof
Copy link
Copy Markdown

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:15
Copy link
Copy Markdown

Copilot AI left a comment

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 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 contains is_[$var], which is invalid PHP syntax and will cause a parse error. Replace this with a valid check (e.g., is_array($var) or is_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() uses is_[$array] (invalid PHP syntax). Also, $array_new is 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.

Comment thread RouterOS/routeros_api.class.php Outdated
public function parseResponse($response) {
if (is_array($response)) {
$PARSED = array();
if (is_[$response]) {
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
if (is_[$response]) {
if (is_array($response)) {

Copilot uses AI. Check for mistakes.
Comment on lines 202 to 205
public function parseResponse4Smarty($response) {
if (is_array($response)) {
$PARSED = array();
if (is_[$response]) {
$PARSED = [];
$CURRENT = null;
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)).

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +8
{
"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
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
{
"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": []
}

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +8
{
"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
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
{
"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": []
}

Copilot uses AI. Check for mistakes.
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>
@somethingwithproof somethingwithproof marked this pull request as draft April 11, 2026 00:10
@somethingwithproof
Copy link
Copy Markdown
Author

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.

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