From 0de5c35dbad2cd2023cff08c0b142aedb16c4ea9 Mon Sep 17 00:00:00 2001
From: Robin McCorkell <rmccorkell@karoshi.org.uk>
Date: Fri, 10 Jul 2015 22:17:55 +0100
Subject: [PATCH] Allow specifying the checkers used in app:check-code

By default, all are enabled, but specific ones can be selected through command
line options.
---
 core/command/app/checkcode.php | 36 ++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/core/command/app/checkcode.php b/core/command/app/checkcode.php
index 3f4fb95868..79c34d6fb4 100644
--- a/core/command/app/checkcode.php
+++ b/core/command/app/checkcode.php
@@ -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;
-- 
GitLab