deployphp /
deployer
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Deployer\Component\PharUpdate\Version; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Validates version information. |
||
| 9 | * |
||
| 10 | * @author Kevin Herrera <[email protected]> |
||
| 11 | */ |
||
| 12 | class Validator |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * The regular expression for a valid identifier. |
||
| 16 | */ |
||
| 17 | public const IDENTIFIER_REGEX = '/^[0-9A-Za-z\-]+$/'; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * The regular expression for a valid semantic version number. |
||
| 21 | */ |
||
| 22 | public const VERSION_REGEX = '/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Checks if a identifier is valid. |
||
| 26 | * |
||
| 27 | * @param string $identifier A identifier. |
||
| 28 | * |
||
| 29 | * @return boolean TRUE if the identifier is valid, FALSE If not. |
||
| 30 | */ |
||
| 31 | public static function isIdentifier(string $identifier): bool |
||
| 32 | { |
||
| 33 | return (true == preg_match(self::IDENTIFIER_REGEX, $identifier)); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Checks if a number is a valid version number. |
||
| 38 | * |
||
| 39 | * @param integer $number A number. |
||
| 40 | * |
||
| 41 | * @return boolean TRUE if the number is valid, FALSE If not. |
||
| 42 | */ |
||
| 43 | public static function isNumber(int $number): bool |
||
| 44 | { |
||
| 45 | return (true == preg_match('/^(0|[1-9]\d*)$/', (string) $number)); |
||
|
0 ignored issues
–
show
|
|||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Checks if the string representation of a version number is valid. |
||
| 50 | * |
||
| 51 | * @param string $version The string representation. |
||
| 52 | * |
||
| 53 | * @return boolean TRUE if the string representation is valid, FALSE if not. |
||
| 54 | */ |
||
| 55 | public static function isVersion(string $version): bool |
||
| 56 | { |
||
| 57 | return (true == preg_match(self::VERSION_REGEX, $version)); |
||
|
0 ignored issues
–
show
|
|||
| 58 | } |
||
| 59 | } |
||
| 60 |