summaryrefslogtreecommitdiffstats
path: root/lib/private/app
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-07-07 12:08:12 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-07-17 12:34:56 +0200
commitbba87a2a3b46d20a552efa4a1d00d3253aedf27b (patch)
treeb243d9e54018e114123b53021d0d93c327fbefcc /lib/private/app
parent9e469046faee66171be15fa6d0bb6eef2289fa0f (diff)
downloadnextcloud-server-bba87a2a3b46d20a552efa4a1d00d3253aedf27b.tar.gz
nextcloud-server-bba87a2a3b46d20a552efa4a1d00d3253aedf27b.zip
Restructor the code into different classes instead of extending
Diffstat (limited to 'lib/private/app')
-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.php152
-rw-r--r--lib/private/app/codechecker/ichecklist.php53
-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.php105
-rw-r--r--lib/private/app/deprecationcodechecker.php127
6 files changed, 327 insertions, 186 deletions
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/lib/private/app/codechecker/ichecklist.php b/lib/private/app/codechecker/ichecklist.php
new file mode 100644
index 00000000000..c5cc82e6bb5
--- /dev/null
+++ b/lib/private/app/codechecker/ichecklist.php
@@ -0,0 +1,53 @@
+<?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;
+
+interface ICheckList {
+ /**
+ * @return string
+ */
+ public function getDescription();
+
+ /**
+ * @return array E.g.: `'ClassName' => 'oc version',`
+ */
+ public function getClasses();
+
+ /**
+ * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',`
+ */
+ public function getConstants();
+
+ /**
+ * @return array E.g.: `'functionName' => 'oc version',`
+ */
+ public function getFunctions();
+
+ /**
+ * @return array E.g.: `'ClassName::methodName' => 'oc version',`
+ */
+ public function getMethods();
+
+ /**
+ * @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',
- ];
-}