Skip to content

Commit afec443

Browse files
authored
Merge pull request #20 from aeviiq/1.0
1.0
2 parents 57393cd + eec3db7 commit afec443

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/Validator.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Aeviiq\ValueObject;
66

77
use Aeviiq\ValueObject\Exception\InvalidArgumentException;
8+
use stdClass;
89
use Symfony\Component\Validator\Constraint;
910
use Symfony\Component\Validator\Constraints\Callback;
1011
use Symfony\Component\Validator\ConstraintViolation;
@@ -61,7 +62,7 @@ public static function validate($value, $constraints): void
6162
$violationMessages[] = $violation->getMessage();
6263
}
6364

64-
throw new InvalidArgumentException(sprintf('Invalid value: "%s"', implode('", "', $violationMessages)));
65+
throw new InvalidArgumentException(sprintf('Invalid value: "%s". "%s"', self::toString($value), implode('", "', $violationMessages)));
6566
}
6667

6768
private static function getValidator(): ValidatorInterface
@@ -72,4 +73,13 @@ private static function getValidator(): ValidatorInterface
7273

7374
return static::$validator;
7475
}
76+
77+
private static function toString(mixed $value): string
78+
{
79+
if (\is_scalar($value) || \is_object($value) && \method_exists($value, '__toString')) {
80+
return (string) $value;
81+
}
82+
83+
return '';
84+
}
7585
}

0 commit comments

Comments
 (0)