1
1
#!/usr/bin/env php
2
2
<?php
3
3
4
- function ask (string $ question , string $ default = '' ): string {
5
- $ answer = readline ($ question . ($ default ? " ( {$ default }) " : null ) . ': ' );
4
+ function ask (string $ question , string $ default = '' ): string
5
+ {
6
+ $ answer = readline ($ question .($ default ? " ( {$ default }) " : null ).': ' );
6
7
7
8
if (! $ answer ) {
8
9
return $ default ;
@@ -11,8 +12,9 @@ function ask(string $question, string $default = ''): string {
11
12
return $ answer ;
12
13
}
13
14
14
- function confirm (string $ question , bool $ default = false ): bool {
15
- $ answer = ask ($ question . ' ( ' . ($ default ? 'Y/n ' : 'y/N ' ) . ') ' );
15
+ function confirm (string $ question , bool $ default = false ): bool
16
+ {
17
+ $ answer = ask ($ question .' ( ' .($ default ? 'Y/n ' : 'y/N ' ).') ' );
16
18
17
19
if (! $ answer ) {
18
20
return $ default ;
@@ -21,15 +23,18 @@ function confirm(string $question, bool $default = false): bool {
21
23
return strtolower ($ answer ) === 'y ' ;
22
24
}
23
25
24
- function writeln (string $ line ): void {
25
- echo $ line . PHP_EOL ;
26
+ function writeln (string $ line ): void
27
+ {
28
+ echo $ line .PHP_EOL ;
26
29
}
27
30
28
- function run (string $ command ): string {
31
+ function run (string $ command ): string
32
+ {
29
33
return trim (shell_exec ($ command ));
30
34
}
31
35
32
- function str_after (string $ subject , string $ search ): string {
36
+ function str_after (string $ subject , string $ search ): string
37
+ {
33
38
$ pos = strrpos ($ subject , $ search );
34
39
35
40
if ($ pos === false ) {
@@ -39,15 +44,18 @@ function str_after(string $subject, string $search): string {
39
44
return substr ($ subject , $ pos + strlen ($ search ));
40
45
}
41
46
42
- function slugify (string $ subject ): string {
47
+ function slugify (string $ subject ): string
48
+ {
43
49
return strtolower (trim (preg_replace ('/[^A-Za-z0-9-]+/ ' , '- ' , $ subject ), '- ' ));
44
50
}
45
51
46
- function title_case (string $ subject ): string {
52
+ function title_case (string $ subject ): string
53
+ {
47
54
return str_replace (' ' , '' , ucwords (str_replace (['- ' , '_ ' ], ' ' , $ subject )));
48
55
}
49
56
50
- function replace_in_file (string $ file , array $ replacements ): void {
57
+ function replace_in_file (string $ file , array $ replacements ): void
58
+ {
51
59
$ contents = file_get_contents ($ file );
52
60
53
61
file_put_contents (
@@ -60,7 +68,8 @@ function replace_in_file(string $file, array $replacements): void {
60
68
);
61
69
}
62
70
63
- function removeReadmeParagraphs (string $ file ): void {
71
+ function removeReadmeParagraphs (string $ file ): void
72
+ {
64
73
$ contents = file_get_contents ($ file );
65
74
66
75
file_put_contents (
@@ -69,16 +78,19 @@ function removeReadmeParagraphs(string $file): void {
69
78
);
70
79
}
71
80
72
- function determineSeparator (string $ path ): string {
81
+ function determineSeparator (string $ path ): string
82
+ {
73
83
return str_replace ('/ ' , DIRECTORY_SEPARATOR , $ path );
74
84
}
75
85
76
- function replaceForWindows (): array {
86
+ function replaceForWindows (): array
87
+ {
77
88
return preg_split (
'/ \\r \\n| \\r| \\n/ ' ,
run (
'dir /S /B * | findstr /v /i .git\ | findstr /v /i vendor | findstr /v /i ' .
basename (
__FILE__ ).
' | findstr /r /i /M /F:/ ":author :vendor :package VendorName skeleton vendor_name vendor_slug [email protected] " ' ));
78
89
}
79
90
80
- function replaceForAllOtherOSes (): array {
81
- return explode (
PHP_EOL ,
run (
'grep -E -r -l -i ":author|:vendor|:package|VendorName|skeleton|vendor_name|vendor_slug|[email protected] " --exclude-dir=vendor ./* ./.github/* | grep -v ' .
basename (
__FILE__ )));
91
+ function replaceForAllOtherOSes (): array
92
+ {
93
+ return explode (
PHP_EOL ,
run (
'grep -E -r -l -i ":author|:vendor|:package|VendorName|skeleton|vendor_name|vendor_slug|[email protected] " --exclude-dir=vendor ./* ./.github/* | grep -v ' .
basename (
__FILE__ )));
82
94
}
83
95
84
96
$ gitName = run ('git config user.name ' );
@@ -138,11 +150,10 @@ function replaceForAllOtherOSes(): array {
138
150
]);
139
151
140
152
match (true ) {
141
- str_contains ($ file , determineSeparator ('src/SkeletonClass.php ' )) => rename ($ file , determineSeparator ('./src/ ' . $ className . 'Class.php ' )),
153
+ str_contains ($ file , determineSeparator ('src/SkeletonClass.php ' )) => rename ($ file , determineSeparator ('./src/ ' . $ className. 'Class.php ' )),
142
154
str_contains ($ file , 'README.md ' ) => removeReadmeParagraphs ($ file ),
143
155
default => [],
144
156
};
145
-
146
157
}
147
158
148
159
confirm ('Execute `composer install` and run tests? ' ) && run ('composer install && composer test ' );
0 commit comments