From d2f05b5011cf7f53ca93c4a832c18b045a3cebef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 12:19:29 +0200 Subject: [PATCH 01/15] Rename --- .../src/Controller/CourseStepsGetController.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index cd144d72..33bc56bd 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -8,6 +8,7 @@ final class CourseStepsGetController { + const VIDEO_DURATION_PAUSES_MULTIPLIER = 1.1; private Platform $platform; public function __construct(Platform $platform) @@ -31,15 +32,16 @@ public function get(string $courseId): string } $type = $row[1]; - $duration = 0; + $stepDuration = 0; $points = 0; + $videoDuration = $row[3]; if ($type === 'video') { - $duration = $row[3] * 1.1; // 1.1 = due to video pauses + $stepDuration = $videoDuration * self::VIDEO_DURATION_PAUSES_MULTIPLIER; } if ($type === 'quiz') { - $duration = $row[2] * 0.5; // 0.5 = time in minutes per question + $stepDuration = $row[2] * 0.5; // 0.5 = time in minutes per question } if ($type !== 'video' && $type !== 'quiz') { @@ -47,7 +49,7 @@ public function get(string $courseId): string } if ($type === 'video') { - $points = $row[3] * 1.1 * 100; + $points = $stepDuration * 100; } if ($type === 'quiz') { @@ -58,7 +60,7 @@ public function get(string $courseId): string [ 'id' => $row[0], 'type' => $row[1], - 'duration' => $duration, + 'duration' => $stepDuration, 'points' => $points ], JSON_THROW_ON_ERROR From 5a6077aabe6182e5f7c5520ec48556e71e643eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 12:24:25 +0200 Subject: [PATCH 02/15] Rename --- .../src/Controller/CourseStepsGetController.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index 33bc56bd..9e5775e0 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -8,7 +8,8 @@ final class CourseStepsGetController { - const VIDEO_DURATION_PAUSES_MULTIPLIER = 1.1; + const VIDEO_DURATION_PAUSES_MULTIPLIER = 1.1; + const QUIZ_TIME_PER_QUESTION_MULTIPLIER = 0.5; private Platform $platform; public function __construct(Platform $platform) @@ -32,16 +33,17 @@ public function get(string $courseId): string } $type = $row[1]; - $stepDuration = 0; + $stepDurationInMinutes = 0; $points = 0; $videoDuration = $row[3]; if ($type === 'video') { - $stepDuration = $videoDuration * self::VIDEO_DURATION_PAUSES_MULTIPLIER; + $stepDurationInMinutes = $videoDuration * self::VIDEO_DURATION_PAUSES_MULTIPLIER; } + $quizTotalQuestions = $row[2]; if ($type === 'quiz') { - $stepDuration = $row[2] * 0.5; // 0.5 = time in minutes per question + $stepDurationInMinutes = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER; } if ($type !== 'video' && $type !== 'quiz') { @@ -49,18 +51,18 @@ public function get(string $courseId): string } if ($type === 'video') { - $points = $stepDuration * 100; + $points = $stepDurationInMinutes * 100; } if ($type === 'quiz') { - $points = $row[2] * 0.5 * 10; + $points = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER * 10; } $results .= json_encode( [ 'id' => $row[0], 'type' => $row[1], - 'duration' => $stepDuration, + 'duration' => $stepDurationInMinutes, 'points' => $points ], JSON_THROW_ON_ERROR From 4f22e1bf0be737097e7d3c2098ca75d9e7a79667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 12:28:33 +0200 Subject: [PATCH 03/15] Rename --- .../Controller/CourseStepsGetController.php | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index 9e5775e0..6deb4b67 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -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) @@ -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 .= ','; } } From 376fe3ff281040fe1704736a1cfabd050d08af1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 12:29:31 +0200 Subject: [PATCH 04/15] Rename --- .../src/Controller/CourseStepsGetController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index 6deb4b67..a08a51e5 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -11,7 +11,9 @@ 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'; + const STEP_TYPE_QUIZ = 'quiz'; + const VIDEO_POINTS_PER_MINUTE = 100; + const QUIZ_POINTS_PER_MINUTE = 10; private Platform $platform; public function __construct(Platform $platform) @@ -52,11 +54,11 @@ public function get(string $courseId): string } if ($type === self::STEP_TYPE_VIDEO) { - $points = $stepDurationInMinutes * 100; + $points = $stepDurationInMinutes * self::VIDEO_POINTS_PER_MINUTE; } if ($type === self::STEP_TYPE_QUIZ) { - $points = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER * 10; + $points = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER * self::QUIZ_POINTS_PER_MINUTE; } $results .= json_encode( From 53fa6612179513f52b5cb5512459d9a033c21e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 12:34:10 +0200 Subject: [PATCH 05/15] Rename --- .../src/Controller/CourseStepsGetController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index a08a51e5..15d5e809 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -58,7 +58,7 @@ public function get(string $courseId): string } if ($type === self::STEP_TYPE_QUIZ) { - $points = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER * self::QUIZ_POINTS_PER_MINUTE; + $points = $stepDurationInMinutes * self::QUIZ_POINTS_PER_MINUTE; } $results .= json_encode( From 0b1b2f845cde18098673a1480df81d18f3a6cc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 12:40:17 +0200 Subject: [PATCH 06/15] ESTE ES UN STEP TEMPORAL --- .../Controller/CourseStepsGetController.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index 15d5e809..46cc093e 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -79,6 +79,60 @@ public function get(string $courseId): string $results .= ']'; + $results = '['; + + $csvLines = explode(PHP_EOL, $csv); + + foreach ($csvLines as $index => $row) { + $row = str_getcsv($row); + + if (empty($csv)) { + continue; + } + + [$stepId, $type, $quizTotalQuestions, $videoDuration] = $row; + + $stepDurationInMinutes = 0; + $points = 0; + + if ($type === self::STEP_TYPE_VIDEO) { + $stepDurationInMinutes = $videoDuration * self::VIDEO_DURATION_PAUSES_MULTIPLIER; + } + + if ($type === self::STEP_TYPE_QUIZ) { + $stepDurationInMinutes = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER; + } + + if ($type !== self::STEP_TYPE_VIDEO && $type !== self::STEP_TYPE_QUIZ) { + continue; + } + + if ($type === self::STEP_TYPE_VIDEO) { + $points = $stepDurationInMinutes * self::VIDEO_POINTS_PER_MINUTE; + } + + if ($type === self::STEP_TYPE_QUIZ) { + $points = $stepDurationInMinutes * self::QUIZ_POINTS_PER_MINUTE; + } + + $results .= json_encode( + [ + 'id' => $stepId, + 'type' => $type, + 'duration' => $stepDurationInMinutes, + 'points' => $points, + ], + JSON_THROW_ON_ERROR + ); + + $hasMoreRows = $index !== count($csvLines) - 1; + if ($hasMoreRows) { + $results .= ','; + } + } + + $results .= ']'; + return $results; } } From 1d6a43f6580345a18c26d95ef62bf606f3bbd7e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 12:47:36 +0200 Subject: [PATCH 07/15] ESTE ES UN STEP TEMPORAL --- .../Controller/CourseStepsGetController.php | 55 +++++-------------- 1 file changed, 13 insertions(+), 42 deletions(-) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index 46cc093e..9d724258 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -24,61 +24,32 @@ public function __construct(Platform $platform) public function get(string $courseId): string { $csv = $this->platform->findCourseSteps($courseId); - + if (empty($csv)) { + return '[]'; + } $results = '['; $csvLines = explode(PHP_EOL, $csv); - foreach ($csvLines as $index => $row) { + $parsedCsv = []; + foreach ($csvLines as $row) { $row = str_getcsv($row); - if (empty($csv)) { - continue; - } - [$stepId, $type, $quizTotalQuestions, $videoDuration] = $row; - $stepDurationInMinutes = 0; - $points = 0; - - if ($type === self::STEP_TYPE_VIDEO) { - $stepDurationInMinutes = $videoDuration * self::VIDEO_DURATION_PAUSES_MULTIPLIER; - } - - if ($type === self::STEP_TYPE_QUIZ) { - $stepDurationInMinutes = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER; - } - - if ($type !== self::STEP_TYPE_VIDEO && $type !== self::STEP_TYPE_QUIZ) { + $isRecognizedStepType = $type !== self::STEP_TYPE_VIDEO && $type !== self::STEP_TYPE_QUIZ; + if ($isRecognizedStepType) { continue; } - if ($type === self::STEP_TYPE_VIDEO) { - $points = $stepDurationInMinutes * self::VIDEO_POINTS_PER_MINUTE; - } - - if ($type === self::STEP_TYPE_QUIZ) { - $points = $stepDurationInMinutes * self::QUIZ_POINTS_PER_MINUTE; - } - - $results .= json_encode( - [ - 'id' => $stepId, - 'type' => $type, - 'duration' => $stepDurationInMinutes, - 'points' => $points, - ], - JSON_THROW_ON_ERROR - ); - - $hasMoreRows = $index !== count($csvLines) - 1; - if ($hasMoreRows) { - $results .= ','; - } + $parsedCsv[] = [ + 'stepId' => $stepId, + 'type' => $type, + 'quizTotalQuestions' => $quizTotalQuestions, + 'videoDuration' => $videoDuration, + ]; } - $results .= ']'; - $results = '['; $csvLines = explode(PHP_EOL, $csv); From e7b9e6c17154975e14b16ac664ea27098756cc87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 12:50:06 +0200 Subject: [PATCH 08/15] ESTE ES UN STEP TEMPORAL --- .../Controller/CourseStepsGetController.php | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index 9d724258..a1c25935 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -27,28 +27,10 @@ public function get(string $courseId): string if (empty($csv)) { return '[]'; } - $results = '['; $csvLines = explode(PHP_EOL, $csv); - $parsedCsv = []; - foreach ($csvLines as $row) { - $row = str_getcsv($row); - - [$stepId, $type, $quizTotalQuestions, $videoDuration] = $row; - - $isRecognizedStepType = $type !== self::STEP_TYPE_VIDEO && $type !== self::STEP_TYPE_QUIZ; - if ($isRecognizedStepType) { - continue; - } - - $parsedCsv[] = [ - 'stepId' => $stepId, - 'type' => $type, - 'quizTotalQuestions' => $quizTotalQuestions, - 'videoDuration' => $videoDuration, - ]; - } + $parsedCsv = $this->parseCsv($csvLines); $results = '['; @@ -106,4 +88,28 @@ public function get(string $courseId): string return $results; } + + private function parseCsv(array $csvLines): array + { + $parsedCsv = []; + foreach ($csvLines as $row) { + $row = str_getcsv($row); + + [$stepId, $type, $quizTotalQuestions, $videoDuration] = $row; + + $isRecognizedStepType = $type !== self::STEP_TYPE_VIDEO && $type !== self::STEP_TYPE_QUIZ; + if ($isRecognizedStepType) { + continue; + } + + $parsedCsv[] = [ + 'stepId' => $stepId, + 'type' => $type, + 'quizTotalQuestions' => $quizTotalQuestions, + 'videoDuration' => $videoDuration, + ]; + } + + return $parsedCsv; + } } From 792d65dab63005f6ac05091b615b072e57366e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 12:55:51 +0200 Subject: [PATCH 09/15] ESTE ES UN STEP TEMPORAL --- .../Controller/CourseStepsGetController.php | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index a1c25935..f9a2b84d 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -8,12 +8,13 @@ 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'; - const VIDEO_POINTS_PER_MINUTE = 100; - const QUIZ_POINTS_PER_MINUTE = 10; + private const VIDEO_DURATION_PAUSES_MULTIPLIER = 1.1; + private const QUIZ_TIME_PER_QUESTION_MULTIPLIER = 0.5; + private const STEP_TYPE_VIDEO = 'video'; + private const STEP_TYPE_QUIZ = 'quiz'; + private const VIDEO_POINTS_PER_MINUTE = 100; + private const QUIZ_POINTS_PER_MINUTE = 10; + private Platform $platform; public function __construct(Platform $platform) @@ -28,22 +29,15 @@ public function get(string $courseId): string return '[]'; } - $csvLines = explode(PHP_EOL, $csv); - - $parsedCsv = $this->parseCsv($csvLines); + $parsedCsv = $this->parseCsv($csv); $results = '['; - $csvLines = explode(PHP_EOL, $csv); - - foreach ($csvLines as $index => $row) { - $row = str_getcsv($row); - - if (empty($csv)) { - continue; - } - - [$stepId, $type, $quizTotalQuestions, $videoDuration] = $row; + foreach ($parsedCsv as $index => $row) { + $stepId = $row['stepId']; + $type = $row['type']; + $quizTotalQuestions = $row['quizTotalQuestions']; + $videoDuration = $row['videoDuration']; $stepDurationInMinutes = 0; $points = 0; @@ -78,7 +72,7 @@ public function get(string $courseId): string JSON_THROW_ON_ERROR ); - $hasMoreRows = $index !== count($csvLines) - 1; + $hasMoreRows = $index !== count($parsedCsv) - 1; if ($hasMoreRows) { $results .= ','; } @@ -89,8 +83,10 @@ public function get(string $courseId): string return $results; } - private function parseCsv(array $csvLines): array + private function parseCsv(string $csv): array { + $csvLines = explode(PHP_EOL, $csv); + $parsedCsv = []; foreach ($csvLines as $row) { $row = str_getcsv($row); From 6ae0c75606ceec6bd52c367a3b049a55b2273ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 13:05:10 +0200 Subject: [PATCH 10/15] ESTE ES UN STEP TEMPORAL --- .../Controller/CourseStepsGetController.php | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index f9a2b84d..25352a68 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -14,7 +14,6 @@ final class CourseStepsGetController private const STEP_TYPE_QUIZ = 'quiz'; private const VIDEO_POINTS_PER_MINUTE = 100; private const QUIZ_POINTS_PER_MINUTE = 10; - private Platform $platform; public function __construct(Platform $platform) @@ -31,8 +30,7 @@ public function get(string $courseId): string $parsedCsv = $this->parseCsv($csv); - $results = '['; - + $steps = []; foreach ($parsedCsv as $index => $row) { $stepId = $row['stepId']; $type = $row['type']; @@ -50,8 +48,39 @@ public function get(string $courseId): string $stepDurationInMinutes = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER; } - if ($type !== self::STEP_TYPE_VIDEO && $type !== self::STEP_TYPE_QUIZ) { - continue; + if ($type === self::STEP_TYPE_VIDEO) { + $points = $stepDurationInMinutes * self::VIDEO_POINTS_PER_MINUTE; + } + + if ($type === self::STEP_TYPE_QUIZ) { + $points = $stepDurationInMinutes * self::QUIZ_POINTS_PER_MINUTE; + } + + $steps[] = [ + 'id' => $stepId, + 'type' => $type, + 'duration' => $stepDurationInMinutes, + 'points' => $points, + ]; + } + + $results = '['; + + foreach ($parsedCsv as $index => $row) { + $stepId = $row['stepId']; + $type = $row['type']; + $quizTotalQuestions = $row['quizTotalQuestions']; + $videoDuration = $row['videoDuration']; + + $stepDurationInMinutes = 0; + $points = 0; + + if ($type === self::STEP_TYPE_VIDEO) { + $stepDurationInMinutes = $videoDuration * self::VIDEO_DURATION_PAUSES_MULTIPLIER; + } + + if ($type === self::STEP_TYPE_QUIZ) { + $stepDurationInMinutes = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER; } if ($type === self::STEP_TYPE_VIDEO) { From d04347192823512926039703f3023ca5a83e1f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 13:07:20 +0200 Subject: [PATCH 11/15] ESTE ES UN STEP TEMPORAL --- .../Controller/CourseStepsGetController.php | 36 ++----------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index 25352a68..22ef2a6e 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -66,40 +66,8 @@ public function get(string $courseId): string $results = '['; - foreach ($parsedCsv as $index => $row) { - $stepId = $row['stepId']; - $type = $row['type']; - $quizTotalQuestions = $row['quizTotalQuestions']; - $videoDuration = $row['videoDuration']; - - $stepDurationInMinutes = 0; - $points = 0; - - if ($type === self::STEP_TYPE_VIDEO) { - $stepDurationInMinutes = $videoDuration * self::VIDEO_DURATION_PAUSES_MULTIPLIER; - } - - if ($type === self::STEP_TYPE_QUIZ) { - $stepDurationInMinutes = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER; - } - - if ($type === self::STEP_TYPE_VIDEO) { - $points = $stepDurationInMinutes * self::VIDEO_POINTS_PER_MINUTE; - } - - if ($type === self::STEP_TYPE_QUIZ) { - $points = $stepDurationInMinutes * self::QUIZ_POINTS_PER_MINUTE; - } - - $results .= json_encode( - [ - 'id' => $stepId, - 'type' => $type, - 'duration' => $stepDurationInMinutes, - 'points' => $points, - ], - JSON_THROW_ON_ERROR - ); + foreach ($steps as $index => $step) { + $results .= json_encode($step, JSON_THROW_ON_ERROR); $hasMoreRows = $index !== count($parsedCsv) - 1; if ($hasMoreRows) { From d03e986efb9a1f898b690cc95e3c575345b2f4a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 13:08:33 +0200 Subject: [PATCH 12/15] ESTE ES UN STEP TEMPORAL --- .../src/Controller/CourseStepsGetController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index 22ef2a6e..1f090ad7 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -69,7 +69,7 @@ public function get(string $courseId): string foreach ($steps as $index => $step) { $results .= json_encode($step, JSON_THROW_ON_ERROR); - $hasMoreRows = $index !== count($parsedCsv) - 1; + $hasMoreRows = $index !== count($steps) - 1; if ($hasMoreRows) { $results .= ','; } From 7bd1784e37ccf6d7879e0e49ee35c4ec3d876864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 13:10:38 +0200 Subject: [PATCH 13/15] ESTE ES UN STEP TEMPORAL --- .../Controller/CourseStepsGetController.php | 73 ++++++++++--------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index 1f090ad7..79623a5b 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -29,40 +29,7 @@ public function get(string $courseId): string } $parsedCsv = $this->parseCsv($csv); - - $steps = []; - foreach ($parsedCsv as $index => $row) { - $stepId = $row['stepId']; - $type = $row['type']; - $quizTotalQuestions = $row['quizTotalQuestions']; - $videoDuration = $row['videoDuration']; - - $stepDurationInMinutes = 0; - $points = 0; - - if ($type === self::STEP_TYPE_VIDEO) { - $stepDurationInMinutes = $videoDuration * self::VIDEO_DURATION_PAUSES_MULTIPLIER; - } - - if ($type === self::STEP_TYPE_QUIZ) { - $stepDurationInMinutes = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER; - } - - if ($type === self::STEP_TYPE_VIDEO) { - $points = $stepDurationInMinutes * self::VIDEO_POINTS_PER_MINUTE; - } - - if ($type === self::STEP_TYPE_QUIZ) { - $points = $stepDurationInMinutes * self::QUIZ_POINTS_PER_MINUTE; - } - - $steps[] = [ - 'id' => $stepId, - 'type' => $type, - 'duration' => $stepDurationInMinutes, - 'points' => $points, - ]; - } + $steps = $this->createStepsFromPrimitives($parsedCsv); $results = '['; @@ -105,4 +72,42 @@ private function parseCsv(string $csv): array return $parsedCsv; } + + private function createStepsFromPrimitives(array $parsedCsv): array + { + $steps = []; + foreach ($parsedCsv as $row) { + $stepId = $row['stepId']; + $type = $row['type']; + $quizTotalQuestions = $row['quizTotalQuestions']; + $videoDuration = $row['videoDuration']; + + $stepDurationInMinutes = 0; + $points = 0; + + if ($type === self::STEP_TYPE_VIDEO) { + $stepDurationInMinutes = $videoDuration * self::VIDEO_DURATION_PAUSES_MULTIPLIER; + } + + if ($type === self::STEP_TYPE_QUIZ) { + $stepDurationInMinutes = $quizTotalQuestions * self::QUIZ_TIME_PER_QUESTION_MULTIPLIER; + } + + if ($type === self::STEP_TYPE_VIDEO) { + $points = $stepDurationInMinutes * self::VIDEO_POINTS_PER_MINUTE; + } + + if ($type === self::STEP_TYPE_QUIZ) { + $points = $stepDurationInMinutes * self::QUIZ_POINTS_PER_MINUTE; + } + + $steps[] = [ + 'id' => $stepId, + 'type' => $type, + 'duration' => $stepDurationInMinutes, + 'points' => $points, + ]; + } + return $steps; + } } From 6b7bbdf04d468b90cfad5d3f18c18e22a70b8ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Wed, 14 Apr 2021 13:22:42 +0200 Subject: [PATCH 14/15] ESTE ES UN STEP TEMPORAL --- .../Controller/CourseStepsGetController.php | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index 79623a5b..a0a2c7fa 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -23,32 +23,19 @@ public function __construct(Platform $platform) public function get(string $courseId): string { - $csv = $this->platform->findCourseSteps($courseId); - if (empty($csv)) { - return '[]'; - } - + $csv = $this->platform->findCourseSteps($courseId); $parsedCsv = $this->parseCsv($csv); $steps = $this->createStepsFromPrimitives($parsedCsv); - $results = '['; - - foreach ($steps as $index => $step) { - $results .= json_encode($step, JSON_THROW_ON_ERROR); - - $hasMoreRows = $index !== count($steps) - 1; - if ($hasMoreRows) { - $results .= ','; - } - } - - $results .= ']'; - - return $results; + return $this->toJson($steps); } private function parseCsv(string $csv): array { + if (empty($csv)) { + return []; + } + $csvLines = explode(PHP_EOL, $csv); $parsedCsv = []; @@ -108,6 +95,24 @@ private function createStepsFromPrimitives(array $parsedCsv): array 'points' => $points, ]; } + return $steps; } + + private function toJson(array $steps): string + { + $results = '['; + + foreach ($steps as $index => $step) { + $results .= json_encode($step, JSON_THROW_ON_ERROR); + + $hasMoreRows = $index !== count($steps) - 1; + if ($hasMoreRows) { + $results .= ','; + } + } + + $results .= ']'; + return $results; + } } From a1ef54da6fcd7fba4b71bec59fa8801d834c7616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=20G=C3=B3mez?= Date: Thu, 22 Apr 2021 11:17:50 +0200 Subject: [PATCH 15/15] idk --- .../src/Controller/CourseStepsGetController.php | 7 +++++-- .../tests/Controller/CourseStepRepository.php | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 examples/php/php-divergent_change-01_base/tests/Controller/CourseStepRepository.php diff --git a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php index a0a2c7fa..d1c07d04 100644 --- a/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php +++ b/examples/php/php-divergent_change-01_base/src/Controller/CourseStepsGetController.php @@ -5,6 +5,7 @@ namespace CodelyTv\DivergentChange\Controller; use CodelyTv\DivergentChange\Platform; +use CodelyTv\DivergentChange\Tests\Controller\CourseStepRepository; final class CourseStepsGetController { @@ -14,11 +15,13 @@ final class CourseStepsGetController private const STEP_TYPE_QUIZ = 'quiz'; private const VIDEO_POINTS_PER_MINUTE = 100; private const QUIZ_POINTS_PER_MINUTE = 10; - private Platform $platform; + private Platform $platform; + private CourseStepRepository $repository; - public function __construct(Platform $platform) + public function __construct(Platform $platform, CourseStepRepository $repository) { $this->platform = $platform; + $this->repository = $repository; } public function get(string $courseId): string diff --git a/examples/php/php-divergent_change-01_base/tests/Controller/CourseStepRepository.php b/examples/php/php-divergent_change-01_base/tests/Controller/CourseStepRepository.php new file mode 100644 index 00000000..f0acb747 --- /dev/null +++ b/examples/php/php-divergent_change-01_base/tests/Controller/CourseStepRepository.php @@ -0,0 +1,10 @@ +