Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $appId = $input->getArgument('app-id');
     $codeChecker = new \OC\App\CodeChecker();
     $codeChecker->listen('CodeChecker', 'analyseFileBegin', function ($params) use($output) {
         if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
             $output->writeln("<info>Analysing {$params}</info>");
         }
     });
     $codeChecker->listen('CodeChecker', 'analyseFileFinished', function ($filename, $errors) use($output) {
         $count = count($errors);
         // show filename if the verbosity is low, but there are errors in a file
         if ($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) {
             $output->writeln("<info>Analysing {$filename}</info>");
         }
         // show error count if there are errros present or the verbosity is high
         if ($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
             $output->writeln(" {$count} errors");
         }
         usort($errors, function ($a, $b) {
             return $a['line'] > $b['line'];
         });
         foreach ($errors as $p) {
             $line = sprintf("%' 4d", $p['line']);
             $output->writeln("    <error>line {$line}: {$p['disallowedToken']} - {$p['reason']}</error>");
         }
     });
     $errors = $codeChecker->analyse($appId);
     if (empty($errors)) {
         $output->writeln('<info>App is compliant - awesome job!</info>');
     } else {
         $output->writeln('<error>App is not compliant</error>');
         return 1;
     }
 }
Exemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $appId = $input->getArgument('app-id');
     $codeChecker = new \OC\App\CodeChecker();
     $codeChecker->listen('CodeChecker', 'analyseFileBegin', function ($params) use($output) {
         $output->writeln("<info>Analysing {$params}</info>");
     });
     $codeChecker->listen('CodeChecker', 'analyseFileFinished', function ($params) use($output) {
         $count = count($params);
         $output->writeln(" {$count} errors");
         usort($params, function ($a, $b) {
             return $a['line'] > $b['line'];
         });
         foreach ($params as $p) {
             $line = sprintf("%' 4d", $p['line']);
             $output->writeln("    <error>line {$line}: {$p['disallowedToken']} - {$p['reason']}</error>");
         }
     });
     $errors = $codeChecker->analyse($appId);
     if (empty($errors)) {
         $output->writeln('<info>App is compliant - awesome job!</info>');
     } else {
         $output->writeln('<error>App is not compliant</error>');
     }
 }
Exemplo n.º 3
0
 /**
  * check the code of an app with some static code checks
  * @param string $folder the folder of the app to check
  * @return boolean true for app is o.k. and false for app is not o.k.
  */
 public static function checkCode($folder)
 {
     // is the code checker enabled?
     if (!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) {
         return true;
     }
     $codeChecker = new \OC\App\CodeChecker();
     $errors = $codeChecker->analyseFolder($folder);
     return empty($errors);
 }