| Conditions | 22 |
| Paths | 1003 |
| Total Lines | 103 |
| Code Lines | 74 |
| Lines | 13 |
| Ratio | 12.62 % |
| Changes | 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 |
||
| 67 | public function handle() |
||
| 68 | { |
||
| 69 | $variables = []; |
||
| 70 | $file = base_path() . '/.env'; |
||
| 71 | if (! file_exists($file)) { |
||
| 72 | $this->error('Missing environment file! It appears that you have not installed this panel correctly.'); |
||
| 73 | exit(); |
||
| 74 | } |
||
| 75 | |||
| 76 | $envContents = file_get_contents($file); |
||
| 77 | |||
| 78 | $this->table([ |
||
| 79 | 'Option', |
||
| 80 | 'Description', |
||
| 81 | ], [ |
||
| 82 | [ |
||
| 83 | 'smtp', |
||
| 84 | 'SMTP Server Email', |
||
| 85 | ], |
||
| 86 | [ |
||
| 87 | 'mail', |
||
| 88 | 'PHP\'s Internal Mail Server', |
||
| 89 | ], |
||
| 90 | [ |
||
| 91 | 'mailgun', |
||
| 92 | 'Mailgun Email Service', |
||
| 93 | ], |
||
| 94 | [ |
||
| 95 | 'mandrill', |
||
| 96 | 'Mandrill Transactional Email Service', |
||
| 97 | ], |
||
| 98 | [ |
||
| 99 | 'postmark', |
||
| 100 | 'Postmark Transactional Email Service', |
||
| 101 | ], |
||
| 102 | ]); |
||
| 103 | |||
| 104 | $variables['MAIL_DRIVER'] = is_null($this->option('driver')) ? $this->choice('Which email driver would you like to use?', [ |
||
| 105 | 'smtp', |
||
| 106 | 'mail', |
||
| 107 | 'mailgun', |
||
| 108 | 'mandrill', |
||
| 109 | 'postmark', |
||
| 110 | ]) : $this->option('driver'); |
||
| 111 | |||
| 112 | switch ($variables['MAIL_DRIVER']) { |
||
| 113 | case 'smtp': |
||
| 114 | $variables['MAIL_HOST'] = is_null($this->option('host')) ? $this->ask('SMTP Host (e.g smtp.google.com)', config('mail.host')) : $this->option('host'); |
||
| 115 | $variables['MAIL_PORT'] = is_null($this->option('port')) ? $this->anticipate('SMTP Host Port (e.g 587)', ['587', config('mail.port')], config('mail.port')) : $this->option('port'); |
||
| 116 | $variables['MAIL_USERNAME'] = is_null($this->option('username')) ? $this->ask('SMTP Username', config('mail.username')) : $this->option('password'); |
||
| 117 | $variables['MAIL_PASSWORD'] = is_null($this->option('password')) ? $this->secret('SMTP Password') : $this->option('password'); |
||
| 118 | break; |
||
| 119 | case 'mail': |
||
| 120 | break; |
||
| 121 | case 'mailgun': |
||
| 122 | $variables['MAILGUN_DOMAIN'] = is_null($this->option('host')) ? $this->ask('Mailgun Domain') : $this->option('host'); |
||
| 123 | $variables['MAILGUN_KEY'] = is_null($this->option('username')) ? $this->ask('Mailgun Key') : $this->option('username'); |
||
| 124 | break; |
||
| 125 | case 'mandrill': |
||
| 126 | $variables['MANDRILL_SECRET'] = is_null($this->option('username')) ? $this->ask('Mandrill Secret') : $this->option('username'); |
||
| 127 | break; |
||
| 128 | case 'postmark': |
||
| 129 | $variables['MAIL_DRIVER'] = 'smtp'; |
||
| 130 | $variables['MAIL_HOST'] = 'smtp.postmarkapp.com'; |
||
| 131 | $variables['MAIL_PORT'] = 587; |
||
| 132 | $variables['MAIL_USERNAME'] = is_null($this->option('username')) ? $this->ask('Postmark API Token', config('mail.username')) : $this->option('username'); |
||
| 133 | $variables['MAIL_PASSWORD'] = $variables['MAIL_USERNAME']; |
||
| 134 | break; |
||
| 135 | default: |
||
| 136 | $this->error('No email service was defined!'); |
||
| 137 | exit(); |
||
| 138 | break; |
||
| 139 | } |
||
| 140 | |||
| 141 | $variables['MAIL_FROM'] = is_null($this->option('email')) ? $this->ask('Email address emails should originate from', config('mail.from.address')) : $this->option('email'); |
||
| 142 | $variables['MAIL_FROM_NAME'] = is_null($this->option('from-name')) ? $this->ask('Name emails should appear to be from', config('mail.from.name')) : $this->option('from-name'); |
||
| 143 | $variables['MAIL_FROM_NAME'] = '"' . $variables['MAIL_FROM_NAME'] . '"'; |
||
| 144 | $variables['MAIL_ENCRYPTION'] = 'tls'; |
||
| 145 | |||
| 146 | $bar = $this->output->createProgressBar(count($variables)); |
||
| 147 | |||
| 148 | $this->line('Writing new email environment configuration to file.'); |
||
| 149 | View Code Duplication | foreach ($variables as $key => $value) { |
|
| 150 | if (str_contains($value, ' ') && ! str_contains($value, '"')) { |
||
| 151 | $value = '"' . $value . '"'; |
||
| 152 | } |
||
| 153 | $newValue = $key . '=' . $value . ' # DO NOT EDIT! set using pterodactyl:mail'; |
||
| 154 | |||
| 155 | if (preg_match_all('/^' . $key . '=(.*)$/m', $envContents) < 1) { |
||
| 156 | $envContents = $envContents . "\n" . $newValue; |
||
| 157 | } else { |
||
| 158 | $envContents = preg_replace('/^' . $key . '=(.*)$/m', $newValue, $envContents); |
||
| 159 | } |
||
| 160 | $bar->advance(); |
||
| 161 | } |
||
| 162 | |||
| 163 | file_put_contents($file, $envContents); |
||
| 164 | $bar->finish(); |
||
| 165 | |||
| 166 | $this->line('Updating evironment configuration cache file.'); |
||
| 167 | $this->call('config:cache'); |
||
| 168 | echo "\n"; |
||
| 169 | } |
||
| 170 | } |
||
| 171 |
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.