@@ -41,209 +41,209 @@ |
||
| 41 | 41 | |
| 42 | 42 | class CheckCode extends Command implements CompletionAwareInterface { |
| 43 | 43 | |
| 44 | - /** @var InfoParser */ |
|
| 45 | - private $infoParser; |
|
| 46 | - |
|
| 47 | - protected $checkers = [ |
|
| 48 | - 'private' => '\OC\App\CodeChecker\PrivateCheck', |
|
| 49 | - 'deprecation' => '\OC\App\CodeChecker\DeprecationCheck', |
|
| 50 | - 'strong-comparison' => '\OC\App\CodeChecker\StrongComparisonCheck', |
|
| 51 | - ]; |
|
| 52 | - |
|
| 53 | - public function __construct(InfoParser $infoParser) { |
|
| 54 | - parent::__construct(); |
|
| 55 | - $this->infoParser = $infoParser; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - protected function configure() { |
|
| 59 | - $this |
|
| 60 | - ->setName('app:check-code') |
|
| 61 | - ->setDescription('check code to be compliant') |
|
| 62 | - ->addArgument( |
|
| 63 | - 'app-id', |
|
| 64 | - InputArgument::REQUIRED, |
|
| 65 | - 'check the specified app' |
|
| 66 | - ) |
|
| 67 | - ->addOption( |
|
| 68 | - 'checker', |
|
| 69 | - 'c', |
|
| 70 | - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
| 71 | - 'enable the specified checker(s)', |
|
| 72 | - [ 'private', 'deprecation', 'strong-comparison' ] |
|
| 73 | - ) |
|
| 74 | - ->addOption( |
|
| 75 | - '--skip-validate-info', |
|
| 76 | - null, |
|
| 77 | - InputOption::VALUE_NONE, |
|
| 78 | - 'skips the info.xml/version check' |
|
| 79 | - ); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 83 | - $appId = $input->getArgument('app-id'); |
|
| 84 | - |
|
| 85 | - $checkList = new EmptyCheck(); |
|
| 86 | - foreach ($input->getOption('checker') as $checker) { |
|
| 87 | - if (!isset($this->checkers[$checker])) { |
|
| 88 | - throw new \InvalidArgumentException('Invalid checker: '.$checker); |
|
| 89 | - } |
|
| 90 | - $checkerClass = $this->checkers[$checker]; |
|
| 91 | - $checkList = new $checkerClass($checkList); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $codeChecker = new CodeChecker($checkList); |
|
| 95 | - |
|
| 96 | - $codeChecker->listen('CodeChecker', 'analyseFileBegin', function($params) use ($output) { |
|
| 97 | - if(OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
| 98 | - $output->writeln("<info>Analysing {$params}</info>"); |
|
| 99 | - } |
|
| 100 | - }); |
|
| 101 | - $codeChecker->listen('CodeChecker', 'analyseFileFinished', function($filename, $errors) use ($output) { |
|
| 102 | - $count = count($errors); |
|
| 103 | - |
|
| 104 | - // show filename if the verbosity is low, but there are errors in a file |
|
| 105 | - if($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
|
| 106 | - $output->writeln("<info>Analysing {$filename}</info>"); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // show error count if there are errors present or the verbosity is high |
|
| 110 | - if($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
| 111 | - $output->writeln(" {$count} errors"); |
|
| 112 | - } |
|
| 113 | - usort($errors, function($a, $b) { |
|
| 114 | - return $a['line'] >$b['line']; |
|
| 115 | - }); |
|
| 116 | - |
|
| 117 | - foreach($errors as $p) { |
|
| 118 | - $line = sprintf("%' 4d", $p['line']); |
|
| 119 | - $output->writeln(" <error>line $line: {$p['disallowedToken']} - {$p['reason']}</error>"); |
|
| 120 | - } |
|
| 121 | - }); |
|
| 122 | - $errors = $codeChecker->analyse($appId); |
|
| 123 | - |
|
| 124 | - if(!$input->getOption('skip-validate-info')) { |
|
| 125 | - $infoChecker = new InfoChecker($this->infoParser); |
|
| 126 | - |
|
| 127 | - $infoChecker->listen('InfoChecker', 'mandatoryFieldMissing', function($key) use ($output) { |
|
| 128 | - $output->writeln("<error>Mandatory field missing: $key</error>"); |
|
| 129 | - }); |
|
| 130 | - |
|
| 131 | - $infoChecker->listen('InfoChecker', 'deprecatedFieldFound', function($key, $value) use ($output) { |
|
| 132 | - if($value === [] || is_null($value) || $value === '') { |
|
| 133 | - $output->writeln("<info>Deprecated field available: $key</info>"); |
|
| 134 | - } else { |
|
| 135 | - $output->writeln("<info>Deprecated field available: $key => $value</info>"); |
|
| 136 | - } |
|
| 137 | - }); |
|
| 138 | - |
|
| 139 | - $infoChecker->listen('InfoChecker', 'missingRequirement', function($minMax) use ($output) { |
|
| 140 | - $output->writeln("<comment>Nextcloud $minMax version requirement missing (will be an error in Nextcloud 12 and later)</comment>"); |
|
| 141 | - }); |
|
| 142 | - |
|
| 143 | - $infoChecker->listen('InfoChecker', 'duplicateRequirement', function($minMax) use ($output) { |
|
| 144 | - $output->writeln("<error>Duplicate $minMax ownCloud version requirement found</error>"); |
|
| 145 | - }); |
|
| 146 | - |
|
| 147 | - $infoChecker->listen('InfoChecker', 'differentVersions', function($versionFile, $infoXML) use ($output) { |
|
| 148 | - $output->writeln("<error>Different versions provided (appinfo/version: $versionFile - appinfo/info.xml: $infoXML)</error>"); |
|
| 149 | - }); |
|
| 150 | - |
|
| 151 | - $infoChecker->listen('InfoChecker', 'sameVersions', function($path) use ($output) { |
|
| 152 | - $output->writeln("<info>Version file isn't needed anymore and can be safely removed ($path)</info>"); |
|
| 153 | - }); |
|
| 154 | - |
|
| 155 | - $infoChecker->listen('InfoChecker', 'migrateVersion', function($version) use ($output) { |
|
| 156 | - $output->writeln("<info>Migrate the app version to appinfo/info.xml (add <version>$version</version> to appinfo/info.xml and remove appinfo/version)</info>"); |
|
| 157 | - }); |
|
| 158 | - |
|
| 159 | - if(OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
| 160 | - $infoChecker->listen('InfoChecker', 'mandatoryFieldFound', function($key, $value) use ($output) { |
|
| 161 | - $output->writeln("<info>Mandatory field available: $key => $value</info>"); |
|
| 162 | - }); |
|
| 163 | - |
|
| 164 | - $infoChecker->listen('InfoChecker', 'optionalFieldFound', function($key, $value) use ($output) { |
|
| 165 | - $output->writeln("<info>Optional field available: $key => $value</info>"); |
|
| 166 | - }); |
|
| 167 | - |
|
| 168 | - $infoChecker->listen('InfoChecker', 'unusedFieldFound', function($key, $value) use ($output) { |
|
| 169 | - $output->writeln("<info>Unused field available: $key => $value</info>"); |
|
| 170 | - }); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - $infoErrors = $infoChecker->analyse($appId); |
|
| 174 | - |
|
| 175 | - $errors = array_merge($errors, $infoErrors); |
|
| 176 | - |
|
| 177 | - $languageParser = new LanguageParseChecker(); |
|
| 178 | - $languageErrors = $languageParser->analyse($appId); |
|
| 179 | - |
|
| 180 | - foreach ($languageErrors as $languageError) { |
|
| 181 | - $output->writeln("<error>$languageError</error>"); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - $errors = array_merge($errors, $languageErrors); |
|
| 185 | - |
|
| 186 | - $databaseSchema = new DatabaseSchemaChecker(); |
|
| 187 | - $schemaErrors = $databaseSchema->analyse($appId); |
|
| 188 | - |
|
| 189 | - foreach ($schemaErrors['errors'] as $schemaError) { |
|
| 190 | - $output->writeln("<error>$schemaError</error>"); |
|
| 191 | - } |
|
| 192 | - foreach ($schemaErrors['warnings'] as $schemaWarning) { |
|
| 193 | - $output->writeln("<comment>$schemaWarning</comment>"); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - $errors = array_merge($errors, $schemaErrors['errors']); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - $this->analyseUpdateFile($appId, $output); |
|
| 200 | - |
|
| 201 | - if (empty($errors)) { |
|
| 202 | - $output->writeln('<info>App is compliant - awesome job!</info>'); |
|
| 203 | - return 0; |
|
| 204 | - } else { |
|
| 205 | - $output->writeln('<error>App is not compliant</error>'); |
|
| 206 | - return 101; |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @param string $appId |
|
| 212 | - * @param $output |
|
| 213 | - */ |
|
| 214 | - private function analyseUpdateFile($appId, OutputInterface $output) { |
|
| 215 | - $appPath = \OC_App::getAppPath($appId); |
|
| 216 | - if ($appPath === false) { |
|
| 217 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - $updatePhp = $appPath . '/appinfo/update.php'; |
|
| 221 | - if (file_exists($updatePhp)) { |
|
| 222 | - $output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>"); |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @param string $optionName |
|
| 228 | - * @param CompletionContext $context |
|
| 229 | - * @return string[] |
|
| 230 | - */ |
|
| 231 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
| 232 | - if ($optionName === 'checker') { |
|
| 233 | - return ['private', 'deprecation', 'strong-comparison']; |
|
| 234 | - } |
|
| 235 | - return []; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @param string $argumentName |
|
| 240 | - * @param CompletionContext $context |
|
| 241 | - * @return string[] |
|
| 242 | - */ |
|
| 243 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 244 | - if ($argumentName === 'app-id') { |
|
| 245 | - return \OC_App::getAllApps(); |
|
| 246 | - } |
|
| 247 | - return []; |
|
| 248 | - } |
|
| 44 | + /** @var InfoParser */ |
|
| 45 | + private $infoParser; |
|
| 46 | + |
|
| 47 | + protected $checkers = [ |
|
| 48 | + 'private' => '\OC\App\CodeChecker\PrivateCheck', |
|
| 49 | + 'deprecation' => '\OC\App\CodeChecker\DeprecationCheck', |
|
| 50 | + 'strong-comparison' => '\OC\App\CodeChecker\StrongComparisonCheck', |
|
| 51 | + ]; |
|
| 52 | + |
|
| 53 | + public function __construct(InfoParser $infoParser) { |
|
| 54 | + parent::__construct(); |
|
| 55 | + $this->infoParser = $infoParser; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + protected function configure() { |
|
| 59 | + $this |
|
| 60 | + ->setName('app:check-code') |
|
| 61 | + ->setDescription('check code to be compliant') |
|
| 62 | + ->addArgument( |
|
| 63 | + 'app-id', |
|
| 64 | + InputArgument::REQUIRED, |
|
| 65 | + 'check the specified app' |
|
| 66 | + ) |
|
| 67 | + ->addOption( |
|
| 68 | + 'checker', |
|
| 69 | + 'c', |
|
| 70 | + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
| 71 | + 'enable the specified checker(s)', |
|
| 72 | + [ 'private', 'deprecation', 'strong-comparison' ] |
|
| 73 | + ) |
|
| 74 | + ->addOption( |
|
| 75 | + '--skip-validate-info', |
|
| 76 | + null, |
|
| 77 | + InputOption::VALUE_NONE, |
|
| 78 | + 'skips the info.xml/version check' |
|
| 79 | + ); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 83 | + $appId = $input->getArgument('app-id'); |
|
| 84 | + |
|
| 85 | + $checkList = new EmptyCheck(); |
|
| 86 | + foreach ($input->getOption('checker') as $checker) { |
|
| 87 | + if (!isset($this->checkers[$checker])) { |
|
| 88 | + throw new \InvalidArgumentException('Invalid checker: '.$checker); |
|
| 89 | + } |
|
| 90 | + $checkerClass = $this->checkers[$checker]; |
|
| 91 | + $checkList = new $checkerClass($checkList); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $codeChecker = new CodeChecker($checkList); |
|
| 95 | + |
|
| 96 | + $codeChecker->listen('CodeChecker', 'analyseFileBegin', function($params) use ($output) { |
|
| 97 | + if(OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
| 98 | + $output->writeln("<info>Analysing {$params}</info>"); |
|
| 99 | + } |
|
| 100 | + }); |
|
| 101 | + $codeChecker->listen('CodeChecker', 'analyseFileFinished', function($filename, $errors) use ($output) { |
|
| 102 | + $count = count($errors); |
|
| 103 | + |
|
| 104 | + // show filename if the verbosity is low, but there are errors in a file |
|
| 105 | + if($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
|
| 106 | + $output->writeln("<info>Analysing {$filename}</info>"); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // show error count if there are errors present or the verbosity is high |
|
| 110 | + if($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
| 111 | + $output->writeln(" {$count} errors"); |
|
| 112 | + } |
|
| 113 | + usort($errors, function($a, $b) { |
|
| 114 | + return $a['line'] >$b['line']; |
|
| 115 | + }); |
|
| 116 | + |
|
| 117 | + foreach($errors as $p) { |
|
| 118 | + $line = sprintf("%' 4d", $p['line']); |
|
| 119 | + $output->writeln(" <error>line $line: {$p['disallowedToken']} - {$p['reason']}</error>"); |
|
| 120 | + } |
|
| 121 | + }); |
|
| 122 | + $errors = $codeChecker->analyse($appId); |
|
| 123 | + |
|
| 124 | + if(!$input->getOption('skip-validate-info')) { |
|
| 125 | + $infoChecker = new InfoChecker($this->infoParser); |
|
| 126 | + |
|
| 127 | + $infoChecker->listen('InfoChecker', 'mandatoryFieldMissing', function($key) use ($output) { |
|
| 128 | + $output->writeln("<error>Mandatory field missing: $key</error>"); |
|
| 129 | + }); |
|
| 130 | + |
|
| 131 | + $infoChecker->listen('InfoChecker', 'deprecatedFieldFound', function($key, $value) use ($output) { |
|
| 132 | + if($value === [] || is_null($value) || $value === '') { |
|
| 133 | + $output->writeln("<info>Deprecated field available: $key</info>"); |
|
| 134 | + } else { |
|
| 135 | + $output->writeln("<info>Deprecated field available: $key => $value</info>"); |
|
| 136 | + } |
|
| 137 | + }); |
|
| 138 | + |
|
| 139 | + $infoChecker->listen('InfoChecker', 'missingRequirement', function($minMax) use ($output) { |
|
| 140 | + $output->writeln("<comment>Nextcloud $minMax version requirement missing (will be an error in Nextcloud 12 and later)</comment>"); |
|
| 141 | + }); |
|
| 142 | + |
|
| 143 | + $infoChecker->listen('InfoChecker', 'duplicateRequirement', function($minMax) use ($output) { |
|
| 144 | + $output->writeln("<error>Duplicate $minMax ownCloud version requirement found</error>"); |
|
| 145 | + }); |
|
| 146 | + |
|
| 147 | + $infoChecker->listen('InfoChecker', 'differentVersions', function($versionFile, $infoXML) use ($output) { |
|
| 148 | + $output->writeln("<error>Different versions provided (appinfo/version: $versionFile - appinfo/info.xml: $infoXML)</error>"); |
|
| 149 | + }); |
|
| 150 | + |
|
| 151 | + $infoChecker->listen('InfoChecker', 'sameVersions', function($path) use ($output) { |
|
| 152 | + $output->writeln("<info>Version file isn't needed anymore and can be safely removed ($path)</info>"); |
|
| 153 | + }); |
|
| 154 | + |
|
| 155 | + $infoChecker->listen('InfoChecker', 'migrateVersion', function($version) use ($output) { |
|
| 156 | + $output->writeln("<info>Migrate the app version to appinfo/info.xml (add <version>$version</version> to appinfo/info.xml and remove appinfo/version)</info>"); |
|
| 157 | + }); |
|
| 158 | + |
|
| 159 | + if(OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
| 160 | + $infoChecker->listen('InfoChecker', 'mandatoryFieldFound', function($key, $value) use ($output) { |
|
| 161 | + $output->writeln("<info>Mandatory field available: $key => $value</info>"); |
|
| 162 | + }); |
|
| 163 | + |
|
| 164 | + $infoChecker->listen('InfoChecker', 'optionalFieldFound', function($key, $value) use ($output) { |
|
| 165 | + $output->writeln("<info>Optional field available: $key => $value</info>"); |
|
| 166 | + }); |
|
| 167 | + |
|
| 168 | + $infoChecker->listen('InfoChecker', 'unusedFieldFound', function($key, $value) use ($output) { |
|
| 169 | + $output->writeln("<info>Unused field available: $key => $value</info>"); |
|
| 170 | + }); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + $infoErrors = $infoChecker->analyse($appId); |
|
| 174 | + |
|
| 175 | + $errors = array_merge($errors, $infoErrors); |
|
| 176 | + |
|
| 177 | + $languageParser = new LanguageParseChecker(); |
|
| 178 | + $languageErrors = $languageParser->analyse($appId); |
|
| 179 | + |
|
| 180 | + foreach ($languageErrors as $languageError) { |
|
| 181 | + $output->writeln("<error>$languageError</error>"); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + $errors = array_merge($errors, $languageErrors); |
|
| 185 | + |
|
| 186 | + $databaseSchema = new DatabaseSchemaChecker(); |
|
| 187 | + $schemaErrors = $databaseSchema->analyse($appId); |
|
| 188 | + |
|
| 189 | + foreach ($schemaErrors['errors'] as $schemaError) { |
|
| 190 | + $output->writeln("<error>$schemaError</error>"); |
|
| 191 | + } |
|
| 192 | + foreach ($schemaErrors['warnings'] as $schemaWarning) { |
|
| 193 | + $output->writeln("<comment>$schemaWarning</comment>"); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + $errors = array_merge($errors, $schemaErrors['errors']); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + $this->analyseUpdateFile($appId, $output); |
|
| 200 | + |
|
| 201 | + if (empty($errors)) { |
|
| 202 | + $output->writeln('<info>App is compliant - awesome job!</info>'); |
|
| 203 | + return 0; |
|
| 204 | + } else { |
|
| 205 | + $output->writeln('<error>App is not compliant</error>'); |
|
| 206 | + return 101; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @param string $appId |
|
| 212 | + * @param $output |
|
| 213 | + */ |
|
| 214 | + private function analyseUpdateFile($appId, OutputInterface $output) { |
|
| 215 | + $appPath = \OC_App::getAppPath($appId); |
|
| 216 | + if ($appPath === false) { |
|
| 217 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + $updatePhp = $appPath . '/appinfo/update.php'; |
|
| 221 | + if (file_exists($updatePhp)) { |
|
| 222 | + $output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>"); |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @param string $optionName |
|
| 228 | + * @param CompletionContext $context |
|
| 229 | + * @return string[] |
|
| 230 | + */ |
|
| 231 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
| 232 | + if ($optionName === 'checker') { |
|
| 233 | + return ['private', 'deprecation', 'strong-comparison']; |
|
| 234 | + } |
|
| 235 | + return []; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @param string $argumentName |
|
| 240 | + * @param CompletionContext $context |
|
| 241 | + * @return string[] |
|
| 242 | + */ |
|
| 243 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 244 | + if ($argumentName === 'app-id') { |
|
| 245 | + return \OC_App::getAllApps(); |
|
| 246 | + } |
|
| 247 | + return []; |
|
| 248 | + } |
|
| 249 | 249 | } |
@@ -25,36 +25,36 @@ |
||
| 25 | 25 | |
| 26 | 26 | class LanguageParseChecker { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param string $appId |
|
| 30 | - * @return array |
|
| 31 | - */ |
|
| 32 | - public function analyse($appId) { |
|
| 33 | - $appPath = \OC_App::getAppPath($appId); |
|
| 34 | - if ($appPath === false) { |
|
| 35 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - if (!is_dir($appPath . '/l10n/')) { |
|
| 39 | - return []; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - $errors = []; |
|
| 43 | - $directory = new \DirectoryIterator($appPath . '/l10n/'); |
|
| 44 | - |
|
| 45 | - foreach ($directory as $file) { |
|
| 46 | - if ($file->getExtension() !== 'json') { |
|
| 47 | - continue; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - $content = file_get_contents($file->getPathname()); |
|
| 51 | - json_decode($content, true); |
|
| 52 | - |
|
| 53 | - if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 54 | - $errors[] = 'Invalid language file found: l10n/' . $file->getFilename() . ': ' . json_last_error_msg(); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - return $errors; |
|
| 59 | - } |
|
| 28 | + /** |
|
| 29 | + * @param string $appId |
|
| 30 | + * @return array |
|
| 31 | + */ |
|
| 32 | + public function analyse($appId) { |
|
| 33 | + $appPath = \OC_App::getAppPath($appId); |
|
| 34 | + if ($appPath === false) { |
|
| 35 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + if (!is_dir($appPath . '/l10n/')) { |
|
| 39 | + return []; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + $errors = []; |
|
| 43 | + $directory = new \DirectoryIterator($appPath . '/l10n/'); |
|
| 44 | + |
|
| 45 | + foreach ($directory as $file) { |
|
| 46 | + if ($file->getExtension() !== 'json') { |
|
| 47 | + continue; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + $content = file_get_contents($file->getPathname()); |
|
| 51 | + json_decode($content, true); |
|
| 52 | + |
|
| 53 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 54 | + $errors[] = 'Invalid language file found: l10n/' . $file->getFilename() . ': ' . json_last_error_msg(); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + return $errors; |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | throw new \RuntimeException("No app with given id <$appId> known."); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - if (!is_dir($appPath . '/l10n/')) { |
|
| 38 | + if (!is_dir($appPath.'/l10n/')) { |
|
| 39 | 39 | return []; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $errors = []; |
| 43 | - $directory = new \DirectoryIterator($appPath . '/l10n/'); |
|
| 43 | + $directory = new \DirectoryIterator($appPath.'/l10n/'); |
|
| 44 | 44 | |
| 45 | 45 | foreach ($directory as $file) { |
| 46 | 46 | if ($file->getExtension() !== 'json') { |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | json_decode($content, true); |
| 52 | 52 | |
| 53 | 53 | if (json_last_error() !== JSON_ERROR_NONE) { |
| 54 | - $errors[] = 'Invalid language file found: l10n/' . $file->getFilename() . ': ' . json_last_error_msg(); |
|
| 54 | + $errors[] = 'Invalid language file found: l10n/'.$file->getFilename().': '.json_last_error_msg(); |
|
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
@@ -25,81 +25,81 @@ |
||
| 25 | 25 | |
| 26 | 26 | class DatabaseSchemaChecker { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param string $appId |
|
| 30 | - * @return array |
|
| 31 | - */ |
|
| 32 | - public function analyse($appId) { |
|
| 33 | - $appPath = \OC_App::getAppPath($appId); |
|
| 34 | - if ($appPath === false) { |
|
| 35 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - if (!file_exists($appPath . '/appinfo/database.xml')) { |
|
| 39 | - return ['errors' => [], 'warnings' => []]; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - libxml_use_internal_errors(true); |
|
| 43 | - $loadEntities = libxml_disable_entity_loader(false); |
|
| 44 | - $xml = simplexml_load_file($appPath . '/appinfo/database.xml'); |
|
| 45 | - libxml_disable_entity_loader($loadEntities); |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - $errors = $warnings = []; |
|
| 49 | - |
|
| 50 | - foreach ($xml->table as $table) { |
|
| 51 | - // Table names |
|
| 52 | - if (strpos($table->name, '*dbprefix*') !== 0) { |
|
| 53 | - $errors[] = 'Database schema error: name of table ' . $table->name . ' does not start with *dbprefix*'; |
|
| 54 | - } |
|
| 55 | - $tableName = substr($table->name, strlen('*dbprefix*')); |
|
| 56 | - if (strpos($tableName, '*dbprefix*') !== false) { |
|
| 57 | - $warnings[] = 'Database schema warning: *dbprefix* should only appear once in name of table ' . $table->name; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if (strlen($tableName) > 27) { |
|
| 61 | - $errors[] = 'Database schema error: Name of table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - $hasAutoIncrement = false; |
|
| 65 | - |
|
| 66 | - // Column names |
|
| 67 | - foreach ($table->declaration->field as $column) { |
|
| 68 | - if (strpos($column->name, '*dbprefix*') !== false) { |
|
| 69 | - $warnings[] = 'Database schema warning: *dbprefix* should not appear in name of column ' . $column->name . ' on table ' . $table->name; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - if (strlen($column->name) > 30) { |
|
| 73 | - $errors[] = 'Database schema error: Name of column ' . $column->name . ' on table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 30 characters allowed'; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if ($column->autoincrement) { |
|
| 77 | - if ($hasAutoIncrement) { |
|
| 78 | - $errors[] = 'Database schema error: Table ' . $table->name . ' has multiple autoincrement columns'; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if (strlen($tableName) > 21) { |
|
| 82 | - $errors[] = 'Database schema error: Name of table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - $hasAutoIncrement = true; |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - // Index names |
|
| 90 | - foreach ($table->declaration->index as $index) { |
|
| 91 | - $hasPrefix = strpos($index->name, '*dbprefix*'); |
|
| 92 | - if ($hasPrefix !== false && $hasPrefix !== 0) { |
|
| 93 | - $warnings[] = 'Database schema warning: *dbprefix* should only appear at the beginning in name of index ' . $index->name . ' on table ' . $table->name; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $indexName = $hasPrefix === 0 ? substr($index->name, strlen('*dbprefix*')) : $index->name; |
|
| 97 | - if (strlen($indexName) > 27) { |
|
| 98 | - $errors[] = 'Database schema error: Name of index ' . $index->name . ' on table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters + *dbprefix* allowed'; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - return ['errors' => $errors, 'warnings' => $warnings]; |
|
| 104 | - } |
|
| 28 | + /** |
|
| 29 | + * @param string $appId |
|
| 30 | + * @return array |
|
| 31 | + */ |
|
| 32 | + public function analyse($appId) { |
|
| 33 | + $appPath = \OC_App::getAppPath($appId); |
|
| 34 | + if ($appPath === false) { |
|
| 35 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + if (!file_exists($appPath . '/appinfo/database.xml')) { |
|
| 39 | + return ['errors' => [], 'warnings' => []]; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + libxml_use_internal_errors(true); |
|
| 43 | + $loadEntities = libxml_disable_entity_loader(false); |
|
| 44 | + $xml = simplexml_load_file($appPath . '/appinfo/database.xml'); |
|
| 45 | + libxml_disable_entity_loader($loadEntities); |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + $errors = $warnings = []; |
|
| 49 | + |
|
| 50 | + foreach ($xml->table as $table) { |
|
| 51 | + // Table names |
|
| 52 | + if (strpos($table->name, '*dbprefix*') !== 0) { |
|
| 53 | + $errors[] = 'Database schema error: name of table ' . $table->name . ' does not start with *dbprefix*'; |
|
| 54 | + } |
|
| 55 | + $tableName = substr($table->name, strlen('*dbprefix*')); |
|
| 56 | + if (strpos($tableName, '*dbprefix*') !== false) { |
|
| 57 | + $warnings[] = 'Database schema warning: *dbprefix* should only appear once in name of table ' . $table->name; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if (strlen($tableName) > 27) { |
|
| 61 | + $errors[] = 'Database schema error: Name of table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + $hasAutoIncrement = false; |
|
| 65 | + |
|
| 66 | + // Column names |
|
| 67 | + foreach ($table->declaration->field as $column) { |
|
| 68 | + if (strpos($column->name, '*dbprefix*') !== false) { |
|
| 69 | + $warnings[] = 'Database schema warning: *dbprefix* should not appear in name of column ' . $column->name . ' on table ' . $table->name; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + if (strlen($column->name) > 30) { |
|
| 73 | + $errors[] = 'Database schema error: Name of column ' . $column->name . ' on table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 30 characters allowed'; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if ($column->autoincrement) { |
|
| 77 | + if ($hasAutoIncrement) { |
|
| 78 | + $errors[] = 'Database schema error: Table ' . $table->name . ' has multiple autoincrement columns'; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if (strlen($tableName) > 21) { |
|
| 82 | + $errors[] = 'Database schema error: Name of table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + $hasAutoIncrement = true; |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + // Index names |
|
| 90 | + foreach ($table->declaration->index as $index) { |
|
| 91 | + $hasPrefix = strpos($index->name, '*dbprefix*'); |
|
| 92 | + if ($hasPrefix !== false && $hasPrefix !== 0) { |
|
| 93 | + $warnings[] = 'Database schema warning: *dbprefix* should only appear at the beginning in name of index ' . $index->name . ' on table ' . $table->name; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $indexName = $hasPrefix === 0 ? substr($index->name, strlen('*dbprefix*')) : $index->name; |
|
| 97 | + if (strlen($indexName) > 27) { |
|
| 98 | + $errors[] = 'Database schema error: Name of index ' . $index->name . ' on table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters + *dbprefix* allowed'; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + return ['errors' => $errors, 'warnings' => $warnings]; |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -35,13 +35,13 @@ discard block |
||
| 35 | 35 | throw new \RuntimeException("No app with given id <$appId> known."); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - if (!file_exists($appPath . '/appinfo/database.xml')) { |
|
| 38 | + if (!file_exists($appPath.'/appinfo/database.xml')) { |
|
| 39 | 39 | return ['errors' => [], 'warnings' => []]; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | libxml_use_internal_errors(true); |
| 43 | 43 | $loadEntities = libxml_disable_entity_loader(false); |
| 44 | - $xml = simplexml_load_file($appPath . '/appinfo/database.xml'); |
|
| 44 | + $xml = simplexml_load_file($appPath.'/appinfo/database.xml'); |
|
| 45 | 45 | libxml_disable_entity_loader($loadEntities); |
| 46 | 46 | |
| 47 | 47 | |
@@ -50,15 +50,15 @@ discard block |
||
| 50 | 50 | foreach ($xml->table as $table) { |
| 51 | 51 | // Table names |
| 52 | 52 | if (strpos($table->name, '*dbprefix*') !== 0) { |
| 53 | - $errors[] = 'Database schema error: name of table ' . $table->name . ' does not start with *dbprefix*'; |
|
| 53 | + $errors[] = 'Database schema error: name of table '.$table->name.' does not start with *dbprefix*'; |
|
| 54 | 54 | } |
| 55 | 55 | $tableName = substr($table->name, strlen('*dbprefix*')); |
| 56 | 56 | if (strpos($tableName, '*dbprefix*') !== false) { |
| 57 | - $warnings[] = 'Database schema warning: *dbprefix* should only appear once in name of table ' . $table->name; |
|
| 57 | + $warnings[] = 'Database schema warning: *dbprefix* should only appear once in name of table '.$table->name; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | if (strlen($tableName) > 27) { |
| 61 | - $errors[] = 'Database schema error: Name of table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 61 | + $errors[] = 'Database schema error: Name of table '.$table->name.' is too long ('.strlen($tableName).'), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | $hasAutoIncrement = false; |
@@ -66,20 +66,20 @@ discard block |
||
| 66 | 66 | // Column names |
| 67 | 67 | foreach ($table->declaration->field as $column) { |
| 68 | 68 | if (strpos($column->name, '*dbprefix*') !== false) { |
| 69 | - $warnings[] = 'Database schema warning: *dbprefix* should not appear in name of column ' . $column->name . ' on table ' . $table->name; |
|
| 69 | + $warnings[] = 'Database schema warning: *dbprefix* should not appear in name of column '.$column->name.' on table '.$table->name; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | if (strlen($column->name) > 30) { |
| 73 | - $errors[] = 'Database schema error: Name of column ' . $column->name . ' on table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 30 characters allowed'; |
|
| 73 | + $errors[] = 'Database schema error: Name of column '.$column->name.' on table '.$table->name.' is too long ('.strlen($tableName).'), max. 30 characters allowed'; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | if ($column->autoincrement) { |
| 77 | 77 | if ($hasAutoIncrement) { |
| 78 | - $errors[] = 'Database schema error: Table ' . $table->name . ' has multiple autoincrement columns'; |
|
| 78 | + $errors[] = 'Database schema error: Table '.$table->name.' has multiple autoincrement columns'; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | if (strlen($tableName) > 21) { |
| 82 | - $errors[] = 'Database schema error: Name of table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 82 | + $errors[] = 'Database schema error: Name of table '.$table->name.' is too long ('.strlen($tableName).'), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | $hasAutoIncrement = true; |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | foreach ($table->declaration->index as $index) { |
| 91 | 91 | $hasPrefix = strpos($index->name, '*dbprefix*'); |
| 92 | 92 | if ($hasPrefix !== false && $hasPrefix !== 0) { |
| 93 | - $warnings[] = 'Database schema warning: *dbprefix* should only appear at the beginning in name of index ' . $index->name . ' on table ' . $table->name; |
|
| 93 | + $warnings[] = 'Database schema warning: *dbprefix* should only appear at the beginning in name of index '.$index->name.' on table '.$table->name; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $indexName = $hasPrefix === 0 ? substr($index->name, strlen('*dbprefix*')) : $index->name; |
| 97 | 97 | if (strlen($indexName) > 27) { |
| 98 | - $errors[] = 'Database schema error: Name of index ' . $index->name . ' on table ' . $table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters + *dbprefix* allowed'; |
|
| 98 | + $errors[] = 'Database schema error: Name of index '.$index->name.' on table '.$table->name.' is too long ('.strlen($tableName).'), max. 27 characters + *dbprefix* allowed'; |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | } |