diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-07-07 15:37:56 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-07-17 12:34:56 +0200 |
commit | a0c6f2e5e071a287717e58f32c5b3cf6e219f321 (patch) | |
tree | 231363a90e1c8296e8a06a0346078adc3c5e8454 /lib | |
parent | bba87a2a3b46d20a552efa4a1d00d3253aedf27b (diff) | |
download | nextcloud-server-a0c6f2e5e071a287717e58f32c5b3cf6e219f321.tar.gz nextcloud-server-a0c6f2e5e071a287717e58f32c5b3cf6e219f321.zip |
Use the decorator pattern
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/app/codechecker/codechecker.php | 10 | ||||
-rw-r--r-- | lib/private/app/codechecker/deprecationcheck.php (renamed from lib/private/app/codechecker/deprecationlist.php) | 33 | ||||
-rw-r--r-- | lib/private/app/codechecker/emptycheck.php | 65 | ||||
-rw-r--r-- | lib/private/app/codechecker/icheck.php (renamed from lib/private/app/codechecker/ichecklist.php) | 2 | ||||
-rw-r--r-- | lib/private/app/codechecker/nodevisitor.php | 4 | ||||
-rw-r--r-- | lib/private/app/codechecker/privatecheck.php | 104 | ||||
-rw-r--r-- | lib/private/app/codechecker/strongcomparisoncheck.php (renamed from lib/private/app/codechecker/privatelist.php) | 59 |
7 files changed, 215 insertions, 62 deletions
diff --git a/lib/private/app/codechecker/codechecker.php b/lib/private/app/codechecker/codechecker.php index b2ee9d6d71d..ae16b156178 100644 --- a/lib/private/app/codechecker/codechecker.php +++ b/lib/private/app/codechecker/codechecker.php @@ -49,11 +49,11 @@ class CodeChecker extends BasicEmitter { /** @var Parser */ private $parser; - /** @var ICheckList */ - protected $list; + /** @var ICheck */ + protected $checkList; - public function __construct(ICheckList $list) { - $this->list = $list; + public function __construct(ICheck $checkList) { + $this->checkList = $checkList; $this->parser = new Parser(new Lexer); } @@ -114,7 +114,7 @@ class CodeChecker extends BasicEmitter { $code = file_get_contents($file); $statements = $this->parser->parse($code); - $visitor = new NodeVisitor($this->list); + $visitor = new NodeVisitor($this->checkList); $traverser = new NodeTraverser; $traverser->addVisitor($visitor); diff --git a/lib/private/app/codechecker/deprecationlist.php b/lib/private/app/codechecker/deprecationcheck.php index d0abc75a30f..bac59e4dd7c 100644 --- a/lib/private/app/codechecker/deprecationlist.php +++ b/lib/private/app/codechecker/deprecationcheck.php @@ -21,19 +21,30 @@ namespace OC\App\CodeChecker; -class DeprecationList implements ICheckList { +class DeprecationCheck implements ICheck { + /** @var ICheck */ + protected $check; + + /** + * @param ICheck $check + */ + public function __construct(ICheck $check) { + $this->check = $check; + } + /** * @return string */ public function getDescription() { - return 'deprecated'; + $innerDescription = $this->check->getDescription(); + return 'deprecated' . (($innerDescription === '') ? '' : ' ' . $innerDescription); } /** * @return array E.g.: `'ClassName' => 'oc version',` */ public function getClasses() { - return [ + return array_merge([ 'OCP\Config' => '8.0.0', 'OCP\Contacts' => '8.1.0', 'OCP\DB' => '8.1.0', @@ -41,14 +52,14 @@ class DeprecationList implements ICheckList { 'OCP\JSON' => '8.1.0', 'OCP\Response' => '8.1.0', 'OCP\AppFramework\IApi' => '8.0.0', - ]; + ], $this->check->getClasses()); } /** * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` */ public function getConstants() { - return [ + return array_merge([ 'OCP::PERMISSION_CREATE' => '8.0.0', 'OCP::PERMISSION_READ' => '8.0.0', 'OCP::PERMISSION_UPDATE' => '8.0.0', @@ -56,14 +67,14 @@ class DeprecationList implements ICheckList { 'OCP::PERMISSION_SHARE' => '8.0.0', 'OCP::PERMISSION_ALL' => '8.0.0', 'OCP::FILENAME_INVALID_CHARS' => '8.0.0', - ]; + ], $this->check->getConstants()); } /** * @return array E.g.: `'functionName' => 'oc version',` */ public function getFunctions() { - return [ + return array_merge([ 'OCP::image_path' => '8.0.0', 'OCP::mimetype_icon' => '8.0.0', 'OCP::preview_icon' => '8.0.0', @@ -72,14 +83,14 @@ class DeprecationList implements ICheckList { 'OCP::relative_modified_date' => '8.0.0', 'OCP::simple_file_size' => '8.0.0', 'OCP::html_select_options' => '8.0.0', - ]; + ], $this->check->getFunctions()); } /** * @return array E.g.: `'ClassName::methodName' => 'oc version',` */ public function getMethods() { - return [ + return array_merge([ 'OCP\App::register' => '8.1.0', 'OCP\App::addNavigationEntry' => '8.1.0', 'OCP\App::setActiveNavigationEntry' => '8.1.0', @@ -140,13 +151,13 @@ class DeprecationList implements ICheckList { 'OCP\Util::imagePath' => '8.1.0', 'OCP\Util::isValidFileName' => '8.1.0', 'OCP\Util::generateRandomBytes' => '8.1.0', - ]; + ], $this->check->getMethods()); } /** * @return bool */ public function checkStrongComparisons() { - return true; + return $this->check->checkStrongComparisons(); } } diff --git a/lib/private/app/codechecker/emptycheck.php b/lib/private/app/codechecker/emptycheck.php new file mode 100644 index 00000000000..78a0d303790 --- /dev/null +++ b/lib/private/app/codechecker/emptycheck.php @@ -0,0 +1,65 @@ +<?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 EmptyCheck implements ICheck { + /** + * @return string + */ + public function getDescription() { + return ''; + } + + /** + * @return array E.g.: `'ClassName' => 'oc version',` + */ + public function getClasses() { + return []; + } + + /** + * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` + */ + public function getConstants() { + return []; + } + + /** + * @return array E.g.: `'functionName' => 'oc version',` + */ + public function getFunctions() { + return []; + } + + /** + * @return array E.g.: `'ClassName::methodName' => 'oc version',` + */ + public function getMethods() { + return []; + } + + /** + * @return bool + */ + public function checkStrongComparisons() { + return false; + } +} diff --git a/lib/private/app/codechecker/ichecklist.php b/lib/private/app/codechecker/icheck.php index c5cc82e6bb5..7625a105b0a 100644 --- a/lib/private/app/codechecker/ichecklist.php +++ b/lib/private/app/codechecker/icheck.php @@ -20,7 +20,7 @@ */ namespace OC\App\CodeChecker; -interface ICheckList { +interface ICheck { /** * @return string */ diff --git a/lib/private/app/codechecker/nodevisitor.php b/lib/private/app/codechecker/nodevisitor.php index 8ec4a0320f4..80acb9f2414 100644 --- a/lib/private/app/codechecker/nodevisitor.php +++ b/lib/private/app/codechecker/nodevisitor.php @@ -43,9 +43,9 @@ class NodeVisitor extends NodeVisitorAbstract { protected $errorMessages; /** - * @param ICheckList $list + * @param ICheck $list */ - public function __construct(ICheckList $list) { + public function __construct(ICheck $list) { $this->blackListDescription = $list->getDescription(); $this->blackListedClassNames = []; diff --git a/lib/private/app/codechecker/privatecheck.php b/lib/private/app/codechecker/privatecheck.php new file mode 100644 index 00000000000..e7497f3dbfc --- /dev/null +++ b/lib/private/app/codechecker/privatecheck.php @@ -0,0 +1,104 @@ +<?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; + +class PrivateCheck implements ICheck { + /** @var ICheck */ + protected $check; + + /** + * @param ICheck $check + */ + public function __construct(ICheck $check) { + $this->check = $check; + } + + /** + * @return string + */ + public function getDescription() { + $innerDescription = $this->check->getDescription(); + return 'private' . (($innerDescription === '') ? '' : ' ' . $innerDescription); + } + + /** + * @return array + */ + public function getClasses() { + return array_merge([ + // classes replaced by the public api + 'OC_API' => '6.0.0', + 'OC_App' => '6.0.0', + 'OC_AppConfig' => '6.0.0', + 'OC_Avatar' => '6.0.0', + 'OC_BackgroundJob' => '6.0.0', + 'OC_Config' => '6.0.0', + 'OC_DB' => '6.0.0', + 'OC_Files' => '6.0.0', + 'OC_Helper' => '6.0.0', + 'OC_Hook' => '6.0.0', + 'OC_Image' => '6.0.0', + 'OC_JSON' => '6.0.0', + 'OC_L10N' => '6.0.0', + 'OC_Log' => '6.0.0', + 'OC_Mail' => '6.0.0', + 'OC_Preferences' => '6.0.0', + 'OC_Search_Provider' => '6.0.0', + 'OC_Search_Result' => '6.0.0', + 'OC_Request' => '6.0.0', + 'OC_Response' => '6.0.0', + 'OC_Template' => '6.0.0', + 'OC_User' => '6.0.0', + 'OC_Util' => '6.0.0', + ], $this->check->getClasses()); + } + + /** + * @return array + */ + public function getConstants() { + return $this->check->getConstants(); + } + + /** + * @return array + */ + public function getFunctions() { + return $this->check->getFunctions(); + } + + /** + * @return array + */ + public function getMethods() { + return $this->check->getMethods(); + } + + /** + * @return bool + */ + public function checkStrongComparisons() { + return $this->check->checkStrongComparisons(); + } +} diff --git a/lib/private/app/codechecker/privatelist.php b/lib/private/app/codechecker/strongcomparisoncheck.php index e44926ada77..bfbde1acbef 100644 --- a/lib/private/app/codechecker/privatelist.php +++ b/lib/private/app/codechecker/strongcomparisoncheck.php @@ -23,83 +23,56 @@ 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 StrongComparisonCheck implements ICheck { + /** @var ICheck */ + protected $check; + + /** + * @param ICheck $check + */ + public function __construct(ICheck $check) { + $this->check = $check; + } -class PrivateList implements ICheckList { /** * @return string */ public function getDescription() { - return 'private'; + return $this->check->getDescription(); } /** * @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 $this->check->getClasses(); } /** * @return array */ public function getConstants() { - return []; + return $this->check->getConstants(); } /** * @return array */ public function getFunctions() { - return []; + return $this->check->getFunctions(); } /** * @return array */ public function getMethods() { - return []; + return $this->check->getMethods(); } /** * @return bool */ public function checkStrongComparisons() { - return false; + return true; } } |