refactor: safe PHP 7.4 modernization#155
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to “modernize” the routerconfigs plugin and its vendored Horde Text/* utilities by adding declare(strict_types=1); broadly, plus some array-syntax updates and a new unit test file.
Changes:
- Add
declare(strict_types=1);across many plugin andText/*library files. - Update some examples/docs to short array syntax (
[]). - Add a new
tests/Unit/TextDiffTest.phptest file.
Reviewed changes
Copilot reviewed 75 out of 75 changed files in this pull request and generated 23 comments.
Show a summary per file
| File | Description |
|---|---|
| Text/Util/Variables.php | Adds strict_types; modifies sanitization logic (currently introduces invalid syntax). |
| Text/Util/Util.php | Adds strict_types; modifies magic-quotes handling (currently introduces invalid syntax). |
| Text/Util/String/Transliterate.php | Adds strict_types. |
| Text/Util/String.php | Adds strict_types; modifies charset conversion logic (currently introduces invalid syntax). |
| Text/Util/Domhtml.php | Adds strict_types. |
| Text/Util/Array/Sort/Helper.php | Adds strict_types. |
| Text/Util/Array.php | Adds strict_types; updates doc examples to []. |
| Text/Translation/Handler/Gettext.php | Adds strict_types. |
| Text/Translation/Handler.php | Adds strict_types. |
| Text/Translation/Exception.php | Adds strict_types. |
| Text/Translation/Autodetect.php | Adds strict_types. |
| Text/Translation.php | Adds strict_types. |
| Text/index.php | Adds strict_types. |
| Text/Exception/Wrapped.php | Adds strict_types. |
| Text/Exception/Translation.php | Adds strict_types. |
| Text/Exception/PermissionDenied.php | Adds strict_types. |
| Text/Exception/Pear.php | Adds strict_types. |
| Text/Exception/NotFound.php | Adds strict_types. |
| Text/Exception/LastError.php | Adds strict_types; modifies last-error detection (currently introduces invalid syntax). |
| Text/Exception.php | Adds strict_types. |
| Text/Diff/ThreeWay/Op/Copy.php | Adds strict_types. |
| Text/Diff/ThreeWay/Op/Base.php | Adds strict_types. |
| Text/Diff/ThreeWay/index.php | Adds strict_types. |
| Text/Diff/ThreeWay/BlockBuilder.php | Adds strict_types. |
| Text/Diff/ThreeWay.php | Adds strict_types. |
| Text/Diff/Renderer/Unified/index.php | Adds strict_types. |
| Text/Diff/Renderer/Unified/Colored.php | Adds strict_types. |
| Text/Diff/Renderer/Unified.php | Adds strict_types. |
| Text/Diff/Renderer/table.php | Adds strict_types; modifies block checks (currently introduces invalid syntax) and has an array/string accumulation bug. |
| Text/Diff/Renderer/Inline.php | Adds strict_types. |
| Text/Diff/Renderer/index.php | Adds strict_types. |
| Text/Diff/Renderer/Context.php | Adds strict_types. |
| Text/Diff/Renderer.php | Adds strict_types; modifies array checks (currently introduces invalid syntax). |
| Text/Diff/Op/index.php | Adds strict_types. |
| Text/Diff/Op/Delete.php | Adds strict_types. |
| Text/Diff/Op/Copy.php | Adds strict_types; modifies constructor check (currently introduces invalid syntax). |
| Text/Diff/Op/Change.php | Adds strict_types. |
| Text/Diff/Op/Base.php | Adds strict_types. |
| Text/Diff/Op/Add.php | Adds strict_types. |
| Text/Diff/Mapped.php | Adds strict_types; modifies mapped reconstruction checks (currently introduces invalid syntax). |
| Text/Diff/index.php | Adds strict_types. |
| Text/Diff/Exception.php | Adds strict_types. |
| Text/Diff/Engine/xdiff.php | Adds strict_types. |
| Text/Diff/Engine/string.php | Adds strict_types; updates doc example to []. |
| Text/Diff/Engine/shell.php | Adds strict_types. |
| Text/Diff/Engine/native.php | Adds strict_types. |
| Text/Diff/Engine/index.php | Adds strict_types. |
| Text/Diff.php | Adds strict_types; modifies diff-engine invocation (currently introduces invalid syntax). |
| tests/Unit/TextDiffTest.php | Adds new diff-related unit tests (uses BDD helpers without an apparent runner/deps in repo). |
| setup.php | Adds strict_types. |
| router-download.php | Adds strict_types; modifies option normalization checks (currently introduces invalid syntax). |
| router-devtypes.php | Adds strict_types. |
| router-devices.php | Adds strict_types. |
| router-compare.php | Adds strict_types. |
| router-backups.php | Adds strict_types. |
| router-accounts.php | Adds strict_types. |
| locales/LC_MESSAGES/index.php | Adds strict_types. |
| locales/index.php | Adds strict_types. |
| index.php | Adds strict_types. |
| include/index.php | Adds strict_types. |
| include/functions.php | Adds strict_types. |
| include/constants.php | Adds strict_types. |
| include/arrays.php | Adds strict_types. |
| HordeTextInclude.php | Adds strict_types. |
| classes/PHPTelnet.php | Adds strict_types. |
| classes/PHPSsh.php | Adds strict_types. |
| classes/PHPShellConnection.php | Adds strict_types. |
| classes/PHPSftp.php | Adds strict_types. |
| classes/PHPScp.php | Adds strict_types. |
| classes/PHPConnection.php | Adds strict_types; modifies debug buffer handling (currently introduces invalid syntax; also has a typo in fallback variable name). |
| classes/LinePrompt.php | Adds strict_types. |
| classes/Interfaces.php | Adds strict_types. |
| classes/index.php | Adds strict_types. |
| .omc/sessions/cd2e76a2-f441-4241-8c06-34bd5c7183a2.json | Adds tooling session artifact file (should not be committed). |
| .omc/sessions/13ee8baf-af79-4f4a-8055-94addbce1910.json | Adds tooling session artifact file (should not be committed). |
Comments suppressed due to low confidence (1)
Text/Util/String.php:72
- Invalid PHP syntax introduced:
is_[$input]will not parse. This needs to beis_array($input)(or otherwise restore the previous array-detection logic).
| return is_[$val] | ||
| ? filter_var_[$val, FILTER_SANITIZE_STRING] | ||
| : filter_var($val, FILTER_SANITIZE_STRING); |
There was a problem hiding this comment.
filter() now contains invalid PHP syntax (is_[$val] / filter_var_[$val, ...]). This will fail to parse and should be restored to the intended is_array(...) / filter_var_array(...) usage (or equivalent).
| if (self::$_magicquotes) { | ||
| $var = is_array($var) | ||
| $var = is_[$var] | ||
| ? array_map([__CLASS__, 'dispelMagicQuotes'], $var) | ||
| : stripslashes($var); |
There was a problem hiding this comment.
Invalid PHP syntax introduced: is_[$var] is not a function call and will cause a parse error. This should be is_array($var) (and any similar replacements in this file should be corrected).
| if (($to == 'utf-8') && | ||
| in_array($from, ['iso-8859-1', 'us-ascii', 'utf-8'], true)) { | ||
| in_[$from, ['iso-8859-1', 'us-ascii', 'utf-8'], true]) { | ||
| return utf8_encode($input); |
There was a problem hiding this comment.
Invalid PHP syntax introduced in the charset conversion condition: in_[$from, ...] is not valid and will fail to parse. This should be the original in_array($from, ..., true) check (or equivalent).
| if (($from == 'utf-8') && | ||
| in_array($to, ['iso-8859-1', 'us-ascii', 'utf-8'], true)) { | ||
| in_[$to, ['iso-8859-1', 'us-ascii', 'utf-8'], true]) { | ||
| return utf8_decode($input); |
There was a problem hiding this comment.
Invalid PHP syntax introduced in the charset conversion condition: in_[$to, ...] is not valid and will fail to parse. This should be the original in_array($to, ..., true) check (or equivalent).
| $diff_engine = new $class(); | ||
|
|
||
| $this->_edits = call_user_func_array([$diff_engine, 'diff'], $params); | ||
| $this->_edits = call_user_func_[[$diff_engine, 'diff'], $params]; |
There was a problem hiding this comment.
This line introduces invalid PHP syntax: call_user_func_[...] is not a valid construct and will cause a parse error. It should remain call_user_func_array([$diff_engine, 'diff'], $params) or be replaced with a valid invocation (e.g., argument unpacking) that preserves current behavior.
| $this->_edits = call_user_func_[[$diff_engine, 'diff'], $params]; | |
| $this->_edits = call_user_func_array([$diff_engine, 'diff'], $params); |
| function routerconfigs_getopts_long(array &$options, array &$long) { | ||
| if (isset($long)) { | ||
| if (!is_array($long)) { | ||
| if (!is_[$long]) { | ||
| $long = [$long]; | ||
| } |
There was a problem hiding this comment.
Invalid PHP syntax introduced: is_[$long] will not parse. This should be is_array($long) (or equivalent) so long option definitions are normalized correctly.
| if ($this->debugbuffer) { | ||
| if (!is_array($line_buf)) { | ||
| if (!is_[$line_buf]) { | ||
| $line_buf = [$line_buff]; | ||
| } |
There was a problem hiding this comment.
This block contains invalid PHP syntax (is_[$line_buf]) which will prevent parsing. Also, if this branch ever executes, it assigns from $line_buff (typo) instead of $line_buf, which would trigger an undefined variable notice; the fallback should use the correct variable name.
| describe('Horde_Text_Diff_Engine_Native: identical files', function (): void { | ||
| it('produces only Copy operations for identical input', function (): void { | ||
| $lines = ['line one', 'line two', 'line three']; | ||
| $engine = new Horde_Text_Diff_Engine_Native(); | ||
| $edits = $engine->diff($lines, $lines); | ||
|
|
There was a problem hiding this comment.
This test file uses describe()/it()/expect() BDD helpers, but the repository doesn't appear to include or configure a test runner/library that defines these (no PHPUnit/Pest/Kahlan config/dependencies found). As-is, running this file will fatal with undefined function errors; either add the corresponding test framework + documentation, or convert tests to the project's existing test setup.
| { | ||
| "session_id": "cd2e76a2-f441-4241-8c06-34bd5c7183a2", | ||
| "ended_at": "2026-04-09T12:12:03.753Z", | ||
| "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 and not part of the plugin/runtime. They should be removed from the repository and added to .gitignore to avoid committing future session data.
| { | |
| "session_id": "cd2e76a2-f441-4241-8c06-34bd5c7183a2", | |
| "ended_at": "2026-04-09T12:12:03.753Z", | |
| "reason": "other", | |
| "agents_spawned": 0, | |
| "agents_completed": 0, | |
| "modes_used": [] | |
| } |
| { | ||
| "session_id": "13ee8baf-af79-4f4a-8055-94addbce1910", | ||
| "ended_at": "2026-04-09T12:23:20.607Z", | ||
| "reason": "other", | ||
| "agents_spawned": 1, | ||
| "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 and not part of the plugin/runtime. They should be removed from the repository and added to .gitignore to avoid committing future session data.
| { | |
| "session_id": "13ee8baf-af79-4f4a-8055-94addbce1910", | |
| "ended_at": "2026-04-09T12:23:20.607Z", | |
| "reason": "other", | |
| "agents_spawned": 1, | |
| "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>
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>
|
Converted to draft to serialize the stack in this repo. Blocked by #153; 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.