| Conditions | 16 |
| Paths | 52 |
| Total Lines | 71 |
| Lines | 5 |
| Ratio | 7.04 % |
| 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 |
||
| 158 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
| 159 | $uid = $input->getArgument('uid'); |
||
| 160 | if ($this->userManager->userExists($uid)) { |
||
| 161 | $output->writeln('<error>The user "' . $uid . '" already exists.</error>'); |
||
| 162 | return 1; |
||
| 163 | } |
||
| 164 | |||
| 165 | $readPasswordFromCmdLine = $input->getOption('password-from-cmdline'); |
||
| 166 | // Validate email before we create the user |
||
| 167 | if ($input->getOption('email')) { |
||
| 168 | // Validate first |
||
| 169 | if (!$this->mailer->validateMailAddress($input->getOption('email'))) { |
||
| 170 | // Invalid! Error |
||
| 171 | $output->writeln('<error>Invalid email address supplied</error>'); |
||
| 172 | return 1; |
||
| 173 | } else { |
||
| 174 | $email = $input->getOption('email'); |
||
| 175 | } |
||
| 176 | } else { |
||
| 177 | $email = null; |
||
| 178 | } |
||
| 179 | |||
| 180 | if ($input->getOption('password-from-env')) { |
||
| 181 | $password = \getenv('OC_PASS'); |
||
| 182 | if (!$password) { |
||
| 183 | $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); |
||
| 184 | return 1; |
||
| 185 | } |
||
| 186 | $this->createUser($input, $output, $password, $email); |
||
| 187 | $this->addUserToGroup($input, $output, $this->userManager->get($uid)); |
||
| 188 | } elseif ($readPasswordFromCmdLine) { |
||
| 189 | /** @var $dialog \Symfony\Component\Console\Helper\QuestionHelper */ |
||
| 190 | $dialog = $this->getHelperSet()->get('question'); |
||
| 191 | $q = new Question('<question>Enter password: </question>', false); |
||
| 192 | $q->setHidden(true); |
||
| 193 | $password = $dialog->ask($input, $output, $q); |
||
| 194 | $q = new Question('<question>Confirm password: </question>', false); |
||
| 195 | $q->setHidden(true); |
||
| 196 | $confirm = $dialog->ask($input, $output, $q); |
||
| 197 | |||
| 198 | if ($password !== $confirm) { |
||
| 199 | $output->writeln("<error>Passwords did not match!</error>"); |
||
| 200 | return 1; |
||
| 201 | } |
||
| 202 | |||
| 203 | $this->createUser($input, $output, $password, $email); |
||
| 204 | $this->addUserToGroup($input, $output, $this->userManager->get($uid)); |
||
| 205 | } elseif ($input->getOption('email') && ($email !== null)) { |
||
| 206 | $newUser = $this->createUser->createUser($uid, '', $input->getOption('group'), $email); |
||
| 207 | if ($newUser instanceof User) { |
||
| 208 | $output->writeln('<info>The user "' . $newUser->getUID() . '" was created successfully</info>'); |
||
| 209 | } |
||
| 210 | View Code Duplication | if ($input->getOption('display-name')) { |
|
| 211 | $user = $this->userManager->get($uid); |
||
| 212 | $user->setDisplayName($input->getOption('display-name')); |
||
| 213 | $output->writeln('Display name set to "' . $user->getDisplayName() . '"'); |
||
| 214 | } |
||
| 215 | if ($input->getOption('group')) { |
||
| 216 | if (\is_array($input->getOption('group'))) { |
||
| 217 | foreach ($input->getOption('group') as $group) { |
||
| 218 | if ($this->groupManager->isInGroup($uid, $group)) { |
||
| 219 | $output->writeln('User "' . $uid . '" added to group "' . $group . '"'); |
||
| 220 | } |
||
| 221 | } |
||
| 222 | } |
||
| 223 | } |
||
| 224 | } else { |
||
| 225 | $output->writeln("<error>Interactive input or --password-from-env is needed for entering a password!</error>"); |
||
| 226 | return 1; |
||
| 227 | } |
||
| 228 | } |
||
| 229 | } |
||
| 230 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.