Conditions | 14 |
Paths | 321 |
Total Lines | 80 |
Code Lines | 56 |
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 | $dbTablePrefix = 'oc_'; |
||
142 | if ($input->hasParameterOption('--database-table-prefix')) { |
||
143 | $dbTablePrefix = (string) $input->getOption('database-table-prefix'); |
||
144 | $dbTablePrefix = trim($dbTablePrefix); |
||
145 | } |
||
146 | if ($input->hasParameterOption('--database-pass')) { |
||
147 | $dbPass = (string) $input->getOption('database-pass'); |
||
148 | } |
||
149 | $adminLogin = $input->getOption('admin-user'); |
||
150 | $adminPassword = $input->getOption('admin-pass'); |
||
151 | $adminEmail = $input->getOption('admin-email'); |
||
152 | $dataDir = $input->getOption('data-dir'); |
||
153 | |||
154 | if ($db !== 'sqlite') { |
||
155 | if (is_null($dbUser)) { |
||
156 | throw new InvalidArgumentException("Database user not provided."); |
||
157 | } |
||
158 | if (is_null($dbName)) { |
||
159 | throw new InvalidArgumentException("Database name not provided."); |
||
160 | } |
||
161 | if (is_null($dbPass)) { |
||
162 | /** @var QuestionHelper $helper */ |
||
163 | $helper = $this->getHelper('question'); |
||
164 | $question = new Question('What is the password to access the database with user <'.$dbUser.'>?'); |
||
165 | $question->setHidden(true); |
||
166 | $question->setHiddenFallback(false); |
||
167 | $dbPass = $helper->ask($input, $output, $question); |
||
168 | } |
||
169 | } |
||
170 | |||
171 | if (is_null($adminPassword)) { |
||
172 | /** @var QuestionHelper $helper */ |
||
173 | $helper = $this->getHelper('question'); |
||
174 | $question = new Question('What is the password you like to use for the admin account <'.$adminLogin.'>?'); |
||
175 | $question->setHidden(true); |
||
176 | $question->setHiddenFallback(false); |
||
177 | $adminPassword = $helper->ask($input, $output, $question); |
||
178 | } |
||
179 | |||
180 | if ($adminEmail !== null && !filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) { |
||
181 | throw new InvalidArgumentException('Invalid e-mail-address <' . $adminEmail . '> for <' . $adminLogin . '>.'); |
||
182 | } |
||
183 | |||
184 | $options = [ |
||
185 | 'dbtype' => $db, |
||
186 | 'dbuser' => $dbUser, |
||
187 | 'dbpass' => $dbPass, |
||
188 | 'dbname' => $dbName, |
||
189 | 'dbhost' => $dbHost, |
||
190 | 'dbtableprefix' => $dbTablePrefix, |
||
191 | 'adminlogin' => $adminLogin, |
||
192 | 'adminpass' => $adminPassword, |
||
193 | 'adminemail' => $adminEmail, |
||
194 | 'directory' => $dataDir |
||
195 | ]; |
||
196 | if ($db === 'oci') { |
||
197 | $options['dbtablespace'] = $input->getParameterOption('--database-table-space', ''); |
||
198 | } |
||
199 | return $options; |
||
200 | } |
||
217 |