You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
939 B
33 lines
939 B
<?php
|
|
namespace App\Validator;
|
|
|
|
use App\Entity\Character;
|
|
use Symfony\Component\Validator\Constraint;
|
|
use Symfony\Component\Validator\ConstraintValidator;
|
|
use Symfony\Component\Validator\Exception\UnexpectedValueException;
|
|
|
|
class CharacterStatsValidator extends ConstraintValidator
|
|
{
|
|
|
|
public function __construct()
|
|
{}
|
|
|
|
public function validate(mixed $character, Constraint $constraint): void
|
|
{
|
|
if (! $character instanceof Character) {
|
|
throw new UnexpectedValueException($character, Character::class);
|
|
}
|
|
|
|
if (! $constraint instanceof CharacterStats) {
|
|
throw new UnexpectedValueException($constraint, CharacterStats::class);
|
|
}
|
|
|
|
if ($character->getFreeSkillPoints() < 0) {
|
|
$this->context->buildViolation($constraint->noMoreSkillPointsMessage)
|
|
->atPath('character.freeSkillPoints')
|
|
->addViolation();
|
|
}
|
|
}
|
|
}
|
|
|