@@ -65,13 +65,7 @@ class InitCommand extends Command implements Isolatable
6565
6666 public function handle (): void
6767 {
68- $ this ->appName = $ this ->argument ('application-name ' );
69-
70- $ pascalCaseAppName = $ this ->toPascalCase ($ this ->appName );
71-
72- if (!$ this ->isPascalCase ($ this ->appName ) && $ this ->confirm ("The application name is not in PascalCase, would you like to use {$ pascalCaseAppName }" )) {
73- $ this ->appName = $ pascalCaseAppName ;
74- }
68+ $ this ->prepareAppName ();
7569
7670 $ kebabName = Str::kebab ($ this ->appName );
7771
@@ -367,20 +361,14 @@ protected function saveReadme(): void
367361 file_put_contents ('README.md ' , $ this ->readmeContent );
368362 }
369363
370- protected function toPascalCase ( string $ string ): string
364+ protected function prepareAppName ( ): void
371365 {
372- // Remove non-alphanumeric characters except underscores
373- $ string = preg_replace ('/[^a-zA-Z0-9_]/ ' , '' , $ string );
374-
375- // Replace underscores with spaces, then uppercase the first letter of each word
376- $ string = ucwords (str_replace ('_ ' , ' ' , $ string ));
366+ $ this ->appName = $ this ->argument ('application-name ' );
377367
378- // Remove spaces
379- return str_replace (' ' , '' , $ string );
380- }
368+ $ pascalCaseAppName = ucfirst (Str::camel ($ this ->appName ));
381369
382- protected function isPascalCase ( string $ string ): bool
383- {
384- return preg_match ( ' /^[A-Z][a-zA-Z0-9]*$/ ' , $ string );
370+ if ( $ this -> appName !== $ pascalCaseAppName && $ this -> confirm ( " The application name is not in PascalCase, would you like to use { $ pascalCaseAppName }" )) {
371+ $ this -> appName = $ pascalCaseAppName ;
372+ }
385373 }
386374}
0 commit comments