Skip to content

Apply Split Phase refactoring #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Rename
  • Loading branch information
rgomezcasas committed Apr 14, 2021
commit 4f22e1bf0be737097e7d3c2098ca75d9e7a79667
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ final class CourseStepsGetController
{
const VIDEO_DURATION_PAUSES_MULTIPLIER = 1.1;
const QUIZ_TIME_PER_QUESTION_MULTIPLIER = 0.5;
const STEP_TYPE_VIDEO = 'video';
const STEP_TYPE_QUIZ = 'quiz';
private Platform $platform;

public function __construct(Platform $platform)
Expand All @@ -32,43 +34,43 @@ public function get(string $courseId): string
continue;
}

$type = $row[1];
[$stepId, $type, $quizTotalQuestions, $videoDuration] = $row;

$stepDurationInMinutes = 0;
$points = 0;
$points = 0;

$videoDuration = $row[3];
if ($type === 'video') {
if ($type === self::STEP_TYPE_VIDEO) {
$stepDurationInMinutes = $videoDuration * self::VIDEO_DURATION_PAUSES_MULTIPLIER;
}

$quizTotalQuestions = $row[2];
if ($type === 'quiz') {
if ($type === self::STEP_TYPE_QUIZ) {
$stepDurationInMinutes = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER;
}

if ($type !== 'video' && $type !== 'quiz') {
if ($type !== self::STEP_TYPE_VIDEO && $type !== self::STEP_TYPE_QUIZ) {
continue;
}

if ($type === 'video') {
if ($type === self::STEP_TYPE_VIDEO) {
$points = $stepDurationInMinutes * 100;
}

if ($type === 'quiz') {
if ($type === self::STEP_TYPE_QUIZ) {
$points = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER * 10;
}

$results .= json_encode(
[
'id' => $row[0],
'type' => $row[1],
'id' => $stepId,
'type' => $type,
'duration' => $stepDurationInMinutes,
'points' => $points
'points' => $points,
],
JSON_THROW_ON_ERROR
);

if ($index !== count($csvLines) - 1) {
$hasMoreRows = $index !== count($csvLines) - 1;
if ($hasMoreRows) {
$results .= ',';
}
}
Expand Down