1 | <?php |
||
14 | class PrefixSuffix |
||
|
|||
15 | { |
||
16 | // https://regex101.com/r/tJWUrd/6 |
||
17 | // ie: "blog/2017-10-19-post-1.md" prefix is "2017-10-19" |
||
18 | // ie: "projet/1-projet-a.md" prefix is "1" |
||
19 | const PREFIX_PATTERN = '^(|.*\/)(([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])|[0-9]+)(-|_|\.)(.*)$'; |
||
20 | // https://regex101.com/r/GlgBdT/7 |
||
21 | // ie: "blog/2017-10-19-post-1.en.md" suffix is "en" |
||
22 | // ie: "projet/1-projet-a.fr-FR.md" suffix is "fr-FR" |
||
23 | const SUFFIX_PATTERN = '^(.*)\.([a-z]{2}(-[A-Z]{2})?)$'; |
||
24 | |||
25 | /** |
||
26 | * Return true if the string contains a prefix or a suffix. |
||
27 | * |
||
28 | * @param string $string |
||
29 | * @param string $type |
||
30 | * |
||
31 | * @return bool |
||
32 | */ |
||
33 | protected static function has(string $string, string $type): bool |
||
37 | |||
38 | /** |
||
39 | * Return true if the string contains a prefix. |
||
40 | * |
||
41 | * @param string $string |
||
42 | * |
||
43 | * @return bool |
||
44 | */ |
||
45 | public static function hasPrefix(string $string): bool |
||
49 | |||
50 | /** |
||
51 | * Return true if the string contains a suffix. |
||
52 | * |
||
53 | * @param string $string |
||
54 | * |
||
55 | * @return bool |
||
56 | */ |
||
57 | public static function hasSuffix(string $string): bool |
||
61 | |||
62 | /** |
||
63 | * Return the prefix or the suffix if exists. |
||
64 | * |
||
65 | * @param string $string |
||
66 | * @param string $type |
||
67 | * |
||
68 | * @return string[]|null |
||
69 | */ |
||
70 | protected static function get(string $string, string $type): ?string |
||
84 | |||
85 | /** |
||
86 | * Return the prefix if exists. |
||
87 | * |
||
88 | * @param string $string |
||
89 | * |
||
90 | * @return string[]|null |
||
91 | */ |
||
92 | public static function getPrefix(string $string): ?string |
||
96 | |||
97 | /** |
||
98 | * Return the suffix if exists. |
||
99 | * |
||
100 | * @param string $string |
||
101 | * |
||
102 | * @return string[]|null |
||
103 | */ |
||
104 | public static function getSuffix(string $string): ?string |
||
108 | |||
109 | /** |
||
110 | * Return string without the prefix and the suffix (if exists). |
||
111 | * |
||
112 | * @param string $string |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | public static function sub(string $string): string |
||
131 | |||
132 | /** |
||
133 | * Return string without the prefix (if exists). |
||
134 | * |
||
135 | * @param string $string |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | public static function subPrefix(string $string): string |
||
149 | |||
150 | /** |
||
151 | * Return expreg pattern by $type. |
||
152 | * |
||
153 | * @param string $type |
||
154 | * |
||
155 | * @return string |
||
156 | */ |
||
157 | protected static function getPattern(string $type): string |
||
168 | } |
||
169 |
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.