From dcff22fb51f927f3d396081d0f8748a11c3ad250 Mon Sep 17 00:00:00 2001 From: Daniel Noel-Davies Date: Wed, 4 Jan 2017 14:52:25 +0000 Subject: [PATCH 1/2] Update Email Assertion messages I've refactored the email message to have the exception message in one place instead of 2 as it was before. --- lib/Assert/Assertion.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/Assert/Assertion.php b/lib/Assert/Assertion.php index 62574be6..de62d92a 100644 --- a/lib/Assert/Assertion.php +++ b/lib/Assert/Assertion.php @@ -1412,12 +1412,11 @@ public static function writeable($value, $message = null, $propertyPath = null) public static function email($value, $message = null, $propertyPath = null) { static::string($value, $message, $propertyPath); + + $message = $message ?: 'Value "%s" was expected to be a valid e-mail address.' if (! filter_var($value, FILTER_VALIDATE_EMAIL)) { - $message = sprintf( - $message ?: 'Value "%s" was expected to be a valid e-mail address.', - static::stringify($value) - ); + $message = sprintf($message, static::stringify($value)); throw static::createException($value, $message, static::INVALID_EMAIL, $propertyPath); } else { @@ -1425,10 +1424,7 @@ public static function email($value, $message = null, $propertyPath = null) // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 if (version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false) { - $message = sprintf( - $message ?: 'Value "%s" was expected to be a valid e-mail address.', - static::stringify($value) - ); + $message = sprintf($message, static::stringify($value)); throw static::createException($value, $message, static::INVALID_EMAIL, $propertyPath); } From 0f48ec835ecca336bf834d2a859148476d9bd49d Mon Sep 17 00:00:00 2001 From: Daniel Noel-Davies Date: Wed, 4 Jan 2017 15:05:25 +0000 Subject: [PATCH 2/2] Add missing semicolon --- lib/Assert/Assertion.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Assert/Assertion.php b/lib/Assert/Assertion.php index de62d92a..e5ab1eac 100644 --- a/lib/Assert/Assertion.php +++ b/lib/Assert/Assertion.php @@ -1413,7 +1413,7 @@ public static function email($value, $message = null, $propertyPath = null) { static::string($value, $message, $propertyPath); - $message = $message ?: 'Value "%s" was expected to be a valid e-mail address.' + $message = $message ?: 'Value "%s" was expected to be a valid e-mail address.'; if (! filter_var($value, FILTER_VALIDATE_EMAIL)) { $message = sprintf($message, static::stringify($value));