From 50b98c1b98e95079602b0e8e0864c3a520e047a7 Mon Sep 17 00:00:00 2001 From: poskrobkaA Date: Mon, 8 Apr 2024 16:13:51 +0300 Subject: [PATCH] =?UTF-8?q?MP=20-=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B8=20=D0=B4=D0=B5=D1=84=D0=BE=D0=BB=D1=82?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=82=D0=BE=D0=B2=D0=B0=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- php/description.txt | 5 ++ php/src/GildedRose.php | 29 +++++++++- php/src/Handlers/AgedBrieItemHandler.php | 28 ++++++++++ php/src/Handlers/BackStageItemHandler.php | 28 ++++++++++ php/src/Handlers/ConjuredItemHandler.php | 28 ++++++++++ php/src/Handlers/DefaultItemHandler.php | 40 +++++++++++++ php/src/Handlers/ItemHandlerInterface.php | 10 ++++ php/src/Handlers/SulfarusItemHandler.php | 28 ++++++++++ php/tests/ApprovalTest.php | 44 --------------- php/tests/DefaultItemTest.php | 55 ++++++++++++++++++ php/tests/GildedRoseTest.php | 20 ------- .../beforeRefactoring/DefaultItemTest.php | 56 +++++++++++++++++++ 12 files changed, 306 insertions(+), 65 deletions(-) create mode 100644 php/description.txt create mode 100644 php/src/Handlers/AgedBrieItemHandler.php create mode 100644 php/src/Handlers/BackStageItemHandler.php create mode 100644 php/src/Handlers/ConjuredItemHandler.php create mode 100644 php/src/Handlers/DefaultItemHandler.php create mode 100644 php/src/Handlers/ItemHandlerInterface.php create mode 100644 php/src/Handlers/SulfarusItemHandler.php delete mode 100644 php/tests/ApprovalTest.php create mode 100644 php/tests/DefaultItemTest.php delete mode 100644 php/tests/GildedRoseTest.php create mode 100644 php/tests/beforeRefactoring/DefaultItemTest.php diff --git a/php/description.txt b/php/description.txt new file mode 100644 index 00000000..8a7efc57 --- /dev/null +++ b/php/description.txt @@ -0,0 +1,5 @@ + на мой взгляд задача описана не полностью и на реальном проекте я бы такую задачу не брал в работу. +по-моему мнению ее следовало бы дополнительно обсудить с бизнес аналитиком. +как минимум вопросы + - поэтому у него нет срока хранения - что значит нет срока? ноль? если уже какой-то был указан обнулить или просто не учитывать? + - качество увеличивается пропорционально возрасту - тут по идее нужен какой-то коэффицинт пропорционалности \ No newline at end of file diff --git a/php/src/GildedRose.php b/php/src/GildedRose.php index db81ee3b..fac7a4a3 100644 --- a/php/src/GildedRose.php +++ b/php/src/GildedRose.php @@ -4,6 +4,12 @@ declare(strict_types=1); namespace GildedRose; +use GildedRose\Handlers\AgedBrieItemHandler; +use GildedRose\Handlers\BackStageItemHandler; +use GildedRose\Handlers\ConjuredItemHandler; +use GildedRose\Handlers\DefaultItemHandler; +use GildedRose\Handlers\SulfarusItemHandler; + final class GildedRose { /** @@ -14,7 +20,7 @@ final class GildedRose ) { } - public function updateQuality(): void + public function updateQuality(): array { foreach ($this->items as $item) { if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') { @@ -63,5 +69,26 @@ final class GildedRose } } } + + return $this->items; + } + + public function updateQuality1(): array + { + foreach ($this->items as $item) { + $handler = match ($item->name) { + 'Aged Brie' => new AgedBrieItemHandler(), + 'Sulfuras, Hand of Ragnaros' => new SulfarusItemHandler(), + 'Backstage passes to a TAFKAL80ETC concert' => new BackStageItemHandler(), + 'Conjured Mana Cake' => new ConjuredItemHandler(), + default => new DefaultItemHandler(), + }; + + $handler->handle($item); + + unset($handler); + } + + return $this->items; } } diff --git a/php/src/Handlers/AgedBrieItemHandler.php b/php/src/Handlers/AgedBrieItemHandler.php new file mode 100644 index 00000000..45b11982 --- /dev/null +++ b/php/src/Handlers/AgedBrieItemHandler.php @@ -0,0 +1,28 @@ +sellIn = $this->changeSallIn($item->sellIn); + $item->quality = $this->changeQuality($item->quality, $item->sellIn); + + return $item; + } + + + private function changeQuality(int $quality, int $sallIn): int + { + //Todo добавить реализацию метода + return $quality; + } + private function changeSallIn(int $sallIn): int + { + //Todo добавить реализацию метода + return $sallIn; + } +} \ No newline at end of file diff --git a/php/src/Handlers/BackStageItemHandler.php b/php/src/Handlers/BackStageItemHandler.php new file mode 100644 index 00000000..a18f457c --- /dev/null +++ b/php/src/Handlers/BackStageItemHandler.php @@ -0,0 +1,28 @@ +sellIn = $this->changeSallIn($item->sellIn); + $item->quality = $this->changeQuality($item->quality, $item->sellIn); + + return $item; + } + + + private function changeQuality(int $quality, int $sallIn): int + { + //Todo добавить реализацию метода + return $quality; + } + private function changeSallIn(int $sallIn): int + { + //Todo добавить реализацию метода + return $sallIn; + } +} \ No newline at end of file diff --git a/php/src/Handlers/ConjuredItemHandler.php b/php/src/Handlers/ConjuredItemHandler.php new file mode 100644 index 00000000..1ebaa711 --- /dev/null +++ b/php/src/Handlers/ConjuredItemHandler.php @@ -0,0 +1,28 @@ +sellIn = $this->changeSallIn($item->sellIn); + $item->quality = $this->changeQuality($item->quality, $item->sellIn); + + return $item; + } + + + private function changeQuality(int $quality, int $sallIn): int + { + //Todo добавить реализацию метода + return $quality; + } + private function changeSallIn(int $sallIn): int + { + //Todo добавить реализацию метода + return $sallIn; + } +} \ No newline at end of file diff --git a/php/src/Handlers/DefaultItemHandler.php b/php/src/Handlers/DefaultItemHandler.php new file mode 100644 index 00000000..3daf0c26 --- /dev/null +++ b/php/src/Handlers/DefaultItemHandler.php @@ -0,0 +1,40 @@ +sellIn = $this->changeSallIn($item->sellIn); + $item->quality = $this->changeQuality($item->quality, $item->sellIn); + + return $item; + } + + + private function changeQuality(int $quality, int $sallIn): int + { + if ($quality === 0) { + return 0; + } + + if ($sallIn === 0) { + return $quality - self::KOEF_DECREASE; + } + + return $quality - 1; + } + private function changeSallIn(int $sallIn): int + { + if ($sallIn === 0) { + return 0; + } + + return $sallIn - 1; + } +} \ No newline at end of file diff --git a/php/src/Handlers/ItemHandlerInterface.php b/php/src/Handlers/ItemHandlerInterface.php new file mode 100644 index 00000000..2d6f1b5e --- /dev/null +++ b/php/src/Handlers/ItemHandlerInterface.php @@ -0,0 +1,10 @@ +sellIn = $this->changeSallIn($item->sellIn); + $item->quality = $this->changeQuality($item->quality, $item->sellIn); + + return $item; + } + + + private function changeQuality(int $quality, int $sallIn): int + { + //Todo добавить реализацию метода + return $quality; + } + private function changeSallIn(int $sallIn): int + { + //Todo добавить реализацию метода + return $sallIn; + } +} \ No newline at end of file diff --git a/php/tests/ApprovalTest.php b/php/tests/ApprovalTest.php deleted file mode 100644 index 0c7220e3..00000000 --- a/php/tests/ApprovalTest.php +++ /dev/null @@ -1,44 +0,0 @@ -"foo" is more similar to the unit test from the 'Java' version - *
  • "thirtyDays" is more similar to the TextTest from the 'Java' version - * - * I suggest choosing one style to develop and deleting the other. - */ -class ApprovalTest extends TestCase -{ - - public function testFoo(): void - { - $items = [new Item('foo', 0, 0)]; - $app = new GildedRose($items); - $app->updateQuality(); - - Approvals::verifyList($items); - } - - public function testThirtyDays(): void - { - ob_start(); - - $argv = ["", "30"]; - include(__DIR__.'/../fixtures/texttest_fixture.php'); - - $output = ob_get_clean(); - - Approvals::approveString($output); - } -} diff --git a/php/tests/DefaultItemTest.php b/php/tests/DefaultItemTest.php new file mode 100644 index 00000000..efdf9731 --- /dev/null +++ b/php/tests/DefaultItemTest.php @@ -0,0 +1,55 @@ +"foo" is more similar to the unit test from the 'Java' version + *
  • "thirtyDays" is more similar to the TextTest from the 'Java' version + * + * I suggest choosing one style to develop and deleting the other. + */ +class DefaultItemTest extends TestCase +{ + public function testDefaultChange(): void + { + $items = [new Item('default', 1, 1)]; + $app = new GildedRose($items); + $actualAItems = $app->updateQuality(); + + $itemsExpected = [new Item('default', 0, 0)]; + + Assert::assertEquals($itemsExpected, $actualAItems); + } + + public function testDefaultAfterSallInChange(): void + { + $items = [new Item('default', -1, 6)]; + $app = new GildedRose($items); + $actualAItems = $app->updateQuality(); + + $itemsExpected = [new Item('default', -2, 4)]; + + Assert::assertEquals($itemsExpected, $actualAItems); + } + + public function testDefaulWithZeroSallInChange(): void + { + $items = [new Item('default', 0, 10)]; + $app = new GildedRose($items); + $actualAItems = $app->updateQuality(); + + $itemsExpected = [new Item('default', -1, 8)]; + + Assert::assertEquals($itemsExpected, $actualAItems); + } +} diff --git a/php/tests/GildedRoseTest.php b/php/tests/GildedRoseTest.php deleted file mode 100644 index 52e7ddc6..00000000 --- a/php/tests/GildedRoseTest.php +++ /dev/null @@ -1,20 +0,0 @@ -updateQuality(); - $this->assertSame('fixme', $items[0]->name); - } -} diff --git a/php/tests/beforeRefactoring/DefaultItemTest.php b/php/tests/beforeRefactoring/DefaultItemTest.php new file mode 100644 index 00000000..73ac422a --- /dev/null +++ b/php/tests/beforeRefactoring/DefaultItemTest.php @@ -0,0 +1,56 @@ +"foo" is more similar to the unit test from the 'Java' version + *
  • "thirtyDays" is more similar to the TextTest from the 'Java' version + * + * I suggest choosing one style to develop and deleting the other. + */ +class DefaultItemTest extends TestCase +{ + public function testDefaultChange(): void + { + $items = [new Item('default', 1, 1)]; + $app = new GildedRose($items); + $actualAItems = $app->updateQuality(); + + $itemsExpected = [new Item('default', 0, 0)]; + + Assert::assertEquals($itemsExpected, $actualAItems); + } + + public function testDefaultAfterSallInChange(): void + { + $items = [new Item('default', -1, 6)]; + $app = new GildedRose($items); + $actualAItems = $app->updateQuality(); + + $itemsExpected = [new Item('default', -2, 4)]; + + Assert::assertEquals($itemsExpected, $actualAItems); + } + + public function testDefaulWithZeroSallInChange(): void + { + $items = [new Item('default', 0, 10)]; + $app = new GildedRose($items); + $actualAItems = $app->updateQuality(); + + $itemsExpected = [new Item('default', -1, 8)]; + + Assert::assertEquals($itemsExpected, $actualAItems); + } +}