File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ function print_usage_and_exit(string $msg = '') {
7
7
}
8
8
9
9
function convert_codestyle () {
10
+ error_reporting (E_ALL );
10
11
global $ argv ;
11
12
if (count ($ argv ) !== 2 ) {
12
13
print_usage_and_exit ();
@@ -26,6 +27,23 @@ function convert_codestyle() {
26
27
return '_ ' . strtolower ($ msg [0 ]) . $ msg [1 ];
27
28
}, $ args [2 ]);
28
29
}, $ contents );
30
+
31
+ preg_match_all ('@\bfunction\s+(_?[a-z]+(_[a-z]+)+)\s*\(@ ' , $ new_contents , $ matches );
32
+ $ function_names = $ matches [1 ];
33
+ $ function_names_set = array_flip ($ function_names );
34
+ $ new_contents = preg_replace_callback ('@\b_?[a-z]+(_[a-z]+)+\b@ ' , function (array $ args ) use ($ function_names_set ) : string {
35
+ $ name = $ args [0 ];
36
+ if (!isset ($ function_names_set [$ name ])) {
37
+ return $ name ;
38
+ }
39
+ $ name = ltrim ($ name , '_ ' );
40
+ $ name = preg_replace_callback ('@_[a-z]@ ' , function (array $ args ) {
41
+ $ msg = $ args [0 ];
42
+ assert (strlen ($ msg ) === 2 );
43
+ return strtoupper ($ msg [1 ]);
44
+ }, $ name );
45
+ return $ name ;
46
+ }, $ new_contents );
29
47
echo $ new_contents ;
30
48
}
31
49
You can’t perform that action at this time.
0 commit comments