Skip to content

Commit 3ebbcd8

Browse files
committed
[PHP] [StepStrategy] Move StepType hierarchy code constants to their parent class
1 parent 8895eb2 commit 3ebbcd8

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ final class ExerciseStepType extends StepType
88
{
99
public function code(): int
1010
{
11-
return Step::EXERCISE_STEP_TYPE;
11+
return StepType::EXERCISE_STEP_TYPE;
1212
}
1313
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public function __construct(array $quizQuestions)
1515

1616
public function code(): int
1717
{
18-
return Step::QUIZ_STEP_TYPE;
18+
return StepType::QUIZ_STEP_TYPE;
1919
}
2020
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ 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-
public const VIDEO_STEP_TYPE = 0;
13-
public const QUIZ_STEP_TYPE = 1;
14-
public const EXERCISE_STEP_TYPE = 2;
15-
1612
private string $title;
1713
private StepType $type;
1814
private ?int $videoDurationInMinutes;
@@ -31,13 +27,13 @@ public function estimatedCompletionMinutes(): int
3127
$estimation = 0;
3228

3329
switch ($this->type->code()) {
34-
case self::VIDEO_STEP_TYPE:
30+
case StepType::VIDEO_STEP_TYPE:
3531
$estimation = $this->videoDurationInMinutes;
3632
break;
37-
case self::QUIZ_STEP_TYPE:
33+
case StepType::QUIZ_STEP_TYPE:
3834
$estimation = self::QUIZ_STEP_QUESTION_DURATION_ESTIMATION_IN_MINUTES * count($this->quizQuestions);
3935
break;
40-
case self::EXERCISE_STEP_TYPE:
36+
case StepType::EXERCISE_STEP_TYPE:
4137
$estimation = self::EXERCISE_STEP_DURATION_ESTIMATION_IN_MINUTES;
4238
break;
4339
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88

99
abstract class StepType
1010
{
11+
public const VIDEO_STEP_TYPE = 0;
12+
public const QUIZ_STEP_TYPE = 1;
13+
public const EXERCISE_STEP_TYPE = 2;
14+
1115
public static function fromPrimitive(int $code, ?int $videoDurationInMinutes, ?array $quizQuestions)
1216
{
1317
switch ($code) {
14-
case Step::VIDEO_STEP_TYPE:
18+
case self::VIDEO_STEP_TYPE:
1519
return new VideoStepType($videoDurationInMinutes);
16-
case Step::QUIZ_STEP_TYPE:
20+
case self::QUIZ_STEP_TYPE:
1721
return new QuizStepType($quizQuestions);
18-
case Step::EXERCISE_STEP_TYPE:
22+
case self::EXERCISE_STEP_TYPE:
1923
return new ExerciseStepType();
2024
default:
2125
throw new InvalidArgumentException("Unrecognized Step type code");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public function __construct(int $videoDurationInMinutes)
1515

1616
public function code(): int
1717
{
18-
return Step::VIDEO_STEP_TYPE;
18+
return StepType::VIDEO_STEP_TYPE;
1919
}
2020
}

0 commit comments

Comments
 (0)