src/App/Security/Voter/Bid/HasNotPurchasedVoter.php line 10

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Security\Voter\Bid;
  3. use App\Contract\Payments\PurchaseOnceInterface;
  4. use App\Entity\User;
  5. use App\Security\Voter\AbstractPurchaseOnceBidVoter;
  6. use Symfony\Component\Validator\Exception\UnexpectedTypeException;
  7. class HasNotPurchasedVoter extends AbstractPurchaseOnceBidVoter
  8. {
  9.     public const ATTRIBUTE 'HAS_NOT_PURCHASED';
  10.     /**
  11.      * @return array<int, string>
  12.      */
  13.     protected function getSupportedAttributes(): array
  14.     {
  15.         return [self::ATTRIBUTE];
  16.     }
  17.     /**
  18.      * @param PurchaseOnceInterface|object $object
  19.      */
  20.     protected function isGrantedForUser($objectUser $user): bool
  21.     {
  22.         if (!$object instanceof PurchaseOnceInterface) {
  23.             throw new UnexpectedTypeException($objectPurchaseOnceInterface::class);
  24.         }
  25.         return false === $object->getPurchased()->getUserBids($user)->exists(static function (int $indexPurchaseOnceInterface $bid): bool {
  26.             return null !== $bid->getId() && $bid->isStillAccessible();
  27.         });
  28.     }
  29. }