<?php declare(strict_types=1);
namespace App\Security\Voter\Bid;
use App\Contract\Payments\PurchaseInterface;
use App\Entity\ProposalBid;
use App\Entity\ShopVideoBid;
use App\Entity\User;
use App\Security\Voter\AbstractAllBidsVoter;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class HasCreditsVoter extends AbstractAllBidsVoter
{
public const ATTRIBUTE = 'HAS_CREDITS';
/**
* @return array<int, string>
*/
protected function getSupportedAttributes(): array
{
return [self::ATTRIBUTE];
}
/**
* @param ProposalBid|ShopVideoBid|object $object
*/
protected function isGrantedForUser($object, User $user): bool
{
if (!$object instanceof PurchaseInterface) {
throw new UnexpectedTypeException($object, PurchaseInterface::class);
}
return $object->getCredits() <= $user->getCredits();
}
}