Restructor the code into different classes instead of extending
This commit is contained in:
parent
9e469046fa
commit
bba87a2a3b
11 changed files with 407 additions and 221 deletions
|
@ -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>");
|
||||
|
|
|
@ -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 ICheckList */
|
||||
protected $list;
|
||||
|
||||
/** @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() {
|
||||
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);
|
||||
|
152
lib/private/app/codechecker/deprecationlist.php
Normal file
152
lib/private/app/codechecker/deprecationlist.php
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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",
|
105
lib/private/app/codechecker/privatelist.php
Normal file
105
lib/private/app/codechecker/privatelist.php
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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',
|
||||
];
|
||||
}
|
|
@ -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));
|
|
@ -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));
|
81
tests/lib/app/codechecker/mock/testlist.php
Normal file
81
tests/lib/app/codechecker/mock/testlist.php
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
Loading…
Reference in a new issue