| Conditions | 18 |
| Paths | 992 |
| Total Lines | 77 |
| 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 |
||
| 76 | public function loadCommands( |
||
| 77 | InputInterface $input, |
||
| 78 | ConsoleOutputInterface $output |
||
| 79 | ) { |
||
| 80 | // $application is required to be defined in the register_command scripts |
||
| 81 | $application = $this->application; |
||
| 82 | $inputDefinition = $application->getDefinition(); |
||
| 83 | $inputDefinition->addOption( |
||
| 84 | new InputOption( |
||
| 85 | 'no-warnings', |
||
| 86 | null, |
||
| 87 | InputOption::VALUE_NONE, |
||
| 88 | 'Skip global warnings, show command output only', |
||
| 89 | null |
||
| 90 | ) |
||
| 91 | ); |
||
| 92 | try { |
||
| 93 | $input->bind($inputDefinition); |
||
| 94 | } catch (\RuntimeException $e) { |
||
| 95 | //expected if there are extra options |
||
| 96 | } |
||
| 97 | if ($input->getOption('no-warnings')) { |
||
| 98 | $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
||
| 99 | } |
||
| 100 | try { |
||
| 101 | require_once __DIR__ . '/../../../core/register_command.php'; |
||
| 102 | if ($this->config->getSystemValue('installed', false)) { |
||
| 103 | if (\OCP\Util::needUpgrade()) { |
||
| 104 | throw new NeedsUpdateException(); |
||
| 105 | } elseif ($this->config->getSystemValue('maintenance', false)) { |
||
| 106 | $this->writeMaintenanceModeInfo($input, $output); |
||
| 107 | } else { |
||
| 108 | OC_App::loadApps(); |
||
| 109 | foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) { |
||
| 110 | $appPath = \OC_App::getAppPath($app); |
||
| 111 | if ($appPath === false) { |
||
| 112 | continue; |
||
| 113 | } |
||
| 114 | // load commands using info.xml |
||
| 115 | $info = \OC_App::getAppInfo($app); |
||
| 116 | if (isset($info['commands'])) { |
||
| 117 | $this->loadCommandsFromInfoXml($info['commands']); |
||
| 118 | } |
||
| 119 | // load from register_command.php |
||
| 120 | \OC_App::registerAutoloading($app, $appPath); |
||
| 121 | $file = $appPath . '/appinfo/register_command.php'; |
||
| 122 | if (file_exists($file)) { |
||
| 123 | try { |
||
| 124 | require $file; |
||
| 125 | } catch (\Exception $e) { |
||
| 126 | $this->logger->logException($e); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | } |
||
| 130 | } |
||
| 131 | } else if ($input->getArgument('command') !== '_completion' && $input->getArgument('command') !== 'maintenance:install') { |
||
| 132 | $output->writeln("Nextcloud is not installed - only a limited number of commands are available"); |
||
| 133 | } |
||
| 134 | } catch(NeedsUpdateException $e) { |
||
| 135 | if ($input->getArgument('command') !== '_completion') { |
||
| 136 | $output->writeln("Nextcloud or one of the apps require upgrade - only a limited number of commands are available"); |
||
| 137 | $output->writeln("You may use your browser or the occ upgrade command to do the upgrade"); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | if ($input->getFirstArgument() !== 'check') { |
||
| 142 | $errors = \OC_Util::checkServer(\OC::$server->getSystemConfig()); |
||
| 143 | if (!empty($errors)) { |
||
| 144 | foreach ($errors as $error) { |
||
| 145 | $output->writeln((string)$error['error']); |
||
| 146 | $output->writeln((string)$error['hint']); |
||
| 147 | $output->writeln(''); |
||
| 148 | } |
||
| 149 | throw new \Exception("Environment not properly prepared."); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 215 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: