Skip to content

Commit 6772923

Browse files
committed
[PHP] [StepStrategy] Define typed code constants as a first step towards polymorphism
1 parent 2cf2689 commit 6772923

File tree

1 file changed

+8
-4
lines changed
  • examples/php/php-step_strategy-02_replace_type_code_with_strategy/src

1 file changed

+8
-4
lines changed

examples/php/php-step_strategy-02_replace_type_code_with_strategy/src/Step.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ final class Step
99
private const EXERCISE_STEP_DURATION_ESTIMATION_IN_MINUTES = 30;
1010
private const QUIZ_STEP_QUESTION_DURATION_ESTIMATION_IN_MINUTES = 3;
1111

12+
private const VIDEO_STEP_TYPE = 0;
13+
private const QUIZ_STEP_TYPE = 1;
14+
private const EXERCISE_STEP_TYPE = 2;
15+
1216
private string $title;
13-
private int $type; // 0: Video, 1: Quizz, 2: Exercise
17+
private int $type;
1418
private ?int $videoDurationInMinutes;
1519
private ?array $quizQuestions;
1620

@@ -26,11 +30,11 @@ public function estimatedCompletionMinutes(): int
2630
{
2731
$estimation = 0;
2832

29-
if ($this->type === 0) { // Video
33+
if ($this->type === self::VIDEO_STEP_TYPE) {
3034
$estimation = $this->videoDurationInMinutes;
31-
} elseif ($this->type === 1) { // Quizz
35+
} elseif ($this->type === self::QUIZ_STEP_TYPE) {
3236
$estimation = self::QUIZ_STEP_QUESTION_DURATION_ESTIMATION_IN_MINUTES * count($this->quizQuestions);
33-
} elseif ($this->type === 2) { // Exercise
37+
} elseif ($this->type === self::EXERCISE_STEP_TYPE) {
3438
$estimation = self::EXERCISE_STEP_DURATION_ESTIMATION_IN_MINUTES;
3539
}
3640

0 commit comments

Comments
 (0)