Conditions | 3 |
Paths | 4 |
Total Lines | 65 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
24 | public function __invoke(string $name, InputInterface $input, OutputInterface $output) |
||
25 | { |
||
26 | $output->writeln('<info># Building Laravel application [' . $name . ']...</info>'); |
||
27 | |||
28 | $directory = getcwd(); |
||
29 | |||
30 | $commands = [ |
||
31 | 'laravel new ' . $name . ' ' . ($this->force ? '--force' : ''), |
||
32 | ]; |
||
33 | |||
34 | $runner = new CommandRunner($output, $directory); |
||
35 | $isSuccessful = $runner->run($commands); |
||
36 | |||
37 | $filesystem = new ProjectFilesystem(getcwd() . '/' . $name); |
||
38 | |||
39 | $output->writeln('<info>Update file: .gitignore</info>'); |
||
40 | $filesystem->updateFile('.gitignore', function (string $content) { |
||
41 | $patterns = [ |
||
42 | '/(\/node_modules)/', |
||
43 | ]; |
||
44 | $replace = [ |
||
45 | "/.idea\n\${1}", |
||
46 | ]; |
||
47 | |||
48 | return preg_replace($patterns, $replace, $content); |
||
49 | }); |
||
50 | |||
51 | $output->writeln('<info>Update file: .env</info>'); |
||
52 | $filesystem->updateFile('.env', function (string $content) use ($name) { |
||
53 | $patterns = [ |
||
54 | '/APP_URL=http:\/\/localhost/', |
||
55 | '/DB_DATABASE=laravel/', |
||
56 | '/DB_USERNAME=root/', |
||
57 | '/DB_PASSWORD=/', |
||
58 | ]; |
||
59 | $replace = [ |
||
60 | "APP_URL=http://{$name}.test", |
||
61 | "DB_DATABASE={$name}", |
||
62 | "DB_USERNAME=homestead", |
||
63 | "DB_PASSWORD=secret", |
||
64 | ]; |
||
65 | |||
66 | return preg_replace($patterns, $replace, $content); |
||
67 | }); |
||
68 | |||
69 | $output->writeln('<info>Update file: .env.example</info>'); |
||
70 | $filesystem->updateFile('.env.example', function (string $content) use ($name) { |
||
71 | $patterns = [ |
||
72 | '/APP_URL=http:\/\/localhost/', |
||
73 | '/DB_DATABASE=laravel/', |
||
74 | '/DB_USERNAME=root/', |
||
75 | '/DB_PASSWORD=/', |
||
76 | ]; |
||
77 | $replace = [ |
||
78 | "APP_URL=http://{$name}.test", |
||
79 | "DB_DATABASE={$name}", |
||
80 | "DB_USERNAME=homestead", |
||
81 | "DB_PASSWORD=secret", |
||
82 | ]; |
||
83 | |||
84 | return preg_replace($patterns, $replace, $content); |
||
85 | }); |
||
86 | |||
87 | if ($isSuccessful) { |
||
88 | $output->writeln('<comment>Default Laravel install done.</comment>'); |
||
89 | } |
||
92 |