1 | <?php |
||
14 | class Prefix |
||
|
|||
15 | { |
||
16 | // https://regex101.com/r/tJWUrd/5 |
||
17 | // ie: "blog/2017-10-19-post-with-prefix.md" prefix is "2017-10-19" |
||
18 | const PREFIX_PATTERN = '^(.*?)(([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])|[0-9]+)(-|_|\.)(.*)$'; |
||
19 | |||
20 | /** |
||
21 | * Return true if the string contains a prefix. |
||
22 | * |
||
23 | * @param string $string |
||
24 | * |
||
25 | * @return bool |
||
26 | */ |
||
27 | public static function hasPrefix(string $string): bool |
||
35 | |||
36 | /** |
||
37 | * Return the prefix if exists. |
||
38 | * |
||
39 | * @param string $string |
||
40 | * |
||
41 | * @return string[]|null |
||
42 | */ |
||
43 | public static function getPrefix(string $string): ?string |
||
52 | |||
53 | /** |
||
54 | * Return string without the prefix (if exists). |
||
55 | * |
||
56 | * @param string $string |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | public static function subPrefix(string $string): string |
||
69 | } |
||
70 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.