From e2a1459192e5c3c933dcfa53b5ddf86ae91b0bf5 Mon Sep 17 00:00:00 2001 From: Kacper Majczak Date: Mon, 12 Sep 2022 14:33:25 +0200 Subject: [PATCH] Move classes to separate files --- php/src/AgedBrieCommand.php | 18 ++++++++ php/src/BackstageCommand.php | 27 +++++++++++ php/src/Command.php | 10 ++++ php/src/CommandFactory.php | 35 ++++++++++++++ php/src/GildedRose.php | 90 ------------------------------------ php/src/NoopCommand.php | 13 ++++++ php/src/NormalCommand.php | 17 +++++++ 7 files changed, 120 insertions(+), 90 deletions(-) create mode 100644 php/src/AgedBrieCommand.php create mode 100644 php/src/BackstageCommand.php create mode 100644 php/src/Command.php create mode 100644 php/src/CommandFactory.php create mode 100644 php/src/NoopCommand.php create mode 100644 php/src/NormalCommand.php diff --git a/php/src/AgedBrieCommand.php b/php/src/AgedBrieCommand.php new file mode 100644 index 00000000..8eba6f55 --- /dev/null +++ b/php/src/AgedBrieCommand.php @@ -0,0 +1,18 @@ +decreaseSellDate(); + + $item->increaseQuality(); + if ($item->isSellDatePassed()) { + $item->increaseQuality(); + } + } +} \ No newline at end of file diff --git a/php/src/BackstageCommand.php b/php/src/BackstageCommand.php new file mode 100644 index 00000000..836da3d8 --- /dev/null +++ b/php/src/BackstageCommand.php @@ -0,0 +1,27 @@ +decreaseSellDate(); + + if ($item->isSellDatePassed()) { + $item->quality = 0; + return; + } + + $item->increaseQuality(); + if ($item->sell_in <= 10) { + $item->increaseQuality(); + } + + if ($item->sell_in <= 5) { + $item->increaseQuality(); + } + } +} \ No newline at end of file diff --git a/php/src/Command.php b/php/src/Command.php new file mode 100644 index 00000000..99769748 --- /dev/null +++ b/php/src/Command.php @@ -0,0 +1,10 @@ +decreaseSellDate(); - - $item->increaseQuality(); - if ($item->isSellDatePassed()) { - $item->increaseQuality(); - } - } -} - -final class BackstageCommand implements Command -{ - public function execute(Item $item): void - { - $item->decreaseSellDate(); - - if ($item->isSellDatePassed()) { - $item->quality = 0; - return; - } - - $item->increaseQuality(); - if ($item->sell_in <= 10) { - $item->increaseQuality(); - } - - if ($item->sell_in <= 5) { - $item->increaseQuality(); - } - } -} - -final class NormalCommand implements Command -{ - public function execute(Item $item): void - { - $item->decreaseSellDate(); - $item->decreaseQuality(); - if ($item->isSellDatePassed()) { - $item->decreaseQuality(); - } - } -} - -final class NoopCommand implements Command -{ - public function execute(Item $item): void - { - // noop - } -} \ No newline at end of file diff --git a/php/src/NoopCommand.php b/php/src/NoopCommand.php new file mode 100644 index 00000000..2af4aa84 --- /dev/null +++ b/php/src/NoopCommand.php @@ -0,0 +1,13 @@ +decreaseSellDate(); + $item->decreaseQuality(); + if ($item->isSellDatePassed()) { + $item->decreaseQuality(); + } + } +} \ No newline at end of file