Skip to content

Commit 9e1c545

Browse files
committed
[PHP] [StepStrategy] Clean out temporary methods created to make the refactoring step by step + restore properties and constant visibilities
1 parent 27984b0 commit 9e1c545

File tree

5 files changed

+16
-36
lines changed

5 files changed

+16
-36
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66

77
final class ExerciseStepType extends StepType
88
{
9-
public const EXERCISE_STEP_DURATION_ESTIMATION_IN_MINUTES = 30;
9+
private const EXERCISE_STEP_DURATION_ESTIMATION_IN_MINUTES = 30;
1010

11-
public function code(): int
12-
{
13-
return StepType::EXERCISE_STEP_TYPE;
14-
}
15-
16-
public function stepEstimatedCompletionMinutes(Step $instance): int
11+
public function estimatedCompletionMinutes(): int
1712
{
1813
return self::EXERCISE_STEP_DURATION_ESTIMATION_IN_MINUTES;
1914
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@
66

77
final class QuizStepType extends StepType
88
{
9-
public const QUIZ_STEP_QUESTION_DURATION_ESTIMATION_IN_MINUTES = 3;
9+
private const QUIZ_STEP_QUESTION_DURATION_ESTIMATION_IN_MINUTES = 3;
10+
1011
private array $quizQuestions;
1112

1213
public function __construct(array $quizQuestions)
1314
{
1415
$this->quizQuestions = $quizQuestions;
1516
}
1617

17-
public function code(): int
18-
{
19-
return StepType::QUIZ_STEP_TYPE;
20-
}
21-
22-
public function stepEstimatedCompletionMinutes(Step $instance): int
18+
public function estimatedCompletionMinutes(): int
2319
{
24-
return self::QUIZ_STEP_QUESTION_DURATION_ESTIMATION_IN_MINUTES * count($instance->quizQuestions);
20+
return self::QUIZ_STEP_QUESTION_DURATION_ESTIMATION_IN_MINUTES * count($this->quizQuestions);
2521
}
2622
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@
77
final class Step
88
{
99
private string $title;
10-
public StepType $type;
11-
public ?int $videoDurationInMinutes;
12-
public ?array $quizQuestions;
10+
private StepType $type;
1311

1412
public function __construct(string $title, int $typeCode, ?int $videoDurationInMinutes, ?array $quizQuestions)
1513
{
16-
$this->title = $title;
17-
$this->type = StepType::fromPrimitive($typeCode, $videoDurationInMinutes, $quizQuestions);
18-
$this->videoDurationInMinutes = $videoDurationInMinutes;
19-
$this->quizQuestions = $quizQuestions;
14+
$this->title = $title;
15+
$this->type = StepType::fromPrimitive($typeCode, $videoDurationInMinutes, $quizQuestions);
2016
}
2117

2218
public function estimatedCompletionMinutes(): int
2319
{
24-
return $this->type->stepEstimatedCompletionMinutes($this);
20+
return $this->type->estimatedCompletionMinutes();
2521
}
2622
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
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;
11+
private const VIDEO_STEP_TYPE = 0;
12+
private const QUIZ_STEP_TYPE = 1;
13+
private const EXERCISE_STEP_TYPE = 2;
1414

1515
public static function fromPrimitive(int $code, ?int $videoDurationInMinutes, ?array $quizQuestions)
1616
{
@@ -26,7 +26,5 @@ public static function fromPrimitive(int $code, ?int $videoDurationInMinutes, ?a
2626
}
2727
}
2828

29-
abstract public function code(): int;
30-
31-
abstract public function stepEstimatedCompletionMinutes(Step $instance): int;
29+
abstract public function estimatedCompletionMinutes(): int;
3230
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@ public function __construct(int $videoDurationInMinutes)
1313
$this->videoDurationInMinutes = $videoDurationInMinutes;
1414
}
1515

16-
public function code(): int
16+
public function estimatedCompletionMinutes(): int
1717
{
18-
return StepType::VIDEO_STEP_TYPE;
19-
}
20-
21-
public function stepEstimatedCompletionMinutes(Step $instance): int
22-
{
23-
return $instance->videoDurationInMinutes;
18+
return $this->videoDurationInMinutes;
2419
}
2520
}

0 commit comments

Comments
 (0)