| Conditions | 22 |
| Paths | > 20000 |
| Total Lines | 137 |
| Code Lines | 94 |
| Lines | 70 |
| Ratio | 51.09 % |
| Changes | 4 | ||
| 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 |
||
| 71 | public function handle() |
||
| 72 | { |
||
| 73 | $variables = []; |
||
| 74 | $file = base_path() . '/.env'; |
||
| 75 | if (! file_exists($file)) { |
||
| 76 | $this->error('Missing environment file! It appears that you have not installed this panel correctly.'); |
||
| 77 | exit(); |
||
| 78 | } |
||
| 79 | |||
| 80 | $envContents = file_get_contents($file); |
||
| 81 | |||
| 82 | $this->info('Simply leave blank and press enter to fields that you do not wish to update.'); |
||
| 83 | if (is_null(config('pterodactyl.service.author', null))) { |
||
| 84 | $this->info('No service author set, setting one now.'); |
||
| 85 | $variables['SERVICE_AUTHOR'] = (string) Uuid::generate(4); |
||
| 86 | } |
||
| 87 | |||
| 88 | if (isset($variables['APP_THEME'])) { |
||
| 89 | if ($variables['APP_THEME'] === 'default') { |
||
| 90 | $variables['APP_THEME'] = 'pterodactyl'; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | View Code Duplication | if (is_null($this->option('dbhost'))) { |
|
| 95 | $variables['DB_HOST'] = $this->anticipate('Database Host', ['localhost', '127.0.0.1', config('database.connections.mysql.host')], config('database.connections.mysql.host')); |
||
| 96 | } else { |
||
| 97 | $variables['DB_HOST'] = $this->option('dbhost'); |
||
| 98 | } |
||
| 99 | |||
| 100 | View Code Duplication | if (is_null($this->option('dbport'))) { |
|
| 101 | $variables['DB_PORT'] = $this->anticipate('Database Port', [3306, config('database.connections.mysql.port')], config('database.connections.mysql.port')); |
||
| 102 | } else { |
||
| 103 | $variables['DB_PORT'] = $this->option('dbport'); |
||
| 104 | } |
||
| 105 | |||
| 106 | View Code Duplication | if (is_null($this->option('dbname'))) { |
|
| 107 | $variables['DB_DATABASE'] = $this->anticipate('Database Name', ['pterodactyl', 'homestead', config('database.connections.mysql.database')], config('database.connections.mysql.database')); |
||
| 108 | } else { |
||
| 109 | $variables['DB_DATABASE'] = $this->option('dbname'); |
||
| 110 | } |
||
| 111 | |||
| 112 | View Code Duplication | if (is_null($this->option('dbuser'))) { |
|
| 113 | $variables['DB_USERNAME'] = $this->anticipate('Database Username', [config('database.connections.mysql.username')], config('database.connections.mysql.username')); |
||
| 114 | } else { |
||
| 115 | $variables['DB_USERNAME'] = $this->option('dbuser'); |
||
| 116 | } |
||
| 117 | |||
| 118 | if (is_null($this->option('dbpass'))) { |
||
| 119 | $this->line('The Database Password field is required; you cannot hit enter and use a default value.'); |
||
| 120 | $variables['DB_PASSWORD'] = $this->secret('Database User Password'); |
||
| 121 | } else { |
||
| 122 | $variables['DB_PASSWORD'] = $this->option('dbpass'); |
||
| 123 | } |
||
| 124 | |||
| 125 | if (is_null($this->option('url'))) { |
||
| 126 | $variables['APP_URL'] = $this->ask('Panel URL (include http(s)://)', config('app.url')); |
||
| 127 | } else { |
||
| 128 | $variables['APP_URL'] = $this->option('url'); |
||
| 129 | } |
||
| 130 | |||
| 131 | View Code Duplication | if (is_null($this->option('timezone'))) { |
|
| 132 | $this->line('The timezone should match one of the supported timezones according to http://php.net/manual/en/timezones.php'); |
||
| 133 | $variables['APP_TIMEZONE'] = $this->anticipate('Panel Timezone', \DateTimeZone::listIdentifiers(\DateTimeZone::ALL), config('app.timezone')); |
||
| 134 | } else { |
||
| 135 | $variables['APP_TIMEZONE'] = $this->option('timezone'); |
||
| 136 | } |
||
| 137 | |||
| 138 | if (is_null($this->option('driver'))) { |
||
| 139 | $options = [ |
||
| 140 | 'memcached' => 'Memcache', |
||
| 141 | 'redis' => 'Redis (recommended)', |
||
| 142 | 'apc' => 'APC', |
||
| 143 | 'array' => 'PHP Array', |
||
| 144 | ]; |
||
| 145 | $default = (in_array(config('cache.default', 'memcached'), $options)) ? config('cache.default', 'memcached') : 'memcached'; |
||
| 146 | |||
| 147 | $this->line('If you chose redis as your cache driver backend, you *must* have a redis server configured already.'); |
||
| 148 | $variables['CACHE_DRIVER'] = $this->choice('Which cache driver backend would you like to use?', $options, $default); |
||
| 149 | } else { |
||
| 150 | $variables['CACHE_DRIVER'] = $this->option('driver'); |
||
| 151 | } |
||
| 152 | |||
| 153 | View Code Duplication | if (is_null($this->option('session-driver'))) { |
|
| 154 | $options = [ |
||
| 155 | 'database' => 'MySQL (recommended)', |
||
| 156 | 'redis' => 'Redis', |
||
| 157 | 'file' => 'File', |
||
| 158 | 'cookie' => 'Cookie', |
||
| 159 | 'apc' => 'APC', |
||
| 160 | 'array' => 'PHP Array', |
||
| 161 | ]; |
||
| 162 | $default = (in_array(config('session.driver', 'database'), $options)) ? config('cache.default', 'database') : 'database'; |
||
| 163 | |||
| 164 | $this->line('If you chose redis as your cache driver backend, you *must* have a redis server configured already.'); |
||
| 165 | $variables['SESSION_DRIVER'] = $this->choice('Which session driver backend would you like to use?', $options, $default); |
||
| 166 | } else { |
||
| 167 | $variables['SESSION_DRIVER'] = $this->option('session-driver'); |
||
| 168 | } |
||
| 169 | |||
| 170 | View Code Duplication | if (is_null($this->option('queue-driver'))) { |
|
| 171 | $options = [ |
||
| 172 | 'database' => 'Database (recommended)', |
||
| 173 | 'redis' => 'Redis', |
||
| 174 | 'sqs' => 'Amazon SQS', |
||
| 175 | 'sync' => 'Sync', |
||
| 176 | 'null' => 'None', |
||
| 177 | ]; |
||
| 178 | $default = (in_array(config('queue.driver', 'database'), $options)) ? config('queue.driver', 'database') : 'database'; |
||
| 179 | |||
| 180 | $this->line('If you chose redis as your queue driver backend, you *must* have a redis server configured already.'); |
||
| 181 | $variables['QUEUE_DRIVER'] = $this->choice('Which queue driver backend would you like to use?', $options, $default); |
||
| 182 | } else { |
||
| 183 | $variables['QUEUE_DRIVER'] = $this->option('queue-driver'); |
||
| 184 | } |
||
| 185 | |||
| 186 | $bar = $this->output->createProgressBar(count($variables)); |
||
| 187 | |||
| 188 | View Code Duplication | foreach ($variables as $key => $value) { |
|
| 189 | if (str_contains($value, ' ') && ! str_contains($value, '"')) { |
||
| 190 | $value = '"' . $value . '"'; |
||
| 191 | } |
||
| 192 | $newValue = $key . '=' . $value . ' # DO NOT EDIT! set using pterodactyl:env'; |
||
| 193 | |||
| 194 | if (preg_match_all('/^' . $key . '=(.*)$/m', $envContents) < 1) { |
||
| 195 | $envContents = $envContents . "\n" . $newValue; |
||
| 196 | } else { |
||
| 197 | $envContents = preg_replace('/^' . $key . '=(.*)$/m', $newValue, $envContents); |
||
| 198 | } |
||
| 199 | $bar->advance(); |
||
| 200 | } |
||
| 201 | |||
| 202 | file_put_contents($file, $envContents); |
||
| 203 | $bar->finish(); |
||
| 204 | |||
| 205 | $this->call('config:cache'); |
||
| 206 | $this->line("\n"); |
||
| 207 | } |
||
| 208 | } |
||
| 209 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.