Skip to content

Commit

Permalink
Improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Aug 2, 2022
1 parent 9af4fe3 commit f074569
Showing 1 changed file with 29 additions and 43 deletions.
72 changes: 29 additions & 43 deletions src/Assert.php
Expand Up @@ -379,12 +379,10 @@ private static function stringPlausibleBase64(string $value, string $message = '
}

if ($result === false) {
throw new InvalidArgumentException(
sprintf(
$message ?: '\'%s\' is not a valid Base64 encoded string',
$value
)
);
throw new InvalidArgumentException(sprintf(
$message ?: '\'%s\' is not a valid Base64 encoded string',
$value
));
}
}

Expand All @@ -396,12 +394,10 @@ private static function stringPlausibleBase64(string $value, string $message = '
private static function validDateTime(string $value, string $message = ''): void
{
if (DateTime::createFromFormat(DateTime::ISO8601, $value) === false) {
throw new InvalidArgumentException(
sprintf(
$message ?: '\'%s\' is not a valid DateTime',
$value
)
);
throw new InvalidArgumentException(sprintf(
$message ?: '\'%s\' is not a valid DateTime',
$value
));
}
}

Expand All @@ -414,19 +410,15 @@ private static function validDateTimeZulu(string $value, string $message = ''):
{
$dateTime = DateTime::createFromFormat(DateTime::ISO8601, $value);
if ($dateTime === false) {
throw new InvalidArgumentException(
sprintf(
$message ?: '\'%s\' is not a valid DateTime',
$value
)
);
throw new InvalidArgumentException(sprintf(
$message ?: '\'%s\' is not a valid DateTime',
$value
));
} elseif ($dateTime->getTimezone()->getName() !== 'Z') {
throw new InvalidArgumentException(
sprintf(
$message ?: '\'%s\' is not a DateTime expressed in the UTC timezone using the \'Z\' timezone identifier.',
$value
)
);
throw new InvalidArgumentException(sprintf(
$message ?: '\'%s\' is not a DateTime expressed in the UTC timezone using the \'Z\' timezone identifier.',
$value
));
}
}

Expand All @@ -439,13 +431,11 @@ private static function validDateTimeZulu(string $value, string $message = ''):
private static function notInArray($value, array $values, string $message = ''): void
{
if (in_array($value, $values, true)) {
throw new InvalidArgumentException(
sprintf(
$message ?: 'Expected none of: %2$s. Got: %s',
static::valueToString($value),
implode(', ', array_map(['static', 'valueToString'], $values))
)
);
throw new InvalidArgumentException(sprintf(
$message ?: 'Expected none of: %2$s. Got: %s',
static::valueToString($value),
implode(', ', array_map(['static', 'valueToString'], $values))
));
}
}

Expand All @@ -472,12 +462,10 @@ private static function validURN(string $value, string $message = ''): void
private static function validURL(string $value, string $message = ''): void
{
if (filter_var($value, FILTER_VALIDATE_URL) === false) {
throw new InvalidArgumentException(
sprintf(
$message ?: '\'%s\' is not a valid RFC2396 compliant URL',
$value
)
);
throw new InvalidArgumentException(sprintf(
$message ?: '\'%s\' is not a valid RFC2396 compliant URL',
$value
));
}
}

Expand All @@ -492,12 +480,10 @@ private static function validURI(string $value, string $message = ''): void
filter_var($value, FILTER_VALIDATE_URL) === false &&
filter_var($value, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => self::$urn_regex]]) === false
) {
throw new InvalidArgumentException(
sprintf(
$message ?: '\'%s\' is not a valid RFC2396 compliant URL, nor a valid RFC8141 compliant URN',
$value
)
);
throw new InvalidArgumentException(sprintf(
$message ?: '\'%s\' is not a valid RFC2396 compliant URL, nor a valid RFC8141 compliant URN',
$value
));
}
}

Expand Down

0 comments on commit f074569

Please sign in to comment.