Skip to content

Commit db75ac3

Browse files
committed
Add method to validate logtype request param
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 0cc6340 commit db75ac3

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

libraries/classes/Controllers/Table/TrackingController.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use function define;
2121
use function explode;
2222
use function htmlspecialchars;
23+
use function in_array;
2324
use function is_array;
2425
use function sprintf;
2526
use function strtotime;
@@ -110,10 +111,8 @@ public function __invoke(ServerRequest $request): void
110111
$versionParam
111112
);
112113

113-
$logType = $request->getParsedBodyParam('logtype', 'schema_and_data');
114-
if (! isset($_POST['logtype'])) {
115-
$_POST['logtype'] = 'schema_and_data';
116-
}
114+
$logType = $this->validateLogTypeParam($request->getParsedBodyParam('logtype'));
115+
$_POST['logtype'] = $logType;
117116

118117
if ($logType === 'schema') {
119118
$GLOBALS['selection_schema'] = true;
@@ -293,4 +292,14 @@ public function __invoke(ServerRequest $request): void
293292
'main' => $main,
294293
]);
295294
}
295+
296+
/**
297+
* @param mixed $param
298+
*
299+
* @psalm-return 'schema'|'data'|'schema_and_data'
300+
*/
301+
private function validateLogTypeParam($param): string
302+
{
303+
return in_array($param, ['schema', 'data'], true) ? $param : 'schema_and_data';
304+
}
296305
}

0 commit comments

Comments
 (0)