Restore Stringy fast paths and remove mutation-only regressions#55
Restore Stringy fast paths and remove mutation-only regressions#55Copilot wants to merge 22 commits into
Conversation
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/fd145f49-5d23-4a8e-a2a9-903226bc1fb0 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/fd145f49-5d23-4a8e-a2a9-903226bc1fb0 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/d19c2708-ace7-4d21-8251-0419248e611e Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/d19c2708-ace7-4d21-8251-0419248e611e Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/d19c2708-ace7-4d21-8251-0419248e611e Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/d19c2708-ace7-4d21-8251-0419248e611e Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/d19c2708-ace7-4d21-8251-0419248e611e Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/e929ead2-bee8-427c-a422-d939c2d23915 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/e929ead2-bee8-427c-a422-d939c2d23915 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/d6b169ee-ea82-4c1f-bf9d-1006d0d80a46 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/8f7ff1e0-d7d1-40ae-aab4-3257432c6a55 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/8f7ff1e0-d7d1-40ae-aab4-3257432c6a55 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/8f7ff1e0-d7d1-40ae-aab4-3257432c6a55 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/8f7ff1e0-d7d1-40ae-aab4-3257432c6a55 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/8f7ff1e0-d7d1-40ae-aab4-3257432c6a55 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/8f7ff1e0-d7d1-40ae-aab4-3257432c6a55 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/8f7ff1e0-d7d1-40ae-aab4-3257432c6a55 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/8f7ff1e0-d7d1-40ae-aab4-3257432c6a55 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/72dffc87-ae29-4e24-ac45-8c7830d0b9e6 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/72dffc87-ae29-4e24-ac45-8c7830d0b9e6 Co-authored-by: voku <264695+voku@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors several methods in the Stringy class to achieve a 100% mutation score (MSI), primarily by removing redundant checks and simplifying logic. Key changes include refactoring format, encode, and at, as well as adding extensive mutation guard tests. Feedback indicates a significant logic flaw in the format method's offset calculation, which introduces an ordering dependency and potential type coercion bugs. Additionally, the removal of the exact match fast path in the is method is identified as a performance regression that should be reconsidered.
I am having trouble creating individual review comments. Click here to see my feedback.
src/Stringy.php (1406-1410)
The logic for calculating the $offset when replacing named parameters is fragile and introduces potential bugs:
- Ordering Dependency: Since
$offsetis shared across all keys in the$argarray and only increases, placeholders must be provided in the array in the exact order they appear in the string. If they are out of order (e.g.,['b' => 2, 'a' => 1]for string%:a %:b), the search for subsequent keys will start after the position of the previous match, failing to find placeholders that appear earlier in the string. - Type Coercion Issue: If
strposreturnsfalse(line 1411) for a key, the$offsetvariable is set tofalse. In the next iteration of the loop (for the next key), line 1409 performsfalse + $replacementLength. While PHP coerces this to an integer, it is logically incorrect as it continues the search from an arbitrary position instead of resetting or maintaining the last valid cursor.
Consider using a single-pass replacement strategy like preg_replace_callback which avoids these ordering and recursion issues entirely.
src/Stringy.php (1962-1964)
Removing the exact match fast path is a performance regression. Although the subsequent regex logic covers this case, a direct string comparison is significantly more efficient. If this change was made solely to achieve 100% mutation score (MSI) by removing 'redundant' branches, it is often better to keep the optimization and use mutation testing annotations to preserve performance without sacrificing the quality score.
|
@copilot feedback from another llm, so maybe totally shit or not, you need to check it yourself : src/Stringy.php (1406-1410) The logic for calculating the $offset when replacing named parameters is fragile and introduces potential bugs: Ordering Dependency: Since $offset is shared across all keys in the $arg array and only increases, placeholders must be provided in the array in the exact order they appear in the string. If they are out of order (e.g., ['b' => 2, 'a' => 1] for string %:a %:b), the search for subsequent keys will start after the position of the previous match, failing to find placeholders that appear earlier in the string. src/Stringy.php (1962-1964) Removing the exact match fast path is a performance regression. Although the subsequent regex logic covers this case, a direct string comparison is significantly more efficient. If this change was made solely to achieve 100% mutation score (MSI) by removing 'redundant' branches, it is often better to keep the optimization and use mutation testing annotations to preserve performance without sacrificing the quality score. |
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/91bda127-29c0-476f-8542-197fd7c67276 Co-authored-by: voku <264695+voku@users.noreply.github.com>
... I fixed the confirmed |
|
@copilot Double check of we need to restore things like |
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/acf90d47-937f-4dca-97c0-24ce249ec0c2 Co-authored-by: voku <264695+voku@users.noreply.github.com>
I double-checked the legacy-sensitive paths and restored the |
encode(),indexOfLast*(),split(..., null), andtitleize()This change is