Skip to content

Commit

Permalink
refactor: Move router rule for exercises status managment inside the …
Browse files Browse the repository at this point in the history
…switch case
  • Loading branch information
Guillaume1868 committed Oct 8, 2024
1 parent 2168b14 commit 49ef6af
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@

function getRedirection($redirect_uri)
{
if (preg_match('/^\/exercises\/([0-9]+)\?exercise%5Bstatus%5D=(answering|closed)$/A', $_SERVER['REQUEST_URI'], $output_array)) {
if ($output_array[2] == 'answering') {
setExerciseAsAnswering($output_array[1]);
} elseif ($output_array[2] == 'closed') {
setExerciseAsClosed($output_array[1]);
}
return;
}
switch ($redirect_uri) {
case '/':
home();
Expand All @@ -51,6 +43,13 @@ function getRedirection($redirect_uri)
case '/exercises/new':
createAnExercises();
break;
case (preg_match('/^\/exercises\/([0-9]+)\?exercise%5Bstatus%5D=(answering|closed)$/A', $_SERVER['REQUEST_URI'], $output_array) ? true : false):
if ($output_array[2] == 'answering') {
setExerciseAsAnswering($output_array[1]);
} elseif ($output_array[2] == 'closed') {
setExerciseAsClosed($output_array[1]);
}
break;
default:
lost();
}
Expand Down

0 comments on commit 49ef6af

Please sign in to comment.