| Conditions | 13 |
| Paths | 161 |
| Total Lines | 74 |
| Code Lines | 51 |
| 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 |
||
| 120 | protected function validateInput(InputInterface $input, OutputInterface $output, $supportedDatabases) { |
||
| 121 | $db = strtolower($input->getOption('database')); |
||
| 122 | |||
| 123 | if (!in_array($db, $supportedDatabases)) { |
||
| 124 | throw new InvalidArgumentException("Database <$db> is not supported."); |
||
| 125 | } |
||
| 126 | |||
| 127 | $dbUser = $input->getOption('database-user'); |
||
| 128 | $dbPass = $input->getOption('database-pass'); |
||
| 129 | $dbName = $input->getOption('database-name'); |
||
| 130 | $dbPort = $input->getOption('database-port'); |
||
| 131 | if ($db === 'oci') { |
||
| 132 | // an empty hostname needs to be read from the raw parameters |
||
| 133 | $dbHost = $input->getParameterOption('--database-host', ''); |
||
| 134 | } else { |
||
| 135 | $dbHost = $input->getOption('database-host'); |
||
| 136 | } |
||
| 137 | if ($dbPort) { |
||
| 138 | // Append the port to the host so it is the same as in the config (there is no dbport config) |
||
| 139 | $dbHost .= ':' . $dbPort; |
||
|
|
|||
| 140 | } |
||
| 141 | if ($input->hasParameterOption('--database-pass')) { |
||
| 142 | $dbPass = (string) $input->getOption('database-pass'); |
||
| 143 | } |
||
| 144 | $adminLogin = $input->getOption('admin-user'); |
||
| 145 | $adminPassword = $input->getOption('admin-pass'); |
||
| 146 | $adminEmail = $input->getOption('admin-email'); |
||
| 147 | $dataDir = $input->getOption('data-dir'); |
||
| 148 | |||
| 149 | if ($db !== 'sqlite') { |
||
| 150 | if (is_null($dbUser)) { |
||
| 151 | throw new InvalidArgumentException("Database user not provided."); |
||
| 152 | } |
||
| 153 | if (is_null($dbName)) { |
||
| 154 | throw new InvalidArgumentException("Database name not provided."); |
||
| 155 | } |
||
| 156 | if (is_null($dbPass)) { |
||
| 157 | /** @var QuestionHelper $helper */ |
||
| 158 | $helper = $this->getHelper('question'); |
||
| 159 | $question = new Question('What is the password to access the database with user <'.$dbUser.'>?'); |
||
| 160 | $question->setHidden(true); |
||
| 161 | $question->setHiddenFallback(false); |
||
| 162 | $dbPass = $helper->ask($input, $output, $question); |
||
| 163 | } |
||
| 164 | } |
||
| 165 | |||
| 166 | if (is_null($adminPassword)) { |
||
| 167 | /** @var QuestionHelper $helper */ |
||
| 168 | $helper = $this->getHelper('question'); |
||
| 169 | $question = new Question('What is the password you like to use for the admin account <'.$adminLogin.'>?'); |
||
| 170 | $question->setHidden(true); |
||
| 171 | $question->setHiddenFallback(false); |
||
| 172 | $adminPassword = $helper->ask($input, $output, $question); |
||
| 173 | } |
||
| 174 | |||
| 175 | if ($adminEmail !== null && !filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) { |
||
| 176 | throw new InvalidArgumentException('Invalid e-mail-address <' . $adminEmail . '> for <' . $adminLogin . '>.'); |
||
| 177 | } |
||
| 178 | |||
| 179 | $options = [ |
||
| 180 | 'dbtype' => $db, |
||
| 181 | 'dbuser' => $dbUser, |
||
| 182 | 'dbpass' => $dbPass, |
||
| 183 | 'dbname' => $dbName, |
||
| 184 | 'dbhost' => $dbHost, |
||
| 185 | 'adminlogin' => $adminLogin, |
||
| 186 | 'adminpass' => $adminPassword, |
||
| 187 | 'adminemail' => $adminEmail, |
||
| 188 | 'directory' => $dataDir |
||
| 189 | ]; |
||
| 190 | if ($db === 'oci') { |
||
| 191 | $options['dbtablespace'] = $input->getParameterOption('--database-table-space', ''); |
||
| 192 | } |
||
| 193 | return $options; |
||
| 194 | } |
||
| 211 |