| Conditions | 16 | 
| Paths | 19 | 
| Total Lines | 81 | 
| Lines | 0 | 
| Ratio | 0 % | 
| 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  | 
            ||
| 104 | 	protected function execute(InputInterface $input, OutputInterface $output) { | 
            ||
| 105 | 		$username = $input->getArgument('user'); | 
            ||
| 106 | 		$emailLink = $input->getOption('send-email'); | 
            ||
| 107 | 		$displayLink = $input->getOption('output-link'); | 
            ||
| 108 | |||
| 109 | /** @var $user \OCP\IUser */  | 
            ||
| 110 | $user = $this->userManager->get($username);  | 
            ||
| 111 | 		if ($user === null) { | 
            ||
| 112 | 			$output->writeln('<error>User does not exist</error>'); | 
            ||
| 113 | return 1;  | 
            ||
| 114 | }  | 
            ||
| 115 | |||
| 116 | 		if ($input->getOption('password-from-env')) { | 
            ||
| 117 | 			$password = $this->environmentHelper->getEnvVar('OC_PASS'); | 
            ||
| 118 | 			if (!$password) { | 
            ||
| 119 | 				$output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); | 
            ||
| 120 | return 1;  | 
            ||
| 121 | }  | 
            ||
| 122 | 		} elseif ($emailLink || $displayLink) { | 
            ||
| 123 | $userId = $user->getUID();  | 
            ||
| 124 | list($link, $token) = $this->lostController->generateTokenAndLink($userId);  | 
            ||
| 125 | |||
| 126 | 			if ($emailLink && $user->getEMailAddress() !== null) { | 
            ||
| 127 | 				try { | 
            ||
| 128 | $this->config->deleteUserValue($userId, 'owncloud', 'lostpassword');  | 
            ||
| 129 | $this->lostController->sendEmail($userId, $token, $link);  | 
            ||
| 130 | 				} catch (\Exception $e) { | 
            ||
| 131 | 					$output->writeln('<error>Can\'t send new user mail to ' . $user->getEMailAddress() . ': ' . $e->getMessage() . '</error>'); | 
            ||
| 132 | return 1;  | 
            ||
| 133 | }  | 
            ||
| 134 | 			} else { | 
            ||
| 135 | 				if ($emailLink) { | 
            ||
| 136 | 					$output->writeln('<error>Email address is not set for the user ' . $user->getUID() . '</error>'); | 
            ||
| 137 | return 1;  | 
            ||
| 138 | }  | 
            ||
| 139 | }  | 
            ||
| 140 | $this->config->setUserValue($userId, 'owncloud', 'lostpassword', $this->timeFactory->getTime() . ':' . $token);  | 
            ||
| 141 | 			$output->writeln('The password reset link is: ' . $link); | 
            ||
| 142 | return 0;  | 
            ||
| 143 | 		} elseif ($input->isInteractive()) { | 
            ||
| 144 | /** @var $dialog \Symfony\Component\Console\Helper\QuestionHelper */  | 
            ||
| 145 | 			$dialog = $this->getHelperSet()->get('question'); | 
            ||
| 146 | |||
| 147 | 			if (\OCP\App::isEnabled('encryption')) { | 
            ||
| 148 | $output->writeln(  | 
            ||
| 149 | '<error>Warning: Resetting the password when using encryption will result in data loss!</error>'  | 
            ||
| 150 | );  | 
            ||
| 151 | 				if (!$dialog->ask($input, $output, new Question('<question>Do you want to continue?</question>', true))) { | 
            ||
| 152 | return 1;  | 
            ||
| 153 | }  | 
            ||
| 154 | }  | 
            ||
| 155 | |||
| 156 | 			$q = new Question('<question>Enter a new password: </question>', false); | 
            ||
| 157 | $q->setHidden(true);  | 
            ||
| 158 | $password = $dialog->ask($input, $output, $q);  | 
            ||
| 159 | 			if ($password === false) { | 
            ||
| 160 | // When user presses RETURN key or no password characters are entered,  | 
            ||
| 161 | // $password gets a boolean value false.  | 
            ||
| 162 | 				$output->writeln("<error>Password cannot be empty!</error>"); | 
            ||
| 163 | return 1;  | 
            ||
| 164 | }  | 
            ||
| 165 | 			$q = new Question('<question>Confirm the new password: </question>', false); | 
            ||
| 166 | $q->setHidden(true);  | 
            ||
| 167 | $confirm = $dialog->ask($input, $output, $q);  | 
            ||
| 168 | 			if ($password !== $confirm) { | 
            ||
| 169 | 				$output->writeln("<error>Passwords did not match!</error>"); | 
            ||
| 170 | return 1;  | 
            ||
| 171 | }  | 
            ||
| 172 | 		} else { | 
            ||
| 173 | 			$output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>"); | 
            ||
| 174 | return 1;  | 
            ||
| 175 | }  | 
            ||
| 176 | |||
| 177 | $success = $user->setPassword($password);  | 
            ||
| 178 | 		if ($success) { | 
            ||
| 179 | 			$output->writeln("<info>Successfully reset password for " . $username . "</info>"); | 
            ||
| 180 | 		} else { | 
            ||
| 181 | 			$output->writeln("<error>Error while resetting password!</error>"); | 
            ||
| 182 | return 1;  | 
            ||
| 183 | }  | 
            ||
| 184 | }  | 
            ||
| 185 | }  | 
            ||
| 186 |