Skip to content

Commit 87a3b9b

Browse files
committed
Simplify with ternary
1 parent 22c1741 commit 87a3b9b

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/UserStateSerializer.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,14 @@ public function serialize(UserState $state)
5959
{
6060
$saveFile = sprintf('%s/%s', $this->path, static::SAVE_FILE);
6161

62-
if (!file_exists($saveFile)) {
63-
$data = [];
64-
$data[$this->workshopName] = [
65-
'completed_exercises' => $state->getCompletedExercises(),
66-
'current_exercise' => $state->getCurrentExercise(),
67-
];
68-
} else {
69-
$data = $this->readJson($saveFile);
70-
$data[$this->workshopName] = [
71-
'completed_exercises' => $state->getCompletedExercises(),
72-
'current_exercise' => $state->getCurrentExercise(),
73-
];
74-
}
62+
$data = file_exists($saveFile)
63+
? $this->readJson($saveFile)
64+
: [];
65+
66+
$data[$this->workshopName] = [
67+
'completed_exercises' => $state->getCompletedExercises(),
68+
'current_exercise' => $state->getCurrentExercise(),
69+
];
7570

7671
return file_put_contents($saveFile, json_encode($data));
7772
}

0 commit comments

Comments
 (0)