diff --git a/composer.lock b/composer.lock index 8d4a424..08762c5 100644 --- a/composer.lock +++ b/composer.lock @@ -516,16 +516,16 @@ }, { "name": "doctrine/doctrine-bundle", - "version": "2.11.2", + "version": "2.11.3", "source": { "type": "git", "url": "https://github.com/doctrine/DoctrineBundle.git", - "reference": "fb22c9320383caa2829c32dc3b84c1b5e0f1ceaf" + "reference": "492725310ae9a1b5b20d6ae09fb5ae6404616e68" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/DoctrineBundle/zipball/fb22c9320383caa2829c32dc3b84c1b5e0f1ceaf", - "reference": "fb22c9320383caa2829c32dc3b84c1b5e0f1ceaf", + "url": "https://api.github.com/repos/doctrine/DoctrineBundle/zipball/492725310ae9a1b5b20d6ae09fb5ae6404616e68", + "reference": "492725310ae9a1b5b20d6ae09fb5ae6404616e68", "shasum": "" }, "require": { @@ -615,7 +615,7 @@ ], "support": { "issues": "https://github.com/doctrine/DoctrineBundle/issues", - "source": "https://github.com/doctrine/DoctrineBundle/tree/2.11.2" + "source": "https://github.com/doctrine/DoctrineBundle/tree/2.11.3" }, "funding": [ { @@ -631,7 +631,7 @@ "type": "tidelift" } ], - "time": "2024-02-06T15:41:25+00:00" + "time": "2024-02-10T20:56:20+00:00" }, { "name": "doctrine/doctrine-migrations-bundle", @@ -1484,16 +1484,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.57", + "version": "1.10.58", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "1627b1d03446904aaa77593f370c5201d2ecc34e" + "reference": "a23518379ec4defd9e47cbf81019526861623ec2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/1627b1d03446904aaa77593f370c5201d2ecc34e", - "reference": "1627b1d03446904aaa77593f370c5201d2ecc34e", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/a23518379ec4defd9e47cbf81019526861623ec2", + "reference": "a23518379ec4defd9e47cbf81019526861623ec2", "shasum": "" }, "require": { @@ -1542,7 +1542,7 @@ "type": "tidelift" } ], - "time": "2024-01-24T11:51:34+00:00" + "time": "2024-02-12T20:02:57+00:00" }, { "name": "psr/cache", @@ -5219,16 +5219,16 @@ }, { "name": "symplify/easy-coding-standard", - "version": "12.1.10", + "version": "12.1.11", "source": { "type": "git", "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", - "reference": "67f643befd6997961aa6bd759b4529e94bb18b53" + "reference": "d8653e2f4ef154039841a7bfed4e91eb5deae1ab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/67f643befd6997961aa6bd759b4529e94bb18b53", - "reference": "67f643befd6997961aa6bd759b4529e94bb18b53", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/d8653e2f4ef154039841a7bfed4e91eb5deae1ab", + "reference": "d8653e2f4ef154039841a7bfed4e91eb5deae1ab", "shasum": "" }, "require": { @@ -5261,7 +5261,7 @@ ], "support": { "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", - "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.1.10" + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.1.11" }, "funding": [ { @@ -5273,7 +5273,7 @@ "type": "github" } ], - "time": "2024-02-05T10:58:24+00:00" + "time": "2024-02-13T11:35:41+00:00" }, { "name": "twig/twig", diff --git a/config/packages/twig.php b/config/packages/twig.php index e4963fd..f8c0a23 100644 --- a/config/packages/twig.php +++ b/config/packages/twig.php @@ -1,15 +1,13 @@ fileNamePattern('*.twig') + $twig->fileNamePattern('*.twig') ->global('username', service(WhoAreYou::class)); if ($_SERVER['APP_ENV'] === 'test') { diff --git a/config/services.php b/config/services.php index 41fbcd4..3bd2d36 100644 --- a/config/services.php +++ b/config/services.php @@ -1,7 +1,7 @@ services(); diff --git a/src/Controller/FoodOrderController.php b/src/Controller/FoodOrderController.php index 3b3432f..9c92f0e 100644 --- a/src/Controller/FoodOrderController.php +++ b/src/Controller/FoodOrderController.php @@ -11,7 +11,6 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; -use DateTimeImmutable; #[Route('/order')] class FoodOrderController extends AbstractController @@ -29,7 +28,8 @@ class FoodOrderController extends AbstractController 'food_order/show.html.twig', [ 'food_order' => $foodOrder, - 'menu_items' => $foodOrder->getVendor()->getMenuItems(), + 'menu_items' => $foodOrder->getVendor() + ->getMenuItems(), ], ); } @@ -62,17 +62,23 @@ class FoodOrderController extends AbstractController EntityManagerInterface $entityManager, Request $request, ): Response { - $orderItem = new OrderItem(); + $orderItem = new OrderItem; $orderItem->setFoodOrder($foodOrder); $orderItem->setMenuItem($menuItem); - - $form = $this->createForm(OrderItemType::class, $orderItem, ['menuItem' => $menuItem]); + $form = $this->createForm( + OrderItemType::class, + $orderItem, + [ + 'menuItem' => $menuItem, + ], + ); $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { $entityManager->persist($orderItem); $entityManager->flush(); return $this->redirectToRoute( - FoodOrderController::APP_FOOD_ORDER_SHOW, + self::APP_FOOD_ORDER_SHOW, [ 'id' => $foodOrder->getId(), ], @@ -80,13 +86,9 @@ class FoodOrderController extends AbstractController ); } - return $this->render( - 'food_order/orderitem.html.twig', - [ - 'form' => $form, - ], - ); - + return $this->render('food_order/orderitem.html.twig', [ + 'form' => $form, + ]); } #[Route( diff --git a/src/Controller/Start.php b/src/Controller/Start.php index 3469b3a..1344ea8 100644 --- a/src/Controller/Start.php +++ b/src/Controller/Start.php @@ -2,10 +2,10 @@ namespace App\Controller; +use App\Entity\FoodOrder; use App\Form\FoodOrderType; use App\Repository\FoodOrderRepository; use App\Service\WhoAreYou; -use App\Entity\FoodOrder; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -23,7 +23,7 @@ final class Start extends AbstractController Request $request, ): Response { $openOrders = $foodOrderRepository->findOpenOrders(); - $order = new FoodOrder(); + $order = new FoodOrder; $form = $this->createForm(FoodOrderType::class, $order); $form->handleRequest($request); diff --git a/src/Controller/VendorController.php b/src/Controller/VendorController.php index 7949226..869339f 100644 --- a/src/Controller/VendorController.php +++ b/src/Controller/VendorController.php @@ -2,9 +2,9 @@ namespace App\Controller; +use App\Entity\Vendor; use App\Form\VendorType; use App\Repository\VendorRepository; -use App\Entity\Vendor; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; diff --git a/src/DataFixtures/AppFixture.php b/src/DataFixtures/AppFixture.php index 0625204..f64b350 100644 --- a/src/DataFixtures/AppFixture.php +++ b/src/DataFixtures/AppFixture.php @@ -8,14 +8,22 @@ use App\Entity\MenuItemAlias; use App\Entity\Vendor; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Persistence\ObjectManager; +use Faker\Factory; use Faker\Generator; +use Override; + +use function random_int; +use function range; final class AppFixture extends Fixture { private Generator $faker; - public function load(ObjectManager $manager) + + #[Override] + public function load(ObjectManager $manager): void { - $this->faker = \Faker\Factory::create(); + $this->faker = Factory::create(); + foreach (range(0, 20) as $vendorCount) { $this->createVendorAndMenuItems($manager); } @@ -23,49 +31,33 @@ final class AppFixture extends Fixture $manager->flush(); } - /** - * @param MenuItem $menuItem - * @param ObjectManager $manager - * @return void - */ - public function addMenuItemAliases(MenuItem $menuItem, ObjectManager $manager): void - { - $menuItemAliasOne = new MenuItemAlias(); + public function addMenuItemAliases( + MenuItem $menuItem, + ObjectManager $manager, + ): void { + $menuItemAliasOne = new MenuItemAlias; $menuItemAliasOne->setName($this->faker->word); $menuItem->addMenuItemAlias($menuItemAliasOne); $manager->persist($menuItemAliasOne); - $menuItemAliasTwo = new MenuItemAlias(); + $menuItemAliasTwo = new MenuItemAlias; $menuItemAliasTwo->setName($this->faker->word); $menuItem->addMenuItemAlias($menuItemAliasTwo); $manager->persist($menuItemAliasTwo); } - /** - * @param MenuItem $menuItem - * @param ObjectManager $manager - * @return void - * @throws \Random\RandomException - */ public function addMenuItemExtras(MenuItem $menuItem, ObjectManager $manager): void { - - foreach(range(0, random_int(0, 5)) as $dispose) { - $itemExtra = new ItemExtra(); + foreach (range(0, random_int(0, 5)) as $dispose) { + $itemExtra = new ItemExtra; $itemExtra->setName($this->faker->word); $menuItem->addItemExtra($itemExtra); $manager->persist($itemExtra); } } - /** - * @param Vendor $vendor - * @param ObjectManager $manager - * @return void - * @throws \Random\RandomException - */ public function createMenuItem(Vendor $vendor, ObjectManager $manager): void { - $menuItem = new MenuItem(); + $menuItem = new MenuItem; $menuItem->setVendor($vendor); $menuItem->setPrice(random_int(500, 2000)); $manager->persist($menuItem); @@ -73,14 +65,9 @@ final class AppFixture extends Fixture $this->addMenuItemExtras($menuItem, $manager); } - /** - * @param ObjectManager $manager - * @return void - * @throws \Random\RandomException - */ public function createVendorAndMenuItems(ObjectManager $manager): void { - $vendor = new Vendor(); + $vendor = new Vendor; $vendor->setName($this->faker->name); $manager->persist($vendor); @@ -88,4 +75,4 @@ final class AppFixture extends Fixture $this->createMenuItem($vendor, $manager); } } -} \ No newline at end of file +} diff --git a/src/Entity/FoodOrder.php b/src/Entity/FoodOrder.php index ae6e5cf..b7803cd 100644 --- a/src/Entity/FoodOrder.php +++ b/src/Entity/FoodOrder.php @@ -1,16 +1,15 @@ -id; } - public function getClosedAt(): \DateTimeImmutable|null + public function getClosedAt(): DateTimeImmutable|null { return $this->closedAt; } - public function setClosedAt(\DateTimeImmutable $closedAt = new DateTimeImmutable()): static - { + public function setClosedAt( + DateTimeImmutable $closedAt = new DateTimeImmutable, + ): static { $this->closedAt = $closedAt; return $this; } @@ -76,12 +75,12 @@ class FoodOrder return $this; } - public function getStartedAt(): \DateTimeImmutable + public function getStartedAt(): DateTimeImmutable { return $this->startedAt; } - public function setStartedAt(\DateTimeImmutable $startedAt): static + public function setStartedAt(DateTimeImmutable $startedAt): static { $this->startedAt = $startedAt; return $this; @@ -118,23 +117,24 @@ class FoodOrder return $this; } - public function getVendor(): ?Vendor + public function getVendor(): Vendor|null { return $this->vendor; } - public function setVendor(?Vendor $vendor): static + public function setVendor(Vendor|null $vendor): static { $this->vendor = $vendor; - return $this; } public function groupedOrderItems(): array { return $this->orderItems->reduce( - function (array $carry, OrderItem $item): array { - $menuItemStringId = (string)$item->getMenuItem()->getId(); + static function (array $carry, OrderItem $item): array { + $menuItemStringId = (string) $item->getMenuItem() + ->getId(); + if (isset($carry[$menuItemStringId])) { $carry[$menuItemStringId]['amount']++; } else { @@ -143,11 +143,10 @@ class FoodOrder 'amount' => 1, ]; } + return $carry; }, - [] + [], ); } - - } diff --git a/src/Entity/ItemExtra.php b/src/Entity/ItemExtra.php index 4aec202..2c770fd 100644 --- a/src/Entity/ItemExtra.php +++ b/src/Entity/ItemExtra.php @@ -1,4 +1,4 @@ -id = new Ulid; } @@ -34,7 +34,7 @@ class ItemExtra return $this->id; } - public function getName(): ?string + public function getName(): string|null { return $this->name; } @@ -42,19 +42,17 @@ class ItemExtra public function setName(string $name): static { $this->name = $name; - return $this; } - public function getMenuItem(): ?MenuItem + public function getMenuItem(): MenuItem|null { return $this->menuItem; } - public function setMenuItem(?MenuItem $menuItem): static + public function setMenuItem(MenuItem|null $menuItem): static { $this->menuItem = $menuItem; - return $this; } } diff --git a/src/Entity/MenuItem.php b/src/Entity/MenuItem.php index 9d301b3..962f487 100644 --- a/src/Entity/MenuItem.php +++ b/src/Entity/MenuItem.php @@ -33,14 +33,18 @@ class MenuItem )] private Collection $menuItemAliases; - #[ORM\OneToMany(mappedBy: 'menuItem', targetEntity: ItemExtra::class, orphanRemoval: true)] + #[ORM\OneToMany( + mappedBy: 'menuItem', + targetEntity: ItemExtra::class, + orphanRemoval: true, + )] private Collection $itemExtras; public function __construct() { $this->id = new Ulid; $this->menuItemAliases = new ArrayCollection; - $this->itemExtras = new ArrayCollection(); + $this->itemExtras = new ArrayCollection; } public function getId(): Ulid @@ -53,7 +57,7 @@ class MenuItem return $this->vendor; } - public function setVendor(Vendor$vendor): static + public function setVendor(Vendor $vendor): static { $this->vendor = $vendor; return $this; @@ -111,7 +115,7 @@ class MenuItem public function addItemExtra(ItemExtra $itemExtra): static { - if (!$this->itemExtras->contains($itemExtra)) { + if (! $this->itemExtras->contains($itemExtra)) { $this->itemExtras->add($itemExtra); $itemExtra->setMenuItem($this); } @@ -121,11 +125,12 @@ class MenuItem public function removeItemExtra(ItemExtra $itemExtra): static { - if ($this->itemExtras->removeElement($itemExtra)) { - // set the owning side to null (unless already changed) - if ($itemExtra->getMenuItem() === $this) { - $itemExtra->setMenuItem(null); - } + // set the owning side to null (unless already changed) + if ( + $this->itemExtras->removeElement($itemExtra) + && $itemExtra->getMenuItem() === $this + ) { + $itemExtra->setMenuItem(null); } return $this; diff --git a/src/Entity/MenuItemAlias.php b/src/Entity/MenuItemAlias.php index e4d9ebc..2c0297d 100644 --- a/src/Entity/MenuItemAlias.php +++ b/src/Entity/MenuItemAlias.php @@ -1,5 +1,4 @@ -id = new Ulid; - $this->extras = new ArrayCollection(); + $this->extras = new ArrayCollection; } public function getId(): Ulid @@ -52,15 +52,14 @@ class OrderItem return $this; } - public function getMenuItem(): ?MenuItem + public function getMenuItem(): MenuItem|null { return $this->menuItem; } - public function setMenuItem(?MenuItem $menuItem): static + public function setMenuItem(MenuItem|null $menuItem): static { $this->menuItem = $menuItem; - return $this; } @@ -74,7 +73,7 @@ class OrderItem public function addExtra(ItemExtra $extra): static { - if (!$this->extras->contains($extra)) { + if (! $this->extras->contains($extra)) { $this->extras->add($extra); } @@ -84,8 +83,6 @@ class OrderItem public function removeExtra(ItemExtra $extra): static { $this->extras->removeElement($extra); - return $this; } - } diff --git a/src/Entity/Vendor.php b/src/Entity/Vendor.php index 2dc18b4..1227a45 100644 --- a/src/Entity/Vendor.php +++ b/src/Entity/Vendor.php @@ -1,5 +1,4 @@ -id = new Ulid; diff --git a/src/Form/FoodOrderType.php b/src/Form/FoodOrderType.php index 0f54812..b507309 100644 --- a/src/Form/FoodOrderType.php +++ b/src/Form/FoodOrderType.php @@ -2,9 +2,9 @@ namespace App\Form; -use App\Service\WhoAreYou; use App\Entity\FoodOrder; use App\Entity\Vendor; +use App\Service\WhoAreYou; use Override; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; diff --git a/src/Form/OrderItemType.php b/src/Form/OrderItemType.php index e080dfd..af106c7 100644 --- a/src/Form/OrderItemType.php +++ b/src/Form/OrderItemType.php @@ -1,42 +1,44 @@ -add('extras', EntityType::class, [ + $builder->add( + 'extras', + EntityType::class, + [ 'class' => ItemExtra::class, 'choices' => $options['menuItem']->getItemExtras(), 'choice_label' => 'name', // Change this for the field you want to display 'multiple' => true, - 'expanded' => true - ]); + 'expanded' => true, + ], + ); } - public function configureOptions(OptionsResolver $resolver) + #[Override] + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'data_class' => OrderItem::class, ]); - $resolver->setRequired('menuItem'); $resolver->setAllowedTypes('menuItem', MenuItem::class); } diff --git a/src/Repository/FoodOrderRepository.php b/src/Repository/FoodOrderRepository.php index 72e2547..c272e49 100644 --- a/src/Repository/FoodOrderRepository.php +++ b/src/Repository/FoodOrderRepository.php @@ -1,5 +1,4 @@ -createQueryBuilder('f') + return $this + ->createQueryBuilder('f') ->andWhere('f.closedAt IS NULL') ->getQuery() ->getResult(); diff --git a/src/Repository/ItemExtraRepository.php b/src/Repository/ItemExtraRepository.php index 2dd61d7..0a63c73 100644 --- a/src/Repository/ItemExtraRepository.php +++ b/src/Repository/ItemExtraRepository.php @@ -1,4 +1,4 @@ -createQueryBuilder('i') -// ->andWhere('i.exampleField = :val') -// ->setParameter('val', $value) -// ->orderBy('i.id', 'ASC') -// ->setMaxResults(10) -// ->getQuery() -// ->getResult() -// ; -// } - -// public function findOneBySomeField($value): ?ItemExtra -// { -// return $this->createQueryBuilder('i') -// ->andWhere('i.exampleField = :val') -// ->setParameter('val', $value) -// ->getQuery() -// ->getOneOrNullResult() -// ; -// } + // /** + // * @return ItemExtra[] Returns an array of ItemExtra objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('i') + // ->andWhere('i.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('i.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + // public function findOneBySomeField($value): ?ItemExtra + // { + // return $this->createQueryBuilder('i') + // ->andWhere('i.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } } diff --git a/src/Repository/MenuItemRepository.php b/src/Repository/MenuItemRepository.php index 43bdddd..06ca4c5 100644 --- a/src/Repository/MenuItemRepository.php +++ b/src/Repository/MenuItemRepository.php @@ -1,5 +1,4 @@ -