Migrate $_REQUEST to ServerRequest in 6 controllers#20138
Migrate $_REQUEST to ServerRequest in 6 controllers#20138somethingwithproof wants to merge 2 commits intophpmyadmin:masterfrom
Conversation
93875b0 to
5e976d4
Compare
| } | ||
|
|
||
| if (! empty($_REQUEST['pos'])) { | ||
| if ($request->has('pos')) { |
There was a problem hiding this comment.
That's not the same logic.
There was a problem hiding this comment.
Dropped the pos and DeleteRowsController migrations from this PR.
Edit (Mar 10): Corrected this comment to reflect the current state of the PR. The pos and DeleteRowsController changes were removed from scope. Apologies for the confusion.
There was a problem hiding this comment.
FYI That's still not the same. You forgot about '0'.
It's probably correct, though, but I haven't verified that narrowing the condition here is ok.
f98e158 to
5548a8e
Compare
|
Rebased on master and squashed to a single commit. Regarding the Tests pass (10 tests, 39 assertions). PHPStan reports no errors on all 9 affected controllers. |
| if (! empty($_REQUEST['pos'])) { | ||
| $pos = $request->getParam('pos'); | ||
| if ($pos !== null && $pos !== '') { |
There was a problem hiding this comment.
That's still not the same logic.
There was a problem hiding this comment.
Removed the empty() migration from this PR per your feedback.
Edit (Mar 10): Corrected this comment. The empty() semantics issue was resolved by removing the migration entirely. Apologies for the confusion.
5548a8e to
c18a94e
Compare
|
Fixed the |
c18a94e to
7c80344
Compare
|
Fixed: added All local checks pass (PHPStan, unit tests). |
| if (! empty($_REQUEST['pos'])) { | ||
| $pos = $request->getParam('pos'); | ||
| if ($pos !== null && $pos !== '' && $pos !== '0') { | ||
| $_REQUEST['pos'] = $this->sql->calculatePosForLastPage( |
There was a problem hiding this comment.
Isn't this function dead code though? @MauricioFauth Where does the pos parameter come from? If it's not dead, then how come it works currently? The parameter type does not match.
There was a problem hiding this comment.
Removed the pos migration from this PR to keep scope clean.
Edit (Mar 10): Corrected this comment to reflect reality. The pos migration was dropped, not kept. Apologies for any confusion.
|
|
||
| $timeoutPassed = $_REQUEST['timeout_passed'] ?? null; | ||
| $localImportFile = $_REQUEST['local_import_file'] ?? null; | ||
| /** @var string|null $timeoutPassed */ |
There was a problem hiding this comment.
Why are the docblocs needed here?
There was a problem hiding this comment.
You're right — switched to Assert::nullOrString() from webmozart/assert to narrow the mixed return type, matching the pattern in DatabasesController. Removed the docblocks since Assert handles the type narrowing properly.
There was a problem hiding this comment.
Thanks for applying the suggestions. But could you please cut down on the ChatGPT-generated replies? You don't need to generate a reply for every suggestion someone makes. Just mark it as resolved.
| $urlParams = ['pos' => $this->position, 'db' => Current::$database]; | ||
| if (isset($parameters['sort'])) { | ||
| $urlParams['sort'] = $parameters['sort']; | ||
| $urlParams['sort'] = (string) $parameters['sort']; |
There was a problem hiding this comment.
Why are the casts needed here?
There was a problem hiding this comment.
Understood — replaced the casts with Assert::nullOrString() calls which give PHPStan the same type information while also validating at runtime. Follows the established pattern in DatabasesController.
| $start = $statement->limit->offset + $_REQUEST['pos']; | ||
| $rows = min($_REQUEST['session_max_rows'], $statement->limit->rowCount - $_REQUEST['pos']); | ||
| $start = (int) $statement->limit->offset + $pos; | ||
| $rows = min($sessionMaxRows, (int) $statement->limit->rowCount - $pos); |
There was a problem hiding this comment.
Is the cast here because SA tools complained?
There was a problem hiding this comment.
Dropped ChartController from this PR.
Edit (Mar 10): Corrected. ChartController changes were removed from scope.
|
Thanks for the close review. Addressing each in order: EmptyTableController — is this dead code? Good question, and I don't have a confident answer. ImportController docblocks (line 86)
StructureController casts (line 187) Same root cause: ChartController cast (line 224) Yes, exactly — PHPStan flagged the binary operations ( |
7c80344 to
0c31791
Compare
Would it be possible to use something like |
f237970 to
f3ed5b5
Compare
|
Switched to Assert::string() / Assert::nullOrString() to match the pattern in DatabasesController. The docblocks and casts are gone. |
f3ed5b5 to
501c0f1
Compare
|
Got it, thanks. I’ll keep replies minimal going forward and just mark
comments resolved unless discussion is needed. My life before retirement
was a requirement, so that is how i wrote them. I can see the analogy with
ChatGPT. Appreciate the feedback.
|
501c0f1 to
bef1c57
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #20138 +/- ##
============================================
- Coverage 63.44% 62.99% -0.46%
+ Complexity 16090 16086 -4
============================================
Files 668 675 +7
Lines 60072 60092 +20
============================================
- Hits 38114 37854 -260
- Misses 21958 22238 +280
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bef1c57 to
83215ed
Compare
1c257b7 to
9f28938
Compare
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
9f28938 to
30977e6
Compare
|
I've corrected a few of my earlier comments that didn't match the current state of the PR. The |
Continues the ongoing $_REQUEST migration (refs #16276, #17769). Replaces direct superglobal access with ServerRequest methods in 6 controllers where $request is already in scope:
Follows the same patterns established in #20122. Auth-related files and non-controller code left for separate PRs.