Allow specifying the checkers used in app:check-code
By default, all are enabled, but specific ones can be selected through command line options.
This commit is contained in:
parent
a0c6f2e5e0
commit
0de5c35dba
1 changed files with 21 additions and 15 deletions
|
@ -3,6 +3,7 @@
|
|||
* @author Joas Schilling <nickvergessen@owncloud.com>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||
* @author Robin McCorkell <rmccorkell@karoshi.org.uk>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
|
@ -24,10 +25,7 @@
|
|||
namespace OC\Core\Command\App;
|
||||
|
||||
use OC\App\CodeChecker\CodeChecker;
|
||||
use OC\App\CodeChecker\DeprecationCheck;
|
||||
use OC\App\CodeChecker\EmptyCheck;
|
||||
use OC\App\CodeChecker\PrivateCheck;
|
||||
use OC\App\CodeChecker\StrongComparisonCheck;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
@ -35,6 +33,12 @@ use Symfony\Component\Console\Input\InputOption;
|
|||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class CheckCode extends Command {
|
||||
protected $checkers = [
|
||||
'private' => '\OC\App\CodeChecker\PrivateCheck',
|
||||
'deprecation' => '\OC\App\CodeChecker\DeprecationCheck',
|
||||
'strong-comparison' => '\OC\App\CodeChecker\StrongComparisonCheck',
|
||||
];
|
||||
|
||||
protected function configure() {
|
||||
$this
|
||||
->setName('app:check-code')
|
||||
|
@ -45,22 +49,26 @@ class CheckCode extends Command {
|
|||
'check the specified app'
|
||||
)
|
||||
->addOption(
|
||||
'deprecated',
|
||||
'd',
|
||||
InputOption::VALUE_NONE,
|
||||
'check the specified app'
|
||||
'checker',
|
||||
'c',
|
||||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
|
||||
'enable the specified checker',
|
||||
[ 'private', 'deprecation', 'strong-comparison' ]
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output) {
|
||||
$appId = $input->getArgument('app-id');
|
||||
|
||||
$checkList = new EmptyCheck();
|
||||
if ($input->getOption('deprecated')) {
|
||||
$checkList = new DeprecationCheck($checkList);
|
||||
$checkList = new StrongComparisonCheck($checkList);
|
||||
} else {
|
||||
$checkList = new PrivateCheck($checkList);
|
||||
foreach ($input->getOption('checker') as $checker) {
|
||||
if (!isset($this->checkers[$checker])) {
|
||||
throw new \InvalidArgumentException('Invalid checker: '.$checker);
|
||||
}
|
||||
$checkerClass = $this->checkers[$checker];
|
||||
$checkList = new $checkerClass($checkList);
|
||||
}
|
||||
|
||||
$codeChecker = new CodeChecker($checkList);
|
||||
|
||||
$codeChecker->listen('CodeChecker', 'analyseFileBegin', function($params) use ($output) {
|
||||
|
@ -92,9 +100,7 @@ class CheckCode extends Command {
|
|||
$errors = $codeChecker->analyse($appId);
|
||||
if (empty($errors)) {
|
||||
$output->writeln('<info>App is compliant - awesome job!</info>');
|
||||
} elseif ($input->getOption('deprecated')) {
|
||||
$output->writeln('<comment>App uses deprecated functionality</comment>');
|
||||
return 102;
|
||||
return 0;
|
||||
} else {
|
||||
$output->writeln('<error>App is not compliant</error>');
|
||||
return 101;
|
||||
|
|
Loading…
Reference in a new issue