Conditions | 24 |
Paths | > 20000 |
Total Lines | 128 |
Code Lines | 80 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
43 | public function handle(): void |
||
44 | { |
||
45 | $maintenance = $this->appDown(); |
||
46 | $running = $this->stopTmux(); |
||
47 | |||
48 | try { |
||
49 | $output = $this->call('nntmux:git'); |
||
50 | if ($output === 'Already up-to-date.') { |
||
|
|||
51 | $this->info($output); |
||
52 | } else { |
||
53 | $status = $this->call('nntmux:composer'); |
||
54 | if ($status) { |
||
55 | $this->error('Composer failed to update!!'); |
||
56 | } |
||
57 | $fail = $this->call('nntmux:db'); |
||
58 | if ($fail) { |
||
59 | $this->error('Db updating failed!!'); |
||
60 | } |
||
61 | } |
||
62 | } catch (\Exception $e) { |
||
63 | $this->error($e->getMessage()); |
||
64 | } |
||
65 | |||
66 | // Install npm packages |
||
67 | $this->info('Installing npm packages...'); |
||
68 | $process = Process::timeout(360)->run('npm install'); |
||
69 | echo $process->output(); |
||
70 | echo $process->errorOutput(); |
||
71 | $this->info('Npm packages installed successfully!'); |
||
72 | // Run npm build |
||
73 | $this->info('Building assets...'); |
||
74 | $process = Process::timeout(360)->run('npm run build'); |
||
75 | echo $process->output(); |
||
76 | echo $process->errorOutput(); |
||
77 | $this->info('Assets built successfully!'); |
||
78 | |||
79 | $cleared = (new Smarty)->setCompileDir(config('ytake-laravel-smarty.compile_path'))->clearCompiledTemplate(); |
||
80 | if ($cleared) { |
||
81 | $this->output->writeln('<comment>The Smarty compiled template cache has been cleaned for you</comment>'); |
||
82 | } else { |
||
83 | $this->output->writeln( |
||
84 | '<comment>You should clear your Smarty compiled template cache at: '. |
||
85 | config('ytake-laravel-smarty.compile_path').'</comment>' |
||
86 | ); |
||
87 | } |
||
88 | |||
89 | // Merge changes from .env.example into .env |
||
90 | $this->info('Merging changes from .env.example into .env...'); |
||
91 | |||
92 | try { |
||
93 | // Read both files |
||
94 | $envExampleContent = file_get_contents(base_path('.env.example')); |
||
95 | $envContent = file_get_contents(base_path('.env')); |
||
96 | |||
97 | if ($envExampleContent === false || $envContent === false) { |
||
98 | throw new \Exception('Could not read .env or .env.example files'); |
||
99 | } |
||
100 | |||
101 | // Parse files into key-value pairs |
||
102 | $envExampleVars = []; |
||
103 | foreach (preg_split("/\r\n|\n|\r/", $envExampleContent) as $line) { |
||
104 | $line = trim($line); |
||
105 | if (empty($line) || strpos($line, '#') === 0) { |
||
106 | continue; |
||
107 | } |
||
108 | |||
109 | if (preg_match('/^([^=]+)=(.*)$/', $line, $matches)) { |
||
110 | $key = trim($matches[1]); |
||
111 | $value = $matches[2]; // Keep the original value with potential = signs |
||
112 | $envExampleVars[$key] = $value; |
||
113 | } |
||
114 | } |
||
115 | |||
116 | $envVars = []; |
||
117 | foreach (preg_split("/\r\n|\n|\r/", $envContent) as $line) { |
||
118 | $line = trim($line); |
||
119 | if (empty($line) || strpos($line, '#') === 0) { |
||
120 | continue; |
||
121 | } |
||
122 | |||
123 | if (preg_match('/^([^=]+)=(.*)$/', $line, $matches)) { |
||
124 | $key = trim($matches[1]); |
||
125 | $value = $matches[2]; |
||
126 | $envVars[$key] = $value; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | // Find keys in .env.example that are not in .env |
||
131 | $missingKeys = array_diff_key($envExampleVars, $envVars); |
||
132 | |||
133 | if (empty($missingKeys)) { |
||
134 | $this->info('No new keys found in .env.example to merge into .env'); |
||
135 | |||
136 | return; |
||
137 | } |
||
138 | |||
139 | // Add missing keys to .env file |
||
140 | $newEnvContent = $envContent; |
||
141 | if (substr($newEnvContent, -1) !== "\n") { |
||
142 | $newEnvContent .= "\n"; |
||
143 | } |
||
144 | $newEnvContent .= "\n# New settings added from .env.example\n"; |
||
145 | |||
146 | foreach ($missingKeys as $key => $value) { |
||
147 | $newEnvContent .= "$key=$value\n"; |
||
148 | } |
||
149 | |||
150 | // Write updated content back to .env |
||
151 | if (file_put_contents(base_path('.env'), $newEnvContent)) { |
||
152 | $this->info('Successfully merged '.count($missingKeys).' new keys from .env.example into .env'); |
||
153 | $this->line('The following keys were added:'); |
||
154 | foreach ($missingKeys as $key => $value) { |
||
155 | $this->line(" $key=$value"); |
||
156 | } |
||
157 | } else { |
||
158 | throw new \Exception('Failed to write changes to .env file'); |
||
159 | } |
||
160 | |||
161 | } catch (\Exception $e) { |
||
162 | $this->error('Failed to merge changes: '.$e->getMessage()); |
||
163 | $this->info('There are changes in .env.example that need to be added manually to .env'); |
||
164 | } |
||
165 | |||
166 | if ($maintenance === true) { |
||
167 | $this->call('up'); |
||
168 | } |
||
169 | if ($running === true) { |
||
170 | $this->startTmux(); |
||
171 | } |
||
201 |