Skip to content

Use class constant in validators #17420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(ManagerRegistry $registry)
public function validate($entity, Constraint $constraint)
{
if (!$constraint instanceof UniqueEntity) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UniqueEntity');
throw new UnexpectedTypeException($constraint, UniqueEntity::class);
}

if (!is_array($constraint->fields) && !is_string($constraint->fields)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FormValidator extends ConstraintValidator
public function validate($form, Constraint $constraint)
{
if (!$constraint instanceof Form) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Form');
throw new UnexpectedTypeException($constraint, Form::class);
}

if (!$form instanceof FormInterface) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(TokenStorageInterface $tokenStorage, EncoderFactoryI
public function validate($password, Constraint $constraint)
{
if (!$constraint instanceof UserPassword) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UserPassword');
throw new UnexpectedTypeException($constraint, UserPassword::class);
}

$user = $this->tokenStorage->getToken()->getUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class AbstractComparisonValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof AbstractComparison) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\AbstractComparison');
throw new UnexpectedTypeException($constraint, AbstractComparison::class);
}

if (null === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AllValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof All) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\All');
throw new UnexpectedTypeException($constraint, All::class);
}

if (null === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BlankValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Blank) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Blank');
throw new UnexpectedTypeException($constraint, Blank::class);
}

if ('' !== $value && null !== $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CallbackValidator extends ConstraintValidator
public function validate($object, Constraint $constraint)
{
if (!$constraint instanceof Callback) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Callback');
throw new UnexpectedTypeException($constraint, Callback::class);
}

$method = $constraint->callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CardSchemeValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof CardScheme) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\CardScheme');
throw new UnexpectedTypeException($constraint, CardScheme::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ChoiceValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Choice) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Choice');
throw new UnexpectedTypeException($constraint, Choice::class);
}

if (!is_array($constraint->choices) && !$constraint->callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CollectionValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Collection) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Collection');
throw new UnexpectedTypeException($constraint, Collection::class);
}

if (null === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CountryValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Country) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Country');
throw new UnexpectedTypeException($constraint, Country::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CurrencyValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Currency) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Currency');
throw new UnexpectedTypeException($constraint, Currency::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DateTimeValidator extends DateValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof DateTime) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\DateTime');
throw new UnexpectedTypeException($constraint, DateTime::class);
}

if (null === $value || '' === $value || $value instanceof \DateTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function checkDate($year, $month, $day)
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Date) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Date');
throw new UnexpectedTypeException($constraint, Date::class);
}

if (null === $value || '' === $value || $value instanceof \DateTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct($strict = false)
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Email) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Email');
throw new UnexpectedTypeException($constraint, Email::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(PropertyAccessorInterface $propertyAccessor = null,
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Expression) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Expression');
throw new UnexpectedTypeException($constraint, Expression::class);
}

$variables = array();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FileValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof File) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\File');
throw new UnexpectedTypeException($constraint, File::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class IbanValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Iban) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Iban');
throw new UnexpectedTypeException($constraint, Iban::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ImageValidator extends FileValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Image) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Image');
throw new UnexpectedTypeException($constraint, Image::class);
}

$violations = count($this->context->getViolations());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class IpValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Ip) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Ip');
throw new UnexpectedTypeException($constraint, Ip::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IsFalseValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof IsFalse) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsFalse');
throw new UnexpectedTypeException($constraint, IsFalse::class);
}

if (null === $value || false === $value || 0 === $value || '0' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IsNullValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof IsNull) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsNull');
throw new UnexpectedTypeException($constraint, IsNull::class);
}

if (null !== $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IsTrueValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof IsTrue) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsTrue');
throw new UnexpectedTypeException($constraint, IsTrue::class);
}

if (null === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class IsbnValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Isbn) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Isbn');
throw new UnexpectedTypeException($constraint, Isbn::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class IssnValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Issn) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Issn');
throw new UnexpectedTypeException($constraint, Issn::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LanguageValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Language) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Language');
throw new UnexpectedTypeException($constraint, Language::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LengthValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Length) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Length');
throw new UnexpectedTypeException($constraint, Length::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LocaleValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Locale) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Locale');
throw new UnexpectedTypeException($constraint, Locale::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LuhnValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Luhn) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Luhn');
throw new UnexpectedTypeException($constraint, Luhn::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class NotBlankValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof NotBlank) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\NotBlank');
throw new UnexpectedTypeException($constraint, NotBlank::class);
}

if (false === $value || (empty($value) && '0' != $value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class NotNullValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof NotNull) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\NotNull');
throw new UnexpectedTypeException($constraint, NotNull::class);
}

if (null === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RangeValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Range) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Range');
throw new UnexpectedTypeException($constraint, Range::class);
}

if (null === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RegexValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Regex) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Regex');
throw new UnexpectedTypeException($constraint, Regex::class);
}

if (null === $value || '' === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function checkTime($hour, $minute, $second)
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Time) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Time');
throw new UnexpectedTypeException($constraint, Time::class);
}

if (null === $value || '' === $value || $value instanceof \DateTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TypeValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Type) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Type');
throw new UnexpectedTypeException($constraint, Type::class);
}

if (null === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class UrlValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Url) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Url');
throw new UnexpectedTypeException($constraint, Url::class);
}

if (null === $value) {
Expand Down