Skip to content

Commit aeda665

Browse files
Leverage PHP8's get_debug_type()
1 parent 43e4790 commit aeda665

38 files changed

+63
-62
lines changed

ConstraintValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function initialize(ExecutionContextInterface $context)
5858
*/
5959
protected function formatTypeOf($value)
6060
{
61-
return \is_object($value) ? \get_class($value) : \gettype($value);
61+
return get_debug_type($value);
6262
}
6363

6464
/**

Constraints/AbstractComparisonValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function validate($value, Constraint $constraint)
5555
try {
5656
$comparedValue = $this->getPropertyAccessor()->getValue($object, $path);
5757
} catch (NoSuchPropertyException $e) {
58-
throw new ConstraintDefinitionException(sprintf('Invalid property path "%s" provided to "%s" constraint: %s.', $path, \get_class($constraint), $e->getMessage()), 0, $e);
58+
throw new ConstraintDefinitionException(sprintf('Invalid property path "%s" provided to "%s" constraint: %s.', $path, get_debug_type($constraint), $e->getMessage()), 0, $e);
5959
}
6060
} else {
6161
$comparedValue = $constraint->value;
@@ -72,7 +72,7 @@ public function validate($value, Constraint $constraint)
7272
try {
7373
$comparedValue = new $dateTimeClass($comparedValue);
7474
} catch (\Exception $e) {
75-
throw new ConstraintDefinitionException(sprintf('The compared value "%s" could not be converted to a "%s" instance in the "%s" constraint.', $comparedValue, $dateTimeClass, \get_class($constraint)));
75+
throw new ConstraintDefinitionException(sprintf('The compared value "%s" could not be converted to a "%s" instance in the "%s" constraint.', $comparedValue, $dateTimeClass, get_debug_type($constraint)));
7676
}
7777
}
7878

Constraints/BicValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function validate($value, Constraint $constraint)
130130
try {
131131
$iban = $this->getPropertyAccessor()->getValue($object, $path);
132132
} catch (NoSuchPropertyException $e) {
133-
throw new ConstraintDefinitionException(sprintf('Invalid property path "%s" provided to "%s" constraint: %s.', $path, \get_class($constraint), $e->getMessage()), 0, $e);
133+
throw new ConstraintDefinitionException(sprintf('Invalid property path "%s" provided to "%s" constraint: %s.', $path, get_debug_type($constraint), $e->getMessage()), 0, $e);
134134
}
135135
}
136136
if (!$iban) {

Constraints/CallbackValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function validate($object, Constraint $constraint)
4646
$method($object, $this->context, $constraint->payload);
4747
} elseif (null !== $object) {
4848
if (!method_exists($object, $method)) {
49-
throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist in class "%s".', $method, \get_class($object)));
49+
throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist in class "%s".', $method, get_debug_type($object)));
5050
}
5151

5252
$reflMethod = new \ReflectionMethod($object, $method);

Constraints/Composite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function __construct($options = null)
101101
$excessGroups = array_diff($constraint->groups, $this->groups);
102102

103103
if (\count($excessGroups) > 0) {
104-
throw new ConstraintDefinitionException(sprintf('The group(s) "%s" passed to the constraint "%s" should also be passed to its containing constraint "%s".', implode('", "', $excessGroups), \get_class($constraint), static::class));
104+
throw new ConstraintDefinitionException(sprintf('The group(s) "%s" passed to the constraint "%s" should also be passed to its containing constraint "%s".', implode('", "', $excessGroups), get_debug_type($constraint), static::class));
105105
}
106106
} else {
107107
$constraint->groups = $this->groups;

Constraints/Email.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct($options = null)
6262
}
6363

6464
if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
65-
throw new InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', \is_object($this->normalizer) ? \get_class($this->normalizer) : \gettype($this->normalizer)));
65+
throw new InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', get_debug_type($this->normalizer)));
6666
}
6767
}
6868
}

Constraints/EmailValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function validate($value, Constraint $constraint)
7070
}
7171

7272
if (!\in_array($constraint->mode, Email::$validationModes, true)) {
73-
throw new \InvalidArgumentException(sprintf('The "%s::$mode" parameter value is not valid.', \get_class($constraint)));
73+
throw new \InvalidArgumentException(sprintf('The "%s::$mode" parameter value is not valid.', get_debug_type($constraint)));
7474
}
7575

7676
if (Email::VALIDATION_MODE_STRICT === $constraint->mode) {

Constraints/Ip.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function __construct($options = null)
8787
}
8888

8989
if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
90-
throw new InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', \is_object($this->normalizer) ? \get_class($this->normalizer) : \gettype($this->normalizer)));
90+
throw new InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', get_debug_type($this->normalizer)));
9191
}
9292
}
9393
}

Constraints/Length.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct($options = null)
6262
}
6363

6464
if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
65-
throw new InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', \is_object($this->normalizer) ? \get_class($this->normalizer) : \gettype($this->normalizer)));
65+
throw new InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', get_debug_type($this->normalizer)));
6666
}
6767
}
6868
}

Constraints/NotBlank.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct($options = null)
3838
parent::__construct($options);
3939

4040
if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
41-
throw new InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', \is_object($this->normalizer) ? \get_class($this->normalizer) : \gettype($this->normalizer)));
41+
throw new InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', get_debug_type($this->normalizer)));
4242
}
4343
}
4444
}

0 commit comments

Comments
 (0)