aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/app
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-06-15 17:20:38 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-07-17 12:34:56 +0200
commitf228a3dc28b579b3d11126544928edacd2e2d9c4 (patch)
treed11eebce3ef51c264bc896cf28cb14a132559d8f /lib/private/app
parent483c886291f23577417d820a8e65702ec0d1cc85 (diff)
downloadnextcloud-server-f228a3dc28b579b3d11126544928edacd2e2d9c4.tar.gz
nextcloud-server-f228a3dc28b579b3d11126544928edacd2e2d9c4.zip
Add support for deprecated constants
Diffstat (limited to 'lib/private/app')
-rw-r--r--lib/private/app/codechecker.php4
-rw-r--r--lib/private/app/codecheckvisitor.php43
-rw-r--r--lib/private/app/deprecationcodechecker.php15
3 files changed, 54 insertions, 8 deletions
diff --git a/lib/private/app/codechecker.php b/lib/private/app/codechecker.php
index 0216e61e7ae..57e1a4c5b5d 100644
--- a/lib/private/app/codechecker.php
+++ b/lib/private/app/codechecker.php
@@ -79,6 +79,8 @@ class CodeChecker extends BasicEmitter {
'OC_Util',
];
+ protected $blackListedConstants = [];
+
/** @var bool */
protected $checkEqualOperators = false;
@@ -144,7 +146,7 @@ class CodeChecker extends BasicEmitter {
$code = file_get_contents($file);
$statements = $this->parser->parse($code);
- $visitor = new CodeCheckVisitor($this->blackListDescription, $this->blackListedClassNames, $this->checkEqualOperators);
+ $visitor = new CodeCheckVisitor($this->blackListDescription, $this->blackListedClassNames, $this->blackListedConstants, $this->checkEqualOperators);
$traverser = new NodeTraverser;
$traverser->addVisitor($visitor);
diff --git a/lib/private/app/codecheckvisitor.php b/lib/private/app/codecheckvisitor.php
index 2d0569e8324..60c685747be 100644
--- a/lib/private/app/codecheckvisitor.php
+++ b/lib/private/app/codecheckvisitor.php
@@ -31,6 +31,8 @@ class CodeCheckVisitor extends NodeVisitorAbstract {
protected $blackListDescription;
/** @var string[] */
protected $blackListedClassNames;
+ /** @var string[] */
+ protected $blackListedConstants;
/** @var bool */
protected $checkEqualOperatorUsage;
/** @var string[] */
@@ -39,9 +41,10 @@ class CodeCheckVisitor extends NodeVisitorAbstract {
/**
* @param string $blackListDescription
* @param array $blackListedClassNames
+ * @param array $blackListedConstants
* @param bool $checkEqualOperatorUsage
*/
- public function __construct($blackListDescription, $blackListedClassNames, $checkEqualOperatorUsage) {
+ public function __construct($blackListDescription, $blackListedClassNames, $blackListedConstants, $checkEqualOperatorUsage) {
$this->blackListDescription = $blackListDescription;
$this->blackListedClassNames = [];
@@ -54,6 +57,13 @@ class CodeCheckVisitor extends NodeVisitorAbstract {
$class = strtolower($class);
$this->blackListedClassNames[$class] = $class;
}
+
+ $this->blackListedConstants = [];
+ foreach ($blackListedConstants as $constant => $blackListInfo) {
+ $constant = strtolower($constant);
+ $this->blackListedConstants[$constant] = $constant;
+ }
+
$this->checkEqualOperatorUsage = $checkEqualOperatorUsage;
$this->errorMessages = [
@@ -122,6 +132,8 @@ class CodeCheckVisitor extends NodeVisitorAbstract {
* $n = $i::ADMIN_AUTH;
*/
}
+
+ $this->checkBlackListConstant($node->class->toString(), $node->name, $node);
}
}
if ($node instanceof Node\Expr\New_) {
@@ -170,15 +182,40 @@ class CodeCheckVisitor extends NodeVisitorAbstract {
$this->blackListedClassNames[$aliasedClassName] = $blackListedClassName;
}
}
+
+ foreach ($this->blackListedConstants as $blackListedAlias => $blackListedConstant) {
+ if (strpos($blackListedConstant, $name . '\\') === 0 || strpos($blackListedConstant, $name . '::') === 0) {
+ $aliasedClassName = str_replace($name, $alias, $blackListedConstant);
+ $this->blackListedConstants[$aliasedClassName] = $blackListedConstant;
+ }
+ }
+
+ $name = strtolower($name);
}
private function checkBlackList($name, $errorCode, Node $node) {
- if (isset($this->blackListedClassNames[strtolower($name)])) {
+ $lowerName = strtolower($name);
+
+ if (isset($this->blackListedClassNames[$lowerName])) {
$this->errors[]= [
'disallowedToken' => $name,
'errorCode' => $errorCode,
'line' => $node->getLine(),
- 'reason' => $this->buildReason($this->blackListedClassNames[strtolower($name)], $errorCode)
+ 'reason' => $this->buildReason($this->blackListedClassNames[$lowerName], $errorCode)
+ ];
+ }
+ }
+
+ private function checkBlackListConstant($class, $constants, Node $node) {
+ $name = $class . '::' . $constants;
+ $lowerName = strtolower($name);
+
+ if (isset($this->blackListedConstants[$lowerName])) {
+ $this->errors[]= [
+ 'disallowedToken' => $name,
+ 'errorCode' => CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED,
+ 'line' => $node->getLine(),
+ 'reason' => $this->buildReason($this->blackListedConstants[$lowerName], CodeChecker::CLASS_CONST_FETCH_NOT_ALLOWED)
];
}
}
diff --git a/lib/private/app/deprecationcodechecker.php b/lib/private/app/deprecationcodechecker.php
index 32ae4e7d7ba..9a23bb2c530 100644
--- a/lib/private/app/deprecationcodechecker.php
+++ b/lib/private/app/deprecationcodechecker.php
@@ -21,10 +21,6 @@
namespace OC\App;
-use PhpParser\Lexer;
-use PhpParser\Node;
-use PhpParser\Node\Name;
-
class DeprecationCodeChecker extends CodeChecker {
protected $checkEqualOperators = true;
@@ -41,4 +37,15 @@ class DeprecationCodeChecker extends CodeChecker {
'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',
+ ];
}