diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-07-07 12:08:12 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-07-17 12:34:56 +0200 |
commit | bba87a2a3b46d20a552efa4a1d00d3253aedf27b (patch) | |
tree | b243d9e54018e114123b53021d0d93c327fbefcc | |
parent | 9e469046faee66171be15fa6d0bb6eef2289fa0f (diff) | |
download | nextcloud-server-bba87a2a3b46d20a552efa4a1d00d3253aedf27b.tar.gz nextcloud-server-bba87a2a3b46d20a552efa4a1d00d3253aedf27b.zip |
Restructor the code into different classes instead of extending
-rw-r--r-- | core/command/app/checkcode.php | 11 | ||||
-rw-r--r-- | lib/private/app/codechecker/codechecker.php (renamed from lib/private/app/codechecker.php) | 51 | ||||
-rw-r--r-- | lib/private/app/codechecker/deprecationlist.php | 152 | ||||
-rw-r--r-- | lib/private/app/codechecker/ichecklist.php (renamed from tests/lib/app/mock/codechecker.php) | 48 | ||||
-rw-r--r-- | lib/private/app/codechecker/nodevisitor.php (renamed from lib/private/app/codecheckvisitor.php) | 25 | ||||
-rw-r--r-- | lib/private/app/codechecker/privatelist.php | 105 | ||||
-rw-r--r-- | lib/private/app/deprecationcodechecker.php | 127 | ||||
-rw-r--r-- | tests/lib/app/codechecker/codecheckertest.php (renamed from tests/lib/app/codechecker.php) | 12 | ||||
-rw-r--r-- | tests/lib/app/codechecker/deprecationlisttest.php (renamed from tests/lib/app/deprecationcodechecker.php) | 10 | ||||
-rw-r--r-- | tests/lib/app/codechecker/mock/testlist.php | 81 | ||||
-rw-r--r-- | tests/lib/app/codechecker/nodevisitortest.php (renamed from tests/lib/app/codecheckvisitor.php) | 8 |
11 files changed, 408 insertions, 222 deletions
diff --git a/core/command/app/checkcode.php b/core/command/app/checkcode.php index 5beb13e2c7c..a533ce767f3 100644 --- a/core/command/app/checkcode.php +++ b/core/command/app/checkcode.php @@ -23,8 +23,9 @@ namespace OC\Core\Command\App; -use OC\App\CodeChecker; -use OC\App\DeprecationCodeChecker; +use OC\App\CodeChecker\CodeChecker; +use OC\App\CodeChecker\DeprecationList; +use OC\App\CodeChecker\PrivateList; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -52,10 +53,12 @@ class CheckCode extends Command { protected function execute(InputInterface $input, OutputInterface $output) { $appId = $input->getArgument('app-id'); if ($input->getOption('deprecated')) { - $codeChecker = new DeprecationCodeChecker(); + $list = new DeprecationList(); } else { - $codeChecker = new CodeChecker(); + $list = new PrivateList(); } + $codeChecker = new CodeChecker($list); + $codeChecker->listen('CodeChecker', 'analyseFileBegin', function($params) use ($output) { if(OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { $output->writeln("<info>Analysing {$params}</info>"); diff --git a/lib/private/app/codechecker.php b/lib/private/app/codechecker/codechecker.php index 93f82def81e..b2ee9d6d71d 100644 --- a/lib/private/app/codechecker.php +++ b/lib/private/app/codechecker/codechecker.php @@ -21,7 +21,7 @@ * */ -namespace OC\App; +namespace OC\App\CodeChecker; use OC\Hooks\BasicEmitter; use PhpParser\Lexer; @@ -49,48 +49,11 @@ class CodeChecker extends BasicEmitter { /** @var Parser */ private $parser; - /** @var string */ - protected $blackListDescription = 'private'; - - /** @var string[] */ - protected $blackListedClassNames = [ - // classes replaced by the public api - 'OC_API', - 'OC_App', - 'OC_AppConfig', - 'OC_Avatar', - 'OC_BackgroundJob', - 'OC_Config', - 'OC_DB', - 'OC_Files', - 'OC_Helper', - 'OC_Hook', - 'OC_Image', - 'OC_JSON', - 'OC_L10N', - 'OC_Log', - 'OC_Mail', - 'OC_Preferences', - 'OC_Search_Provider', - 'OC_Search_Result', - 'OC_Request', - 'OC_Response', - 'OC_Template', - 'OC_User', - 'OC_Util', - ]; - - protected $blackListedConstants = []; - - protected $blackListedFunctions = []; - - protected $blackListedMethods = []; - - /** @var bool */ - protected $checkEqualOperators = false; - - - public function __construct() { + /** @var ICheckList */ + protected $list; + + public function __construct(ICheckList $list) { + $this->list = $list; $this->parser = new Parser(new Lexer); } @@ -151,7 +114,7 @@ class CodeChecker extends BasicEmitter { $code = file_get_contents($file); $statements = $this->parser->parse($code); - $visitor = new CodeCheckVisitor($this->blackListDescription, $this->blackListedClassNames, $this->blackListedConstants, $this->blackListedFunctions, $this->blackListedMethods, $this->checkEqualOperators); + $visitor = new NodeVisitor($this->list); $traverser = new NodeTraverser; $traverser->addVisitor($visitor); diff --git a/lib/private/app/codechecker/deprecationlist.php b/lib/private/app/codechecker/deprecationlist.php new file mode 100644 index 00000000000..d0abc75a30f --- /dev/null +++ b/lib/private/app/codechecker/deprecationlist.php @@ -0,0 +1,152 @@ +<?php +/** + * @author Joas Schilling <nickvergessen@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OC\App\CodeChecker; + +class DeprecationList implements ICheckList { + /** + * @return string + */ + public function getDescription() { + return 'deprecated'; + } + + /** + * @return array E.g.: `'ClassName' => 'oc version',` + */ + public function getClasses() { + return [ + 'OCP\Config' => '8.0.0', + 'OCP\Contacts' => '8.1.0', + 'OCP\DB' => '8.1.0', + 'OCP\IHelper' => '8.1.0', + 'OCP\JSON' => '8.1.0', + 'OCP\Response' => '8.1.0', + 'OCP\AppFramework\IApi' => '8.0.0', + ]; + } + + /** + * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` + */ + public function getConstants() { + return [ + 'OCP::PERMISSION_CREATE' => '8.0.0', + 'OCP::PERMISSION_READ' => '8.0.0', + 'OCP::PERMISSION_UPDATE' => '8.0.0', + 'OCP::PERMISSION_DELETE' => '8.0.0', + 'OCP::PERMISSION_SHARE' => '8.0.0', + 'OCP::PERMISSION_ALL' => '8.0.0', + 'OCP::FILENAME_INVALID_CHARS' => '8.0.0', + ]; + } + + /** + * @return array E.g.: `'functionName' => 'oc version',` + */ + public function getFunctions() { + return [ + 'OCP::image_path' => '8.0.0', + 'OCP::mimetype_icon' => '8.0.0', + 'OCP::preview_icon' => '8.0.0', + 'OCP::publicPreview_icon' => '8.0.0', + 'OCP::human_file_size' => '8.0.0', + 'OCP::relative_modified_date' => '8.0.0', + 'OCP::simple_file_size' => '8.0.0', + 'OCP::html_select_options' => '8.0.0', + ]; + } + + /** + * @return array E.g.: `'ClassName::methodName' => 'oc version',` + */ + public function getMethods() { + return [ + 'OCP\App::register' => '8.1.0', + 'OCP\App::addNavigationEntry' => '8.1.0', + 'OCP\App::setActiveNavigationEntry' => '8.1.0', + + 'OCP\AppFramework\Controller::params' => '7.0.0', + 'OCP\AppFramework\Controller::getParams' => '7.0.0', + 'OCP\AppFramework\Controller::method' => '7.0.0', + 'OCP\AppFramework\Controller::getUploadedFile' => '7.0.0', + 'OCP\AppFramework\Controller::env' => '7.0.0', + 'OCP\AppFramework\Controller::cookie' => '7.0.0', + 'OCP\AppFramework\Controller::render' => '7.0.0', + + 'OCP\AppFramework\IAppContainer::getCoreApi' => '8.0.0', + 'OCP\AppFramework\IAppContainer::isLoggedIn' => '8.0.0', + 'OCP\AppFramework\IAppContainer::isAdminUser' => '8.0.0', + 'OCP\AppFramework\IAppContainer::log' => '8.0.0', + + 'OCP\BackgroundJob::addQueuedTask' => '6.0.0', + 'OCP\BackgroundJob::addRegularTask' => '6.0.0', + 'OCP\BackgroundJob::allQueuedTasks' => '6.0.0', + 'OCP\BackgroundJob::allRegularTasks' => '6.0.0', + 'OCP\BackgroundJob::deleteQueuedTask' => '6.0.0', + 'OCP\BackgroundJob::findQueuedTask' => '6.0.0', + 'OCP\BackgroundJob::queuedTaskWhereAppIs' => '6.0.0', + 'OCP\BackgroundJob::registerJob' => '8.1.0', + + 'OCP\Files::tmpFile' => '8.1.0', + 'OCP\Files::tmpFolder' => '8.1.0', + + 'OCP\IAppConfig::getValue' => '8.0.0', + 'OCP\IAppConfig::deleteKey' => '8.0.0', + 'OCP\IAppConfig::getKeys' => '8.0.0', + 'OCP\IAppConfig::setValue' => '8.0.0', + 'OCP\IAppConfig::deleteApp' => '8.0.0', + + 'OCP\ISearch::search' => '8.0.0', + + 'OCP\IServerContainer::getDb' => '8.1.0', + 'OCP\IServerContainer::getHTTPHelper' => '8.1.0', + + 'OCP\User::getUser' => '8.0.0', + 'OCP\User::getUsers' => '8.1.0', + 'OCP\User::getDisplayName' => '8.1.0', + 'OCP\User::getDisplayNames' => '8.1.0', + 'OCP\User::userExists' => '8.1.0', + 'OCP\User::logout' => '8.1.0', + 'OCP\User::checkPassword' => '8.1.0', + + 'OCP\Util::sendMail' => '8.1.0', + 'OCP\Util::formatDate' => '8.0.0', + 'OCP\Util::encryptedFiles' => '8.1.0', + 'OCP\Util::linkToRoute' => '8.1.0', + 'OCP\Util::linkTo' => '8.1.0', + 'OCP\Util::getServerHost' => '8.1.0', + 'OCP\Util::getServerProtocol' => '8.1.0', + 'OCP\Util::getRequestUri' => '8.1.0', + 'OCP\Util::getScriptName' => '8.1.0', + 'OCP\Util::imagePath' => '8.1.0', + 'OCP\Util::isValidFileName' => '8.1.0', + 'OCP\Util::generateRandomBytes' => '8.1.0', + ]; + } + + /** + * @return bool + */ + public function checkStrongComparisons() { + return true; + } +} diff --git a/tests/lib/app/mock/codechecker.php b/lib/private/app/codechecker/ichecklist.php index b5a775cc43d..c5cc82e6bb5 100644 --- a/tests/lib/app/mock/codechecker.php +++ b/lib/private/app/codechecker/ichecklist.php @@ -18,32 +18,36 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ +namespace OC\App\CodeChecker; -namespace Test\App\Mock; +interface ICheckList { + /** + * @return string + */ + public function getDescription(); -class CodeChecker extends \OC\App\CodeChecker { - protected $checkEqualOperators = true; + /** + * @return array E.g.: `'ClassName' => 'oc version',` + */ + public function getClasses(); - /** @var string */ - protected $blackListDescription = 'deprecated'; + /** + * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` + */ + public function getConstants(); - protected $blackListedClassNames = [ - // Deprecated classes - 'OCP\AppFramework\IApi' => '8.0.0', - ]; + /** + * @return array E.g.: `'functionName' => 'oc version',` + */ + public function getFunctions(); - protected $blackListedConstants = [ - // Deprecated constants - 'OCP\NamespaceName\ClassName::CONSTANT_NAME' => '8.0.0', - ]; + /** + * @return array E.g.: `'ClassName::methodName' => 'oc version',` + */ + public function getMethods(); - protected $blackListedFunctions = [ - // Deprecated functions - 'OCP\NamespaceName\ClassName::functionName' => '8.0.0', - ]; - - protected $blackListedMethods = [ - // Deprecated methods - 'OCP\NamespaceName\ClassName::methodName' => '8.0.0', - ]; + /** + * @return bool + */ + public function checkStrongComparisons(); } diff --git a/lib/private/app/codecheckvisitor.php b/lib/private/app/codechecker/nodevisitor.php index dd12d2faa4d..8ec4a0320f4 100644 --- a/lib/private/app/codecheckvisitor.php +++ b/lib/private/app/codechecker/nodevisitor.php @@ -20,13 +20,13 @@ * */ -namespace OC\App; +namespace OC\App\CodeChecker; use PhpParser\Node; use PhpParser\Node\Name; use PhpParser\NodeVisitorAbstract; -class CodeCheckVisitor extends NodeVisitorAbstract { +class NodeVisitor extends NodeVisitorAbstract { /** @var string */ protected $blackListDescription; /** @var string[] */ @@ -43,18 +43,13 @@ class CodeCheckVisitor extends NodeVisitorAbstract { protected $errorMessages; /** - * @param string $blackListDescription - * @param array $blackListedClassNames - * @param array $blackListedConstants - * @param array $blackListedFunctions - * @param array $blackListedMethods - * @param bool $checkEqualOperatorUsage + * @param ICheckList $list */ - public function __construct($blackListDescription, $blackListedClassNames, $blackListedConstants, $blackListedFunctions, $blackListedMethods, $checkEqualOperatorUsage) { - $this->blackListDescription = $blackListDescription; + public function __construct(ICheckList $list) { + $this->blackListDescription = $list->getDescription(); $this->blackListedClassNames = []; - foreach ($blackListedClassNames as $class => $blackListInfo) { + foreach ($list->getClasses() as $class => $blackListInfo) { if (is_numeric($class) && is_string($blackListInfo)) { $class = $blackListInfo; $blackListInfo = null; @@ -65,24 +60,24 @@ class CodeCheckVisitor extends NodeVisitorAbstract { } $this->blackListedConstants = []; - foreach ($blackListedConstants as $constantName => $blackListInfo) { + foreach ($list->getConstants() as $constantName => $blackListInfo) { $constantName = strtolower($constantName); $this->blackListedConstants[$constantName] = $constantName; } $this->blackListedFunctions = []; - foreach ($blackListedFunctions as $functionName => $blackListInfo) { + foreach ($list->getFunctions() as $functionName => $blackListInfo) { $functionName = strtolower($functionName); $this->blackListedFunctions[$functionName] = $functionName; } $this->blackListedMethods = []; - foreach ($blackListedMethods as $functionName => $blackListInfo) { + foreach ($list->getMethods() as $functionName => $blackListInfo) { $functionName = strtolower($functionName); $this->blackListedMethods[$functionName] = $functionName; } - $this->checkEqualOperatorUsage = $checkEqualOperatorUsage; + $this->checkEqualOperatorUsage = $list->checkStrongComparisons(); $this->errorMessages = [ CodeChecker::CLASS_EXTENDS_NOT_ALLOWED => "{$this->blackListDescription} class must not be extended", diff --git a/lib/private/app/codechecker/privatelist.php b/lib/private/app/codechecker/privatelist.php new file mode 100644 index 00000000000..e44926ada77 --- /dev/null +++ b/lib/private/app/codechecker/privatelist.php @@ -0,0 +1,105 @@ +<?php +/** + * @author Joas Schilling <nickvergessen@owncloud.com> + * @author Morris Jobke <hey@morrisjobke.de> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OC\App\CodeChecker; + +use OC\Hooks\BasicEmitter; +use PhpParser\Lexer; +use PhpParser\Node; +use PhpParser\Node\Name; +use PhpParser\NodeTraverser; +use PhpParser\Parser; +use RecursiveCallbackFilterIterator; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use RegexIterator; +use SplFileInfo; + +class PrivateList implements ICheckList { + /** + * @return string + */ + public function getDescription() { + return 'private'; + } + + /** + * @return array + */ + public function getClasses() { + return [ + // classes replaced by the public api + 'OC_API', + 'OC_App', + 'OC_AppConfig', + 'OC_Avatar', + 'OC_BackgroundJob', + 'OC_Config', + 'OC_DB', + 'OC_Files', + 'OC_Helper', + 'OC_Hook', + 'OC_Image', + 'OC_JSON', + 'OC_L10N', + 'OC_Log', + 'OC_Mail', + 'OC_Preferences', + 'OC_Search_Provider', + 'OC_Search_Result', + 'OC_Request', + 'OC_Response', + 'OC_Template', + 'OC_User', + 'OC_Util', + ]; + } + + /** + * @return array + */ + public function getConstants() { + return []; + } + + /** + * @return array + */ + public function getFunctions() { + return []; + } + + /** + * @return array + */ + public function getMethods() { + return []; + } + + /** + * @return bool + */ + public function checkStrongComparisons() { + return false; + } +} diff --git a/lib/private/app/deprecationcodechecker.php b/lib/private/app/deprecationcodechecker.php deleted file mode 100644 index 5bec83f971a..00000000000 --- a/lib/private/app/deprecationcodechecker.php +++ /dev/null @@ -1,127 +0,0 @@ -<?php -/** - * @author Joas Schilling <nickvergessen@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\App; - -class DeprecationCodeChecker extends CodeChecker { - protected $checkEqualOperators = true; - - /** @var string */ - protected $blackListDescription = 'deprecated'; - - protected $blackListedClassNames = [ - // Deprecated classes - 'OCP\Config' => '8.0.0', - 'OCP\Contacts' => '8.1.0', - 'OCP\DB' => '8.1.0', - 'OCP\IHelper' => '8.1.0', - 'OCP\JSON' => '8.1.0', - 'OCP\Response' => '8.1.0', - 'OCP\AppFramework\IApi' => '8.0.0', - ]; - - protected $blackListedConstants = [ - // Deprecated constants - 'OCP::PERMISSION_CREATE' => '8.0.0', - 'OCP::PERMISSION_READ' => '8.0.0', - 'OCP::PERMISSION_UPDATE' => '8.0.0', - 'OCP::PERMISSION_DELETE' => '8.0.0', - 'OCP::PERMISSION_SHARE' => '8.0.0', - 'OCP::PERMISSION_ALL' => '8.0.0', - 'OCP::FILENAME_INVALID_CHARS' => '8.0.0', - ]; - - protected $blackListedFunctions = [ - // Deprecated functions - 'OCP::image_path' => '8.0.0', - 'OCP::mimetype_icon' => '8.0.0', - 'OCP::preview_icon' => '8.0.0', - 'OCP::publicPreview_icon' => '8.0.0', - 'OCP::human_file_size' => '8.0.0', - 'OCP::relative_modified_date' => '8.0.0', - 'OCP::simple_file_size' => '8.0.0', - 'OCP::html_select_options' => '8.0.0', - ]; - - protected $blackListedMethods = [ - // Deprecated methods - 'OCP\App::register' => '8.1.0', - 'OCP\App::addNavigationEntry' => '8.1.0', - 'OCP\App::setActiveNavigationEntry' => '8.1.0', - - 'OCP\AppFramework\Controller::params' => '7.0.0', - 'OCP\AppFramework\Controller::getParams' => '7.0.0', - 'OCP\AppFramework\Controller::method' => '7.0.0', - 'OCP\AppFramework\Controller::getUploadedFile' => '7.0.0', - 'OCP\AppFramework\Controller::env' => '7.0.0', - 'OCP\AppFramework\Controller::cookie' => '7.0.0', - 'OCP\AppFramework\Controller::render' => '7.0.0', - - 'OCP\AppFramework\IAppContainer::getCoreApi' => '8.0.0', - 'OCP\AppFramework\IAppContainer::isLoggedIn' => '8.0.0', - 'OCP\AppFramework\IAppContainer::isAdminUser' => '8.0.0', - 'OCP\AppFramework\IAppContainer::log' => '8.0.0', - - 'OCP\BackgroundJob::addQueuedTask' => '6.0.0', - 'OCP\BackgroundJob::addRegularTask' => '6.0.0', - 'OCP\BackgroundJob::allQueuedTasks' => '6.0.0', - 'OCP\BackgroundJob::allRegularTasks' => '6.0.0', - 'OCP\BackgroundJob::deleteQueuedTask' => '6.0.0', - 'OCP\BackgroundJob::findQueuedTask' => '6.0.0', - 'OCP\BackgroundJob::queuedTaskWhereAppIs' => '6.0.0', - 'OCP\BackgroundJob::registerJob' => '8.1.0', - - 'OCP\Files::tmpFile' => '8.1.0', - 'OCP\Files::tmpFolder' => '8.1.0', - - 'OCP\IAppConfig::getValue' => '8.0.0', - 'OCP\IAppConfig::deleteKey' => '8.0.0', - 'OCP\IAppConfig::getKeys' => '8.0.0', - 'OCP\IAppConfig::setValue' => '8.0.0', - 'OCP\IAppConfig::deleteApp' => '8.0.0', - - 'OCP\ISearch::search' => '8.0.0', - - 'OCP\IServerContainer::getDb' => '8.1.0', - 'OCP\IServerContainer::getHTTPHelper' => '8.1.0', - - 'OCP\User::getUser' => '8.0.0', - 'OCP\User::getUsers' => '8.1.0', - 'OCP\User::getDisplayName' => '8.1.0', - 'OCP\User::getDisplayNames' => '8.1.0', - 'OCP\User::userExists' => '8.1.0', - 'OCP\User::logout' => '8.1.0', - 'OCP\User::checkPassword' => '8.1.0', - - 'OCP\Util::sendMail' => '8.1.0', - 'OCP\Util::formatDate' => '8.0.0', - 'OCP\Util::encryptedFiles' => '8.1.0', - 'OCP\Util::linkToRoute' => '8.1.0', - 'OCP\Util::linkTo' => '8.1.0', - 'OCP\Util::getServerHost' => '8.1.0', - 'OCP\Util::getServerProtocol' => '8.1.0', - 'OCP\Util::getRequestUri' => '8.1.0', - 'OCP\Util::getScriptName' => '8.1.0', - 'OCP\Util::imagePath' => '8.1.0', - 'OCP\Util::isValidFileName' => '8.1.0', - 'OCP\Util::generateRandomBytes' => '8.1.0', - ]; -} diff --git a/tests/lib/app/codechecker.php b/tests/lib/app/codechecker/codecheckertest.php index 435aedfe3ad..93bf0b32c58 100644 --- a/tests/lib/app/codechecker.php +++ b/tests/lib/app/codechecker/codecheckertest.php @@ -6,12 +6,12 @@ * See the COPYING-README file. */ -namespace Test\App; +namespace Test\App\CodeChecker; use OC; use Test\TestCase; -class CodeChecker extends TestCase { +class CodeCheckerTest extends TestCase { /** * @dataProvider providesFilesToCheck @@ -20,7 +20,9 @@ class CodeChecker extends TestCase { * @param string $fileToVerify */ public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { - $checker = new OC\App\CodeChecker(); + $checker = new OC\App\CodeChecker\CodeChecker( + new OC\App\CodeChecker\PrivateList() + ); $errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); $this->assertEquals(1, count($errors)); @@ -44,7 +46,9 @@ class CodeChecker extends TestCase { * @param string $fileToVerify */ public function testPassValidUsage($fileToVerify) { - $checker = new OC\App\CodeChecker(); + $checker = new OC\App\CodeChecker\CodeChecker( + new OC\App\CodeChecker\PrivateList() + ); $errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); $this->assertEquals(0, count($errors)); diff --git a/tests/lib/app/deprecationcodechecker.php b/tests/lib/app/codechecker/deprecationlisttest.php index 57d9ca85a7a..2293d31a1f6 100644 --- a/tests/lib/app/deprecationcodechecker.php +++ b/tests/lib/app/codechecker/deprecationlisttest.php @@ -11,7 +11,7 @@ namespace Test\App; use OC; use Test\TestCase; -class DeprecationCodeChecker extends TestCase { +class DeprecationListTest extends TestCase { /** * @dataProvider providesFilesToCheck @@ -20,7 +20,9 @@ class DeprecationCodeChecker extends TestCase { * @param string $fileToVerify */ public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { - $checker = new \OC\App\DeprecationCodeChecker(); + $checker = new OC\App\CodeChecker\CodeChecker( + new OC\App\CodeChecker\DeprecationList() + ); $errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); $this->assertEquals(1, count($errors)); @@ -44,7 +46,9 @@ class DeprecationCodeChecker extends TestCase { * @param string $fileToVerify */ public function testPassValidUsage($fileToVerify) { - $checker = new \OC\App\DeprecationCodeChecker(); + $checker = new OC\App\CodeChecker\CodeChecker( + new OC\App\CodeChecker\DeprecationList() + ); $errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); $this->assertEquals(0, count($errors)); diff --git a/tests/lib/app/codechecker/mock/testlist.php b/tests/lib/app/codechecker/mock/testlist.php new file mode 100644 index 00000000000..c4985e8e625 --- /dev/null +++ b/tests/lib/app/codechecker/mock/testlist.php @@ -0,0 +1,81 @@ +<?php +/** + * @author Joas Schilling <nickvergessen@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace Test\App\CodeChecker\Mock; + +use OC\App\CodeChecker\ICheckList; + +class TestList implements ICheckList { + + /** + * @return string + */ + public function getDescription() { + return 'deprecated'; + } + + /** + * @return array E.g.: `'ClassName' => 'oc version',` + */ + public function getClasses() { + return [ + // Deprecated classes + 'OCP\AppFramework\IApi' => '8.0.0', + ]; + } + + /** + * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` + */ + public function getConstants() { + return [ + // Deprecated constants + 'OCP\NamespaceName\ClassName::CONSTANT_NAME' => '8.0.0', + ]; + } + + /** + * @return array E.g.: `'functionName' => 'oc version',` + */ + public function getFunctions() { + return [ + // Deprecated functions + 'OCP\NamespaceName\ClassName::functionName' => '8.0.0', + ]; + } + + /** + * @return array E.g.: `'ClassName::methodName' => 'oc version',` + */ + public function getMethods() { + return [ + // Deprecated methods + 'OCP\NamespaceName\ClassName::methodName' => '8.0.0', + ]; + } + + /** + * @return bool + */ + public function checkStrongComparisons() { + return true; + } +} diff --git a/tests/lib/app/codecheckvisitor.php b/tests/lib/app/codechecker/nodevisitortest.php index d836f1b3c84..1207ca6a043 100644 --- a/tests/lib/app/codecheckvisitor.php +++ b/tests/lib/app/codechecker/nodevisitortest.php @@ -6,12 +6,12 @@ * See the COPYING-README file. */ -namespace Test\App; +namespace Test\AppCodeChecker; use OC; use Test\TestCase; -class CodeCheckVisitor extends TestCase { +class NodeVisitorTest extends TestCase { public function providesFilesToCheck() { return [ @@ -56,7 +56,9 @@ class CodeCheckVisitor extends TestCase { * @param string $fileToVerify */ public function testMethodsToCheck($expectedErrors, $fileToVerify) { - $checker = new \Test\App\Mock\CodeChecker(); + $checker = new OC\App\CodeChecker\CodeChecker( + new \Test\App\CodeChecker\Mock\TestList() + ); $errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); $this->assertCount(sizeof($expectedErrors), $errors); |