/**
  * Transforms an object (menu item) to a string (id).
  *
  * @param MenuItemInterface|string $menuItem
  *
  * @return string|null
  *
  * @throws TransformationFailedException if object (menu item) is of wrong type
  */
 public function transform($menuItem)
 {
     if (null === $menuItem) {
         return;
     }
     if (!$menuItem instanceof MenuItemInterface) {
         throw new UnexpectedTypeException($menuItem, MenuItemInterface::class);
     }
     return $menuItem->getId();
 }
 public function it_throws_exception_if_item_after_moved_item_should_be_placed_does_not_exist(MenuItemInterface $sourceItem, MenuItemInterface $parentItem, MenuItemInterface $afterItem, MenuItemRepositoryInterface $menuItemRepository, ObjectManager $objectManager)
 {
     $sourceItem->getPosition()->willReturn(1);
     $menuItemRepository->findChildByParentAndPosition($parentItem, 2)->willReturn(null);
     $menuItemRepository->persistAsNextSiblingOf($sourceItem, $afterItem)->shouldNotBeCalled();
     $sourceItem->getPosition()->shouldBeCalled();
     $sourceItem->setPosition(2)->shouldNotBeCalled();
     $objectManager->flush()->shouldNotBeCalled();
     $this->shouldThrow(HttpException::class)->duringMove($sourceItem, $parentItem, 2);
 }
 /**
  * {@inheritdoc}
  */
 public function findChildByParentAndPosition(MenuItemInterface $parent, int $position)
 {
     return $this->createQueryBuilder('m')->where('m.parent = :id')->andWhere('m.position = :position')->setParameters(['id' => $parent->getId(), 'position' => $position])->getQuery()->getOneOrNullResult();
 }
 private function ensurePositionIsValid(MenuItemInterface $menuItem, int $position)
 {
     if ($menuItem->getPosition() === $position) {
         throw new ConflictHttpException(sprintf('Menu item %d is already placed at position %d.', $menuItem->getId(), $position));
     }
 }