Skip to content

Commit cf69328

Browse files
Merge pull request #19766 from MauricioFauth/redirect-response
Directly return a Reponse object after a redirect when possible
2 parents 813964c + 842f986 commit cf69328

52 files changed

Lines changed: 138 additions & 238 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

psalm-baseline.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,11 +1456,6 @@
14561456
<code><![CDATA[$options]]></code>
14571457
</MixedAssignment>
14581458
</file>
1459-
<file src="src/Controllers/LogoutController.php">
1460-
<PossiblyUnusedReturnValue>
1461-
<code><![CDATA[Response]]></code>
1462-
</PossiblyUnusedReturnValue>
1463-
</file>
14641459
<file src="src/Controllers/Navigation/UpdateNavWidthConfigController.php">
14651460
<PossiblyUnusedReturnValue>
14661461
<code><![CDATA[Response]]></code>

src/Controllers/Database/DesignerController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ public function __invoke(ServerRequest $request): Response
173173
return $this->response->response();
174174
}
175175

176-
$this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
177-
178-
return $this->response->response();
176+
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
179177
}
180178

181179
$scriptDisplayField = $this->designerCommon->getTablesInfo();

src/Controllers/Database/EventsController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ public function __invoke(ServerRequest $request): Response
4747

4848
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
4949
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
50-
$this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
51-
52-
return $this->response->response();
50+
return $this->response->redirectToRoute(
51+
'/',
52+
['reload' => true, 'message' => __('No databases selected.')],
53+
);
5354
}
5455
} elseif (Current::$database !== '') {
5556
$this->dbi->selectDb(Current::$database);

src/Controllers/Database/ExportController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ public function __invoke(ServerRequest $request): Response
5959
return $this->response->response();
6060
}
6161

62-
$this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
63-
64-
return $this->response->response();
62+
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
6563
}
6664

6765
UrlParams::$params['goto'] = Url::getFromRoute('/database/export');

src/Controllers/Database/ImportController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ public function __invoke(ServerRequest $request): Response
6262
return $this->response->response();
6363
}
6464

65-
$this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
66-
67-
return $this->response->response();
65+
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
6866
}
6967

7068
[$uploadId] = Ajax::uploadProgressSetup();

src/Controllers/Database/RoutinesController.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,28 @@ public function __invoke(ServerRequest $request): Response
7575

7676
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
7777
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
78-
$this->response->redirectToRoute(
78+
return $this->response->redirectToRoute(
7979
'/',
8080
['reload' => true, 'message' => __('No databases selected.')],
8181
);
82-
83-
return $this->response->response();
8482
}
8583

8684
$tableName = TableName::tryFrom($request->getParam('table'));
8785
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
88-
$this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
89-
90-
return $this->response->response();
86+
return $this->response->redirectToRoute(
87+
'/',
88+
['reload' => true, 'message' => __('No table selected.')],
89+
);
9190
}
9291
} else {
9392
Current::$table = '';
9493

9594
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
9695
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
97-
$this->response->redirectToRoute(
96+
return $this->response->redirectToRoute(
9897
'/',
9998
['reload' => true, 'message' => __('No databases selected.')],
10099
);
101-
102-
return $this->response->response();
103100
}
104101
}
105102
} elseif (Current::$database !== '') {
@@ -472,9 +469,7 @@ public function __invoke(ServerRequest $request): Response
472469
$redirParams['ajax_page_request'] = 'true';
473470
}
474471

475-
$this->response->redirectToRoute('/database/routines', $redirParams);
476-
477-
return $this->response->response();
472+
return $this->response->redirectToRoute('/database/routines', $redirParams);
478473
}
479474

480475
$items = Routines::getDetails($this->dbi, Current::$database, $type, limit: $pageSize, offset: $pos);

src/Controllers/Database/SearchController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ public function __invoke(ServerRequest $request): Response
5555
return $this->response->response();
5656
}
5757

58-
$this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
59-
60-
return $this->response->response();
58+
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
6159
}
6260

6361
if (! $this->config->settings['UseDbSearch']) {

src/Controllers/Database/SqlController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ public function __invoke(ServerRequest $request): Response
5656
return $this->response->response();
5757
}
5858

59-
$this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
60-
61-
return $this->response->response();
59+
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
6260
}
6361

6462
/**

src/Controllers/Database/Structure/EmptyTableController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ public function __invoke(ServerRequest $request): Response
4141

4242
if ($multBtn !== __('Yes')) {
4343
$this->flashMessenger->addMessage('success', __('No change'));
44-
$this->response->redirectToRoute('/database/structure', ['db' => Current::$database]);
4544

46-
return $this->response->response();
45+
return $this->response->redirectToRoute('/database/structure', ['db' => Current::$database]);
4746
}
4847

4948
$defaultFkCheckValue = ForeignKey::handleDisableCheckInit();

src/Controllers/Database/StructureController.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ public function __invoke(ServerRequest $request): Response
141141
return $this->response->response();
142142
}
143143

144-
$this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
145-
146-
return $this->response->response();
144+
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
147145
}
148146

149147
$this->response->addScriptFiles(['database/structure.js', 'table/change.js']);
@@ -155,7 +153,7 @@ public function __invoke(ServerRequest $request): Response
155153
// If there are no tables, the user is redirected to the last page
156154
// having any.
157155
if ($this->totalNumTables > 0 && $this->position > $this->totalNumTables) {
158-
$this->response->redirectToRoute('/database/structure', [
156+
return $this->response->redirectToRoute('/database/structure', [
159157
'db' => Current::$database,
160158
'pos' => max(0, $this->totalNumTables - $this->config->settings['MaxTableList']),
161159
'reload' => 1,

0 commit comments

Comments
 (0)