Skip to content

Commit 8baf183

Browse files
fre5hnicolas-grekas
authored andcommitted
Use ::class constants instead of __NAMESPACE__ when possible
1 parent f825293 commit 8baf183

38 files changed

+44
-44
lines changed

Constraints/AbstractComparisonValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(PropertyAccessorInterface $propertyAccessor = null)
4040
public function validate($value, Constraint $constraint)
4141
{
4242
if (!$constraint instanceof AbstractComparison) {
43-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\AbstractComparison');
43+
throw new UnexpectedTypeException($constraint, AbstractComparison::class);
4444
}
4545

4646
if (null === $value) {

Constraints/AllValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AllValidator extends ConstraintValidator
2626
public function validate($value, Constraint $constraint)
2727
{
2828
if (!$constraint instanceof All) {
29-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\All');
29+
throw new UnexpectedTypeException($constraint, All::class);
3030
}
3131

3232
if (null === $value) {

Constraints/BicValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class BicValidator extends ConstraintValidator
2828
public function validate($value, Constraint $constraint)
2929
{
3030
if (!$constraint instanceof Bic) {
31-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Bic');
31+
throw new UnexpectedTypeException($constraint, Bic::class);
3232
}
3333

3434
if (null === $value || '' === $value) {

Constraints/BlankValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class BlankValidator extends ConstraintValidator
2626
public function validate($value, Constraint $constraint)
2727
{
2828
if (!$constraint instanceof Blank) {
29-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Blank');
29+
throw new UnexpectedTypeException($constraint, Blank::class);
3030
}
3131

3232
if ('' !== $value && null !== $value) {

Constraints/CallbackValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CallbackValidator extends ConstraintValidator
2929
public function validate($object, Constraint $constraint)
3030
{
3131
if (!$constraint instanceof Callback) {
32-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Callback');
32+
throw new UnexpectedTypeException($constraint, Callback::class);
3333
}
3434

3535
$method = $constraint->callback;

Constraints/CardSchemeValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class CardSchemeValidator extends ConstraintValidator
9191
public function validate($value, Constraint $constraint)
9292
{
9393
if (!$constraint instanceof CardScheme) {
94-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\CardScheme');
94+
throw new UnexpectedTypeException($constraint, CardScheme::class);
9595
}
9696

9797
if (null === $value || '' === $value) {

Constraints/ChoiceValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ChoiceValidator extends ConstraintValidator
3131
public function validate($value, Constraint $constraint)
3232
{
3333
if (!$constraint instanceof Choice) {
34-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Choice');
34+
throw new UnexpectedTypeException($constraint, Choice::class);
3535
}
3636

3737
if (!\is_array($constraint->choices) && !$constraint->callback) {

Constraints/CollectionValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CollectionValidator extends ConstraintValidator
2626
public function validate($value, Constraint $constraint)
2727
{
2828
if (!$constraint instanceof Collection) {
29-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Collection');
29+
throw new UnexpectedTypeException($constraint, Collection::class);
3030
}
3131

3232
if (null === $value) {

Constraints/CountValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CountValidator extends ConstraintValidator
2626
public function validate($value, Constraint $constraint)
2727
{
2828
if (!$constraint instanceof Count) {
29-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Count');
29+
throw new UnexpectedTypeException($constraint, Count::class);
3030
}
3131

3232
if (null === $value) {

Constraints/CountryValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CountryValidator extends ConstraintValidator
2929
public function validate($value, Constraint $constraint)
3030
{
3131
if (!$constraint instanceof Country) {
32-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Country');
32+
throw new UnexpectedTypeException($constraint, Country::class);
3333
}
3434

3535
if (null === $value || '' === $value) {

Constraints/CurrencyValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CurrencyValidator extends ConstraintValidator
3030
public function validate($value, Constraint $constraint)
3131
{
3232
if (!$constraint instanceof Currency) {
33-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Currency');
33+
throw new UnexpectedTypeException($constraint, Currency::class);
3434
}
3535

3636
if (null === $value || '' === $value) {

Constraints/DateTimeValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class DateTimeValidator extends DateValidator
3131
public function validate($value, Constraint $constraint)
3232
{
3333
if (!$constraint instanceof DateTime) {
34-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\DateTime');
34+
throw new UnexpectedTypeException($constraint, DateTime::class);
3535
}
3636

3737
if (null === $value || '' === $value || $value instanceof \DateTimeInterface) {

Constraints/DateValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static function checkDate($year, $month, $day)
4444
public function validate($value, Constraint $constraint)
4545
{
4646
if (!$constraint instanceof Date) {
47-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Date');
47+
throw new UnexpectedTypeException($constraint, Date::class);
4848
}
4949

5050
if (null === $value || '' === $value || $value instanceof \DateTimeInterface) {

Constraints/EmailValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct($strict = false)
3939
public function validate($value, Constraint $constraint)
4040
{
4141
if (!$constraint instanceof Email) {
42-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Email');
42+
throw new UnexpectedTypeException($constraint, Email::class);
4343
}
4444

4545
if (null === $value || '' === $value) {

Constraints/ExpressionValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct($propertyAccessor = null, ExpressionLanguage $expres
3636
public function validate($value, Constraint $constraint)
3737
{
3838
if (!$constraint instanceof Expression) {
39-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Expression');
39+
throw new UnexpectedTypeException($constraint, Expression::class);
4040
}
4141

4242
$variables = [];

Constraints/FileValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class FileValidator extends ConstraintValidator
4141
public function validate($value, Constraint $constraint)
4242
{
4343
if (!$constraint instanceof File) {
44-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\File');
44+
throw new UnexpectedTypeException($constraint, File::class);
4545
}
4646

4747
if (null === $value || '' === $value) {

Constraints/IbanValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class IbanValidator extends ConstraintValidator
142142
public function validate($value, Constraint $constraint)
143143
{
144144
if (!$constraint instanceof Iban) {
145-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Iban');
145+
throw new UnexpectedTypeException($constraint, Iban::class);
146146
}
147147

148148
if (null === $value || '' === $value) {

Constraints/ImageValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ImageValidator extends FileValidator
3131
public function validate($value, Constraint $constraint)
3232
{
3333
if (!$constraint instanceof Image) {
34-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Image');
34+
throw new UnexpectedTypeException($constraint, Image::class);
3535
}
3636

3737
$violations = \count($this->context->getViolations());

Constraints/IpValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class IpValidator extends ConstraintValidator
2929
public function validate($value, Constraint $constraint)
3030
{
3131
if (!$constraint instanceof Ip) {
32-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Ip');
32+
throw new UnexpectedTypeException($constraint, Ip::class);
3333
}
3434

3535
if (null === $value || '' === $value) {

Constraints/IsFalseValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class IsFalseValidator extends ConstraintValidator
2626
public function validate($value, Constraint $constraint)
2727
{
2828
if (!$constraint instanceof IsFalse) {
29-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsFalse');
29+
throw new UnexpectedTypeException($constraint, IsFalse::class);
3030
}
3131

3232
if (null === $value || false === $value || 0 === $value || '0' === $value) {

Constraints/IsNullValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class IsNullValidator extends ConstraintValidator
2626
public function validate($value, Constraint $constraint)
2727
{
2828
if (!$constraint instanceof IsNull) {
29-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsNull');
29+
throw new UnexpectedTypeException($constraint, IsNull::class);
3030
}
3131

3232
if (null !== $value) {

Constraints/IsTrueValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class IsTrueValidator extends ConstraintValidator
2626
public function validate($value, Constraint $constraint)
2727
{
2828
if (!$constraint instanceof IsTrue) {
29-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsTrue');
29+
throw new UnexpectedTypeException($constraint, IsTrue::class);
3030
}
3131

3232
if (null === $value) {

Constraints/IsbnValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class IsbnValidator extends ConstraintValidator
3232
public function validate($value, Constraint $constraint)
3333
{
3434
if (!$constraint instanceof Isbn) {
35-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Isbn');
35+
throw new UnexpectedTypeException($constraint, Isbn::class);
3636
}
3737

3838
if (null === $value || '' === $value) {

Constraints/IssnValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class IssnValidator extends ConstraintValidator
3131
public function validate($value, Constraint $constraint)
3232
{
3333
if (!$constraint instanceof Issn) {
34-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Issn');
34+
throw new UnexpectedTypeException($constraint, Issn::class);
3535
}
3636

3737
if (null === $value || '' === $value) {

Constraints/LanguageValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LanguageValidator extends ConstraintValidator
2929
public function validate($value, Constraint $constraint)
3030
{
3131
if (!$constraint instanceof Language) {
32-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Language');
32+
throw new UnexpectedTypeException($constraint, Language::class);
3333
}
3434

3535
if (null === $value || '' === $value) {

Constraints/LengthValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class LengthValidator extends ConstraintValidator
2626
public function validate($value, Constraint $constraint)
2727
{
2828
if (!$constraint instanceof Length) {
29-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Length');
29+
throw new UnexpectedTypeException($constraint, Length::class);
3030
}
3131

3232
if (null === $value || '' === $value) {

Constraints/LocaleValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LocaleValidator extends ConstraintValidator
2929
public function validate($value, Constraint $constraint)
3030
{
3131
if (!$constraint instanceof Locale) {
32-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Locale');
32+
throw new UnexpectedTypeException($constraint, Locale::class);
3333
}
3434

3535
if (null === $value || '' === $value) {

Constraints/LuhnValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class LuhnValidator extends ConstraintValidator
3939
public function validate($value, Constraint $constraint)
4040
{
4141
if (!$constraint instanceof Luhn) {
42-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Luhn');
42+
throw new UnexpectedTypeException($constraint, Luhn::class);
4343
}
4444

4545
if (null === $value || '' === $value) {

Constraints/NotBlankValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class NotBlankValidator extends ConstraintValidator
2626
public function validate($value, Constraint $constraint)
2727
{
2828
if (!$constraint instanceof NotBlank) {
29-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\NotBlank');
29+
throw new UnexpectedTypeException($constraint, NotBlank::class);
3030
}
3131

3232
if (false === $value || (empty($value) && '0' != $value)) {

Constraints/NotNullValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class NotNullValidator extends ConstraintValidator
2626
public function validate($value, Constraint $constraint)
2727
{
2828
if (!$constraint instanceof NotNull) {
29-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\NotNull');
29+
throw new UnexpectedTypeException($constraint, NotNull::class);
3030
}
3131

3232
if (null === $value) {

Constraints/RangeValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class RangeValidator extends ConstraintValidator
2727
public function validate($value, Constraint $constraint)
2828
{
2929
if (!$constraint instanceof Range) {
30-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Range');
30+
throw new UnexpectedTypeException($constraint, Range::class);
3131
}
3232

3333
if (null === $value) {

Constraints/RegexValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class RegexValidator extends ConstraintValidator
2929
public function validate($value, Constraint $constraint)
3030
{
3131
if (!$constraint instanceof Regex) {
32-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Regex');
32+
throw new UnexpectedTypeException($constraint, Regex::class);
3333
}
3434

3535
if (null === $value || '' === $value) {

Constraints/TimeValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static function checkTime($hour, $minute, $second)
4444
public function validate($value, Constraint $constraint)
4545
{
4646
if (!$constraint instanceof Time) {
47-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Time');
47+
throw new UnexpectedTypeException($constraint, Time::class);
4848
}
4949

5050
if (null === $value || '' === $value || $value instanceof \DateTimeInterface) {

Constraints/TypeValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TypeValidator extends ConstraintValidator
2626
public function validate($value, Constraint $constraint)
2727
{
2828
if (!$constraint instanceof Type) {
29-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Type');
29+
throw new UnexpectedTypeException($constraint, Type::class);
3030
}
3131

3232
if (null === $value) {

Constraints/UrlValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class UrlValidator extends ConstraintValidator
4545
public function validate($value, Constraint $constraint)
4646
{
4747
if (!$constraint instanceof Url) {
48-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Url');
48+
throw new UnexpectedTypeException($constraint, Url::class);
4949
}
5050

5151
if (null === $value || '' === $value) {

Constraints/UuidValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class UuidValidator extends ConstraintValidator
6767
public function validate($value, Constraint $constraint)
6868
{
6969
if (!$constraint instanceof Uuid) {
70-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Uuid');
70+
throw new UnexpectedTypeException($constraint, Uuid::class);
7171
}
7272

7373
if (null === $value || '' === $value) {

Constraints/ValidValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ValidValidator extends ConstraintValidator
2323
public function validate($value, Constraint $constraint)
2424
{
2525
if (!$constraint instanceof Valid) {
26-
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Valid');
26+
throw new UnexpectedTypeException($constraint, Valid::class);
2727
}
2828

2929
if (null === $value) {

Tests/Mapping/Loader/StaticMethodLoaderTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function tearDown()
3333
public function testLoadClassMetadataReturnsTrueIfSuccessful()
3434
{
3535
$loader = new StaticMethodLoader('loadMetadata');
36-
$metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderEntity');
36+
$metadata = new ClassMetadata(StaticLoaderEntity::class);
3737

3838
$this->assertTrue($loader->loadClassMetadata($metadata));
3939
}
@@ -49,7 +49,7 @@ public function testLoadClassMetadataReturnsFalseIfNotSuccessful()
4949
public function testLoadClassMetadata()
5050
{
5151
$loader = new StaticMethodLoader('loadMetadata');
52-
$metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderEntity');
52+
$metadata = new ClassMetadata(StaticLoaderEntity::class);
5353

5454
$loader->loadClassMetadata($metadata);
5555

@@ -59,20 +59,20 @@ public function testLoadClassMetadata()
5959
public function testLoadClassMetadataDoesNotRepeatLoadWithParentClasses()
6060
{
6161
$loader = new StaticMethodLoader('loadMetadata');
62-
$metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderDocument');
62+
$metadata = new ClassMetadata(StaticLoaderDocument::class);
6363
$loader->loadClassMetadata($metadata);
6464
$this->assertCount(0, $metadata->getConstraints());
6565

6666
$loader = new StaticMethodLoader('loadMetadata');
67-
$metadata = new ClassMetadata(__NAMESPACE__.'\BaseStaticLoaderDocument');
67+
$metadata = new ClassMetadata(BaseStaticLoaderDocument::class);
6868
$loader->loadClassMetadata($metadata);
6969
$this->assertCount(1, $metadata->getConstraints());
7070
}
7171

7272
public function testLoadClassMetadataIgnoresInterfaces()
7373
{
7474
$loader = new StaticMethodLoader('loadMetadata');
75-
$metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderInterface');
75+
$metadata = new ClassMetadata(StaticLoaderInterface::class);
7676

7777
$loader->loadClassMetadata($metadata);
7878

@@ -82,7 +82,7 @@ public function testLoadClassMetadataIgnoresInterfaces()
8282
public function testLoadClassMetadataInAbstractClasses()
8383
{
8484
$loader = new StaticMethodLoader('loadMetadata');
85-
$metadata = new ClassMetadata(__NAMESPACE__.'\AbstractStaticLoader');
85+
$metadata = new ClassMetadata(AbstractStaticLoader::class);
8686

8787
$loader->loadClassMetadata($metadata);
8888

@@ -95,7 +95,7 @@ public function testLoadClassMetadataIgnoresAbstractMethods()
9595
// strict standards error
9696
error_reporting(0);
9797

98-
$metadata = new ClassMetadata(__NAMESPACE__.'\AbstractStaticMethodLoader');
98+
$metadata = new ClassMetadata(AbstractStaticMethodLoader::class);
9999

100100
$loader = new StaticMethodLoader('loadMetadata');
101101
$loader->loadClassMetadata($metadata);

0 commit comments

Comments
 (0)