@@ -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