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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Security\Voter\Bid;
  3. use App\Entity\DealBid;
  4. use App\Entity\User;
  5. use App\Security\Voter\AbstractProposalBidVoter;
  6. use Symfony\Component\Validator\Exception\UnexpectedTypeException;
  7. class HasNoContributionVoter extends AbstractProposalBidVoter
  8. {
  9.     public const ATTRIBUTE 'HAS_NO_CONTRIBUTION';
  10.     /**
  11.      * @return array<int, string>
  12.      */
  13.     protected function getSupportedAttributes(): array
  14.     {
  15.         return [self::ATTRIBUTE];
  16.     }
  17.     /**
  18.      * @param DealBid|object $object
  19.      */
  20.     protected function isGrantedForUser($objectUser $user): bool
  21.     {
  22.         if (!$object instanceof DealBid) {
  23.             throw new UnexpectedTypeException($objectDealBid::class);
  24.         }
  25.         return false === $object->getDeal()->getUserBids($user)->exists(static function (int $indexDealBid $bid) use ($object): bool {
  26.             return null !== $bid->getId() && $bid->isStillAccessible() && $object->getDealPerk() === $bid->getDealPerk();
  27.         });
  28.     }
  29.     protected function generateCacheKey(object $object): string
  30.     {
  31.         if (!$object instanceof DealBid) {
  32.             throw new UnexpectedTypeException($objectDealBid::class);
  33.         }
  34.         $key parent::generateCacheKey($object);
  35.         if (null !== $object->getDealPerk() && null !== $object->getDealPerk()->getId()) {
  36.             $key .= '-perk' $object->getDealPerk()->getId();
  37.         }
  38.         return $key;
  39.     }
  40. }