| Conditions | 19 |
| Paths | 25 |
| Total Lines | 130 |
| Code Lines | 73 |
| 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 |
||
| 88 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
| 89 | $appId = $input->getArgument('app-id'); |
||
| 90 | |||
| 91 | $checkList = new EmptyCheck(); |
||
| 92 | foreach ($input->getOption('checker') as $checker) { |
||
| 93 | if (!isset($this->checkers[$checker])) { |
||
| 94 | throw new \InvalidArgumentException('Invalid checker: '.$checker); |
||
| 95 | } |
||
| 96 | $checkerClass = $this->checkers[$checker]; |
||
| 97 | $checkList = new $checkerClass($checkList); |
||
| 98 | } |
||
| 99 | |||
| 100 | $codeChecker = new CodeChecker($checkList); |
||
| 101 | |||
| 102 | $codeChecker->listen('CodeChecker', 'analyseFileBegin', function($params) use ($output) { |
||
| 103 | if(OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
||
| 104 | $output->writeln("<info>Analysing {$params}</info>"); |
||
| 105 | } |
||
| 106 | }); |
||
| 107 | $codeChecker->listen('CodeChecker', 'analyseFileFinished', function($filename, $errors) use ($output) { |
||
| 108 | $count = count($errors); |
||
| 109 | |||
| 110 | // show filename if the verbosity is low, but there are errors in a file |
||
| 111 | if($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
||
| 112 | $output->writeln("<info>Analysing {$filename}</info>"); |
||
| 113 | } |
||
| 114 | |||
| 115 | // show error count if there are errors present or the verbosity is high |
||
| 116 | if($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
||
| 117 | $output->writeln(" {$count} errors"); |
||
| 118 | } |
||
| 119 | usort($errors, function($a, $b) { |
||
| 120 | return $a['line'] >$b['line']; |
||
| 121 | }); |
||
| 122 | |||
| 123 | foreach($errors as $p) { |
||
| 124 | $line = sprintf("%' 4d", $p['line']); |
||
| 125 | $output->writeln(" <error>line $line: {$p['disallowedToken']} - {$p['reason']}</error>"); |
||
| 126 | } |
||
| 127 | }); |
||
| 128 | $errors = []; |
||
| 129 | if(!$input->getOption('skip-checkers')) { |
||
| 130 | $errors = $codeChecker->analyse($appId); |
||
| 131 | } |
||
| 132 | |||
| 133 | if(!$input->getOption('skip-validate-info')) { |
||
| 134 | $infoChecker = new InfoChecker($this->infoParser); |
||
| 135 | |||
| 136 | $infoChecker->listen('InfoChecker', 'mandatoryFieldMissing', function($key) use ($output) { |
||
| 137 | $output->writeln("<error>Mandatory field missing: $key</error>"); |
||
| 138 | }); |
||
| 139 | |||
| 140 | $infoChecker->listen('InfoChecker', 'deprecatedFieldFound', function($key, $value) use ($output) { |
||
| 141 | if($value === [] || is_null($value) || $value === '') { |
||
| 142 | $output->writeln("<info>Deprecated field available: $key</info>"); |
||
| 143 | } else { |
||
| 144 | $output->writeln("<info>Deprecated field available: $key => $value</info>"); |
||
| 145 | } |
||
| 146 | }); |
||
| 147 | |||
| 148 | $infoChecker->listen('InfoChecker', 'missingRequirement', function($minMax) use ($output) { |
||
| 149 | $output->writeln("<comment>Nextcloud $minMax version requirement missing (will be an error in Nextcloud 12 and later)</comment>"); |
||
| 150 | }); |
||
| 151 | |||
| 152 | $infoChecker->listen('InfoChecker', 'duplicateRequirement', function($minMax) use ($output) { |
||
| 153 | $output->writeln("<error>Duplicate $minMax ownCloud version requirement found</error>"); |
||
| 154 | }); |
||
| 155 | |||
| 156 | $infoChecker->listen('InfoChecker', 'differentVersions', function($versionFile, $infoXML) use ($output) { |
||
| 157 | $output->writeln("<error>Different versions provided (appinfo/version: $versionFile - appinfo/info.xml: $infoXML)</error>"); |
||
| 158 | }); |
||
| 159 | |||
| 160 | $infoChecker->listen('InfoChecker', 'sameVersions', function($path) use ($output) { |
||
| 161 | $output->writeln("<info>Version file isn't needed anymore and can be safely removed ($path)</info>"); |
||
| 162 | }); |
||
| 163 | |||
| 164 | $infoChecker->listen('InfoChecker', 'migrateVersion', function($version) use ($output) { |
||
| 165 | $output->writeln("<info>Migrate the app version to appinfo/info.xml (add <version>$version</version> to appinfo/info.xml and remove appinfo/version)</info>"); |
||
| 166 | }); |
||
| 167 | |||
| 168 | if(OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
||
| 169 | $infoChecker->listen('InfoChecker', 'mandatoryFieldFound', function($key, $value) use ($output) { |
||
| 170 | $output->writeln("<info>Mandatory field available: $key => $value</info>"); |
||
| 171 | }); |
||
| 172 | |||
| 173 | $infoChecker->listen('InfoChecker', 'optionalFieldFound', function($key, $value) use ($output) { |
||
| 174 | $output->writeln("<info>Optional field available: $key => $value</info>"); |
||
| 175 | }); |
||
| 176 | |||
| 177 | $infoChecker->listen('InfoChecker', 'unusedFieldFound', function($key, $value) use ($output) { |
||
| 178 | $output->writeln("<info>Unused field available: $key => $value</info>"); |
||
| 179 | }); |
||
| 180 | } |
||
| 181 | |||
| 182 | $infoErrors = $infoChecker->analyse($appId); |
||
| 183 | |||
| 184 | $errors = array_merge($errors, $infoErrors); |
||
| 185 | |||
| 186 | $languageParser = new LanguageParseChecker(); |
||
| 187 | $languageErrors = $languageParser->analyse($appId); |
||
| 188 | |||
| 189 | foreach ($languageErrors as $languageError) { |
||
| 190 | $output->writeln("<error>$languageError</error>"); |
||
| 191 | } |
||
| 192 | |||
| 193 | $errors = array_merge($errors, $languageErrors); |
||
| 194 | |||
| 195 | $databaseSchema = new DatabaseSchemaChecker(); |
||
| 196 | $schemaErrors = $databaseSchema->analyse($appId); |
||
| 197 | |||
| 198 | foreach ($schemaErrors['errors'] as $schemaError) { |
||
| 199 | $output->writeln("<error>$schemaError</error>"); |
||
| 200 | } |
||
| 201 | foreach ($schemaErrors['warnings'] as $schemaWarning) { |
||
| 202 | $output->writeln("<comment>$schemaWarning</comment>"); |
||
| 203 | } |
||
| 204 | |||
| 205 | $errors = array_merge($errors, $schemaErrors['errors']); |
||
| 206 | } |
||
| 207 | |||
| 208 | $this->analyseUpdateFile($appId, $output); |
||
| 209 | |||
| 210 | if (empty($errors)) { |
||
| 211 | $output->writeln('<info>App is compliant - awesome job!</info>'); |
||
| 212 | return 0; |
||
| 213 | } else { |
||
| 214 | $output->writeln('<error>App is not compliant</error>'); |
||
| 215 | return 101; |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 259 |