Add ValidatorInterface::getPattern() and set constants to private

This commit is contained in:
Ben Ramsey
2020-02-23 16:12:52 -06:00
parent 84a2e76c7e
commit a8bbc2f58a
4 changed files with 37 additions and 8 deletions
+13 -5
View File
@@ -23,14 +23,22 @@ use function str_replace;
/**
* Rfc4122\Validator validates strings as UUIDs of the RFC 4122 variant
*/
class Validator implements ValidatorInterface
final class Validator implements ValidatorInterface
{
/**
* Regular expression pattern for matching an RFC 4122 UUID
*/
public const VALID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-'
private const VALID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-'
. '[1-5]{1}[0-9A-Fa-f]{3}-[ABab89]{1}[0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$';
/**
* @psalm-pure
* @psalm-return non-empty-string
* @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty
* @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty
*/
public function getPattern(): string
{
return self::VALID_PATTERN;
}
/**
* @psalm-pure
*/
+1 -1
View File
@@ -112,7 +112,7 @@ class Uuid implements UuidInterface
public const RESERVED_FUTURE = 7;
/**
* @deprecated Use {@see GenericValidator::VALID_PATTERN} instead.
* @deprecated Use {@see ValidatorInterface::getPattern()} instead.
*/
public const VALID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$';
+13 -2
View File
@@ -22,12 +22,23 @@ use function str_replace;
/**
* GenericValidator validates strings as UUIDs of any variant
*/
class GenericValidator implements ValidatorInterface
final class GenericValidator implements ValidatorInterface
{
/**
* Regular expression pattern for matching a UUID of any variant.
*/
public const VALID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$';
private const VALID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$';
/**
* @psalm-pure
* @psalm-return non-empty-string
* @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty
* @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty
*/
public function getPattern(): string
{
return self::VALID_PATTERN;
}
/**
* @psalm-pure
+10
View File
@@ -19,6 +19,16 @@ namespace Ramsey\Uuid\Validator;
*/
interface ValidatorInterface
{
/**
* Returns the regular expression pattern used by this validator
*
* @return string The regular expression pattern this validator uses
*
* @psalm-pure
* @psalm-return non-empty-string
*/
public function getPattern(): string;
/**
* Returns true if the provided string represents a UUID
*