src/App/Security/Voter/Bid/HasCreditsVoter.php line 12

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