Skip to content
Prev Previous commit
Next Next commit
refactor: create constants
  • Loading branch information
mbarreche committed Nov 6, 2022
commit 216b95d1f60b6718cec34a900e4c59d26a09d365
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

final class CourseStepsGetController
{
private const VIDEO_TYPE = 'video';
private const QUIZ_TYPE = 'quiz';
private const DURATION_VIDEO_MINUTES = 1.1;
private const DURATION_QUIZ_MINUTES = 0.5;
private const VIDEO_POINTS_PER_MINUTE = 100;
private const QUIZ_POINTS_PER_MINUTE = 10;

private Platform $platform;

public function __construct(Platform $platform)
Expand Down Expand Up @@ -38,7 +45,7 @@ private function createSteps(string $csv): array
foreach ($csvLines as $row) {
$row = str_getcsv($row);
$type = $row[1];
if ($type !== 'video' && $type !== 'quiz') {
if (in_array($type, [self::VIDEO_TYPE, self::QUIZ_TYPE], true)) {
continue;
}

Expand All @@ -54,27 +61,19 @@ private function createSteps(string $csv): array
return $steps;
}

private function duration(string $type, $durationVideo, $durationQuiz): float
private function duration(string $type, float $durationVideo, float $durationQuiz): float
{
$duration = 0;
if ($type === 'video') {
$duration = $durationVideo * 1.1; // 1.1 = due to video pauses
}
if ($type === 'quiz') {
$duration = $durationQuiz * 0.5; // 0.5 = time in minutes per question
if ($type === self::VIDEO_TYPE) {
return $durationVideo * self::DURATION_VIDEO_MINUTES;
}
return $duration;
return $durationQuiz * self::DURATION_QUIZ_MINUTES;
}

private function points(string $type, $durationVideo, $durationQuiz): float
private function points(string $type, float $durationVideo, float $durationQuiz): float
{
$points = 0;
if ($type === 'video') {
$points = $durationVideo * 1.1 * 100;
}
if ($type === 'quiz') {
$points = $durationQuiz * 0.5 * 10;
if ($type === self::VIDEO_TYPE) {
return $durationVideo * self::DURATION_VIDEO_MINUTES * self::VIDEO_POINTS_PER_MINUTE;
}
return $points;
return $durationQuiz * self::DURATION_QUIZ_MINUTES * self::QUIZ_POINTS_PER_MINUTE;
}
}