Skip to content

Commit b7e95d2

Browse files
committed
Refactoring: Split code into smaller readable chunks
1 parent bf04dc7 commit b7e95d2

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

src/Dal/FoodItemDal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function (object $itemBean): array {
4949
}, $itemsBean);
5050
}
5151

52-
public static function createDefaultItem(ItemEntity $itemEntity): int|string
52+
public static function insertDefaultItem(ItemEntity $itemEntity): int|string
5353
{
5454
$itemBan = R::dispense(self::TABLE_NAME);
5555

src/Service/FoodItem.php

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,7 @@ public function retrieveAll(): array
4242
$items = FoodItemDal::getAll();
4343

4444
if (count($items) === 0) {
45-
// if no items have been added yet, create the first one
46-
$itemUuid = Uuid::uuid4()->toString();
47-
$itemEntity = new ItemEntity();
48-
49-
// chaining each method with the arrow ->
50-
$itemEntity
51-
->setItemUuid($itemUuid)
52-
->setName('Burrito Cheese with French Fries')
53-
->setPrice(19.99)
54-
->setAvailable(true);
55-
56-
FoodItemDal::createDefaultItem($itemEntity);
45+
$this->createDefaultItem();
5746

5847
// then, get again all items
5948
// to retrieve the new one that just got added
@@ -62,4 +51,25 @@ public function retrieveAll(): array
6251

6352
return $items;
6453
}
54+
55+
private function createDefaultItem(): void
56+
{
57+
// default item values
58+
$defaultPrice = 19.99;
59+
$isEnabled = true;
60+
61+
62+
// if no items have been added yet, create the first one
63+
$itemUuid = Uuid::uuid4()->toString();
64+
$itemEntity = new ItemEntity();
65+
66+
// chaining each method with the arrow ->
67+
$itemEntity
68+
->setItemUuid($itemUuid)
69+
->setName('Burrito Cheese with French Fries')
70+
->setPrice($defaultPrice)
71+
->setAvailable($isEnabled);
72+
73+
FoodItemDal::insertDefaultItem($itemEntity);
74+
}
6575
}

0 commit comments

Comments
 (0)