From 32c7f62f3f801e2714e8d1b34e20036d40b1bb4b Mon Sep 17 00:00:00 2001 From: Tomas Norre Mikkelsen Date: Fri, 23 Feb 2024 19:05:58 +0100 Subject: [PATCH] Update after iteration 1 --- .../practice/food-chain/.meta/example.php | 24 +++++++++---------- exercises/practice/food-chain/FoodChain.php | 6 ++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/exercises/practice/food-chain/.meta/example.php b/exercises/practice/food-chain/.meta/example.php index 2be2fbcd..dd39ba58 100644 --- a/exercises/practice/food-chain/.meta/example.php +++ b/exercises/practice/food-chain/.meta/example.php @@ -4,7 +4,7 @@ class FoodChain { - private static array $verse = [ + private const VERSE = [ ["", ""], ["fly", "I don't know why she swallowed the fly. Perhaps she'll die."], ["spider", "It wriggled and jiggled and tickled inside her."], @@ -16,20 +16,20 @@ class FoodChain ["horse", "She's dead, of course!"], ]; - public static function verse(int $verseNumber): array + public function verse(int $verseNumber): array { $result = []; - $result[] = sprintf("I know an old lady who swallowed a %s.", self::$verse[$verseNumber][0]); - $result[] = self::$verse[$verseNumber][1]; + $result[] = sprintf("I know an old lady who swallowed a %s.", self::VERSE[$verseNumber][0]); + $result[] = self::VERSE[$verseNumber][1]; if ($verseNumber === 1 || $verseNumber === 8) { return $result; } for (; $verseNumber > 1; $verseNumber--) { $text = sprintf( "She swallowed the %s to catch the %s%s", - self::$verse[$verseNumber][0], - self::$verse[$verseNumber - 1][0], + self::VERSE[$verseNumber][0], + self::VERSE[$verseNumber - 1][0], $verseNumber !== 3 ? "." : "" ); if ($verseNumber === 3) { @@ -37,26 +37,26 @@ public static function verse(int $verseNumber): array } $result[] = $text; } - $result[] = self::$verse[$verseNumber][1]; + $result[] = self::VERSE[$verseNumber][1]; return $result; } - public static function verses(int $start, int $end): array + public function verses(int $start, int $end): array { if ($start < 1 || $start > $end || $end > 8) { - return self::verse(0); + return $this->verse(0); } $s = self::verse($start); while ($start < $end) { $start++; $s[] = ""; - $s = array_merge($s, self::verse($start)); + $s = array_merge($s, $this->verse($start)); } return $s; } - public static function song(): array + public function song(): array { - return self::verses(1, 8); + return $this->verses(1, 8); } } diff --git a/exercises/practice/food-chain/FoodChain.php b/exercises/practice/food-chain/FoodChain.php index 45345cfe..8cd60bae 100644 --- a/exercises/practice/food-chain/FoodChain.php +++ b/exercises/practice/food-chain/FoodChain.php @@ -26,17 +26,17 @@ class FoodChain { - public static function verse(int $verseNumber): array + public function verse(int $verseNumber): array { throw new \BadMethodCallException(sprintf('Implement the %s method', __FUNCTION__)); } - public static function verses(int $start, int $end): array + public function verses(int $start, int $end): array { throw new \BadMethodCallException(sprintf('Implement the %s method', __FUNCTION__)); } - public static function song(): array + public function song(): array { throw new \BadMethodCallException(sprintf('Implement the %s method', __FUNCTION__)); }