Page MenuHomePhabricator

D10567.diff
No OneTemporary

D10567.diff

diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php
--- a/src/lint/linter/ArcanistXHPASTLinter.php
+++ b/src/lint/linter/ArcanistXHPASTLinter.php
@@ -545,10 +545,14 @@
if (version_compare($this->version, '5.3.0') < 0) {
$this->lintPHP53Features($root);
+ } else {
+ $this->lintPHP53Incompatibilities($root);
}
if (version_compare($this->version, '5.4.0') < 0) {
$this->lintPHP54Features($root);
+ } else {
+ $this->lintPHP54Incompatibilities($root);
}
}
@@ -637,19 +641,51 @@
}
}
+ private function lintPHP53Incompatibilities(XHPASTNode $root) {}
+
private function lintPHP54Features(XHPASTNode $root) {
$indexes = $root->selectDescendantsOfType('n_INDEX_ACCESS');
foreach ($indexes as $index) {
- $left = $index->getChildByIndex(0);
- switch ($left->getTypeName()) {
+ switch ($index->getChildByIndex(0)->getTypeName()) {
case 'n_FUNCTION_CALL':
case 'n_METHOD_CALL':
$this->raiseLintAtNode(
$index->getChildByIndex(1),
self::LINT_PHP_COMPATIBILITY,
- 'The f()[...] syntax was not introduced until PHP 5.4, but this '.
- 'codebase targets an earlier version of PHP. You can rewrite '.
- 'this expression using idx().');
+ pht(
+ 'The `%s` syntax was not introduced until PHP 5.4, but this '.
+ 'codebase targets an earlier version of PHP. You can rewrite '.
+ 'this expression using `%s`.',
+ 'f()[...]',
+ 'idx()'));
+ break;
+ }
+ }
+ }
+
+ private function lintPHP54Incompatibilities(XHPASTNode $root) {
+ $breaks = $root->selectDescendantsOfTypes(array('n_BREAK', 'n_CONTINUE'));
+ foreach ($breaks as $break) {
+ $arg = $break->getChildByIndex(0);
+
+ switch ($arg->getTypeName()) {
+ case 'n_EMPTY':
+ break;
+
+ case 'n_NUMERIC_SCALAR':
+ if ($arg->getConcreteString() != '0') {
+ break;
+ }
+
+ default:
+ $this->raiseLintAtNode(
+ $break->getChildByIndex(0),
+ self::LINT_PHP_COMPATIBILITY,
+ pht(
+ 'The `%s` and `%s` statements no longer accept '.
+ 'variable arguments.',
+ 'break',
+ 'continue'));
break;
}
}
diff --git a/src/lint/linter/__tests__/xhpast/php53.lint-test b/src/lint/linter/__tests__/xhpast/php53-features.lint-test
rename from src/lint/linter/__tests__/xhpast/php53.lint-test
rename to src/lint/linter/__tests__/xhpast/php53-features.lint-test
diff --git a/src/lint/linter/__tests__/xhpast/php54.lint-test b/src/lint/linter/__tests__/xhpast/php54-features.lint-test
rename from src/lint/linter/__tests__/xhpast/php54.lint-test
rename to src/lint/linter/__tests__/xhpast/php54-features.lint-test
diff --git a/src/lint/linter/__tests__/xhpast/php54-incompat.lint-test b/src/lint/linter/__tests__/xhpast/php54-incompat.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/php54-incompat.lint-test
@@ -0,0 +1,17 @@
+<?php
+break;
+break 0;
+break 1;
+break 1 + foo() * $bar;
+continue;
+continue 0;
+continue 1;
+continue 1 + foo() * $bar;
+~~~~~~~~~~
+error:3:7
+error:5:7
+error:7:10
+error:9:10
+~~~~~~~~~~
+~~~~~~~~~~
+{"config": {"xhpast.php-version": "5.4.0"}}

File Metadata

Mime Type
text/plain
Expires
Wed, Jun 12, 6:46 AM (6 d, 7 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6276140
Default Alt Text
D10567.diff (3 KB)

Event Timeline