Skip to content

Commit

Permalink
Refactoring: Split code into smaller readable chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
pH-7 committed Aug 20, 2023
1 parent bf04dc7 commit b7e95d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Dal/FoodItemDal.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function (object $itemBean): array {
}, $itemsBean);
}

public static function createDefaultItem(ItemEntity $itemEntity): int|string
public static function insertDefaultItem(ItemEntity $itemEntity): int|string
{
$itemBan = R::dispense(self::TABLE_NAME);

Expand Down
34 changes: 22 additions & 12 deletions src/Service/FoodItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,7 @@ public function retrieveAll(): array
$items = FoodItemDal::getAll();

if (count($items) === 0) {
// if no items have been added yet, create the first one
$itemUuid = Uuid::uuid4()->toString();
$itemEntity = new ItemEntity();

// chaining each method with the arrow ->
$itemEntity
->setItemUuid($itemUuid)
->setName('Burrito Cheese with French Fries')
->setPrice(19.99)
->setAvailable(true);

FoodItemDal::createDefaultItem($itemEntity);
$this->createDefaultItem();

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

return $items;
}

private function createDefaultItem(): void
{
// default item values
$defaultPrice = 19.99;
$isEnabled = true;


// if no items have been added yet, create the first one
$itemUuid = Uuid::uuid4()->toString();
$itemEntity = new ItemEntity();

// chaining each method with the arrow ->
$itemEntity
->setItemUuid($itemUuid)
->setName('Burrito Cheese with French Fries')
->setPrice($defaultPrice)
->setAvailable($isEnabled);

FoodItemDal::insertDefaultItem($itemEntity);
}
}

0 comments on commit b7e95d2

Please sign in to comment.