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