Skip to content

Commit 0fb5f84

Browse files
committed
[PHP] [StepStrategy] Push member down (stepEstimatedCompletionMinutes -> childs)
1 parent 612683b commit 0fb5f84

File tree

4 files changed

+59
-19
lines changed

4 files changed

+59
-19
lines changed

examples/php/php-step_strategy-01_base/src/ExerciseStepType.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,23 @@ public function code(): int
1212
{
1313
return StepType::EXERCISE_STEP_TYPE;
1414
}
15+
16+
public function stepEstimatedCompletionMinutes(Step $instance): int
17+
{
18+
$estimation = 0;
19+
20+
switch ($instance->type->code()) {
21+
case StepType::VIDEO_STEP_TYPE:
22+
$estimation = $instance->videoDurationInMinutes;
23+
break;
24+
case StepType::QUIZ_STEP_TYPE:
25+
$estimation = QuizStepType::QUIZ_STEP_QUESTION_DURATION_ESTIMATION_IN_MINUTES * count($instance->quizQuestions);
26+
break;
27+
case StepType::EXERCISE_STEP_TYPE:
28+
$estimation = ExerciseStepType::EXERCISE_STEP_DURATION_ESTIMATION_IN_MINUTES;
29+
break;
30+
}
31+
32+
return $estimation;
33+
}
1534
}

examples/php/php-step_strategy-01_base/src/QuizStepType.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,23 @@ public function code(): int
1818
{
1919
return StepType::QUIZ_STEP_TYPE;
2020
}
21+
22+
public function stepEstimatedCompletionMinutes(Step $instance): int
23+
{
24+
$estimation = 0;
25+
26+
switch ($instance->type->code()) {
27+
case StepType::VIDEO_STEP_TYPE:
28+
$estimation = $instance->videoDurationInMinutes;
29+
break;
30+
case StepType::QUIZ_STEP_TYPE:
31+
$estimation = QuizStepType::QUIZ_STEP_QUESTION_DURATION_ESTIMATION_IN_MINUTES * count($instance->quizQuestions);
32+
break;
33+
case StepType::EXERCISE_STEP_TYPE:
34+
$estimation = ExerciseStepType::EXERCISE_STEP_DURATION_ESTIMATION_IN_MINUTES;
35+
break;
36+
}
37+
38+
return $estimation;
39+
}
2140
}

examples/php/php-step_strategy-01_base/src/StepType.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,7 @@ public static function fromPrimitive(int $code, ?int $videoDurationInMinutes, ?a
2626
}
2727
}
2828

29-
public function stepEstimatedCompletionMinutes(Step $instance)
30-
{
31-
$estimation = 0;
32-
33-
switch ($instance->type->code()) {
34-
case self::VIDEO_STEP_TYPE:
35-
$estimation = $instance->videoDurationInMinutes;
36-
break;
37-
case self::QUIZ_STEP_TYPE:
38-
$estimation = QuizStepType::QUIZ_STEP_QUESTION_DURATION_ESTIMATION_IN_MINUTES * count($instance->quizQuestions);
39-
break;
40-
case self::EXERCISE_STEP_TYPE:
41-
$estimation = ExerciseStepType::EXERCISE_STEP_DURATION_ESTIMATION_IN_MINUTES;
42-
break;
43-
}
44-
45-
return $estimation;
46-
}
47-
4829
abstract public function code(): int;
30+
31+
abstract public function stepEstimatedCompletionMinutes(Step $instance): int;
4932
}

examples/php/php-step_strategy-01_base/src/VideoStepType.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,23 @@ public function code(): int
1717
{
1818
return StepType::VIDEO_STEP_TYPE;
1919
}
20+
21+
public function stepEstimatedCompletionMinutes(Step $instance): int
22+
{
23+
$estimation = 0;
24+
25+
switch ($instance->type->code()) {
26+
case StepType::VIDEO_STEP_TYPE:
27+
$estimation = $instance->videoDurationInMinutes;
28+
break;
29+
case StepType::QUIZ_STEP_TYPE:
30+
$estimation = QuizStepType::QUIZ_STEP_QUESTION_DURATION_ESTIMATION_IN_MINUTES * count($instance->quizQuestions);
31+
break;
32+
case StepType::EXERCISE_STEP_TYPE:
33+
$estimation = ExerciseStepType::EXERCISE_STEP_DURATION_ESTIMATION_IN_MINUTES;
34+
break;
35+
}
36+
37+
return $estimation;
38+
}
2039
}

0 commit comments

Comments
 (0)