<?php declare(strict_types=1);
namespace App\Security\Voter\Bid;
use App\Contract\Payments\PurchaseOnceInterface;
use App\Entity\User;
use App\Security\Voter\AbstractPurchaseOnceBidVoter;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class HasNotPurchasedVoter extends AbstractPurchaseOnceBidVoter
{
public const ATTRIBUTE = 'HAS_NOT_PURCHASED';
/**
* @return array<int, string>
*/
protected function getSupportedAttributes(): array
{
return [self::ATTRIBUTE];
}
/**
* @param PurchaseOnceInterface|object $object
*/
protected function isGrantedForUser($object, User $user): bool
{
if (!$object instanceof PurchaseOnceInterface) {
throw new UnexpectedTypeException($object, PurchaseOnceInterface::class);
}
return false === $object->getPurchased()->getUserBids($user)->exists(static function (int $index, PurchaseOnceInterface $bid): bool {
return null !== $bid->getId() && $bid->isStillAccessible();
});
}
}