Skip to content

Commit 8895eb2

Browse files
committed
[PHP] [StepStrategy] Start using the StepType hirearchy
1 parent cbc3d83 commit 8895eb2

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
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
@@ -4,7 +4,7 @@
44

55
namespace CodelyTv\StepStrategy;
66

7-
final class ExerciseStepType
7+
final class ExerciseStepType extends StepType
88
{
99
public function code(): int
1010
{

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
@@ -4,7 +4,7 @@
44

55
namespace CodelyTv\StepStrategy;
66

7-
final class QuizStepType
7+
final class QuizStepType extends StepType
88
{
99
private array $quizQuestions;
1010

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ final class Step
1313
public const QUIZ_STEP_TYPE = 1;
1414
public const EXERCISE_STEP_TYPE = 2;
1515

16-
private string $title;
17-
private int $type;
18-
private ?int $videoDurationInMinutes;
19-
private ?array $quizQuestions;
16+
private string $title;
17+
private StepType $type;
18+
private ?int $videoDurationInMinutes;
19+
private ?array $quizQuestions;
2020

21-
public function __construct(string $title, int $type, ?int $videoDurationInMinutes, ?array $quizQuestions)
21+
public function __construct(string $title, int $typeCode, ?int $videoDurationInMinutes, ?array $quizQuestions)
2222
{
2323
$this->title = $title;
24-
$this->type = $type;
24+
$this->type = StepType::fromPrimitive($typeCode, $videoDurationInMinutes, $quizQuestions);
2525
$this->videoDurationInMinutes = $videoDurationInMinutes;
2626
$this->quizQuestions = $quizQuestions;
2727
}
@@ -30,7 +30,7 @@ public function estimatedCompletionMinutes(): int
3030
{
3131
$estimation = 0;
3232

33-
switch ($this->type) {
33+
switch ($this->type->code()) {
3434
case self::VIDEO_STEP_TYPE:
3535
$estimation = $this->videoDurationInMinutes;
3636
break;

0 commit comments

Comments
 (0)