Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/ArcanistXHPASTLinter.php
| Show First 20 Lines • Show All 296 Lines • ▼ Show 20 Lines | foreach ($expressions as $expression) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| $name = strtolower($strstr->getChildByIndex(0)->getConcreteString()); | $name = strtolower($strstr->getChildByIndex(0)->getConcreteString()); | ||||
| if ($name == 'strstr' || $name == 'strchr') { | if ($name == 'strstr' || $name == 'strchr') { | ||||
| $this->raiseLintAtNode( | $this->raiseLintAtNode( | ||||
| $strstr, | $strstr, | ||||
| self::LINT_SLOWNESS, | self::LINT_SLOWNESS, | ||||
| "Use strpos() for checking if the string contains something."); | 'Use strpos() for checking if the string contains something.'); | ||||
| } else if ($name == 'stristr') { | } else if ($name == 'stristr') { | ||||
| $this->raiseLintAtNode( | $this->raiseLintAtNode( | ||||
| $strstr, | $strstr, | ||||
| self::LINT_SLOWNESS, | self::LINT_SLOWNESS, | ||||
| "Use stripos() for checking if the string contains something."); | 'Use stripos() for checking if the string contains something.'); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| public function lintStrposUsedForStart(XHPASTNode $root) { | public function lintStrposUsedForStart(XHPASTNode $root) { | ||||
| $expressions = $root->selectDescendantsOfType('n_BINARY_EXPRESSION'); | $expressions = $root->selectDescendantsOfType('n_BINARY_EXPRESSION'); | ||||
| foreach ($expressions as $expression) { | foreach ($expressions as $expression) { | ||||
| $operator = $expression->getChildOfType(1, 'n_OPERATOR'); | $operator = $expression->getChildOfType(1, 'n_OPERATOR'); | ||||
| Show All 20 Lines | foreach ($expressions as $expression) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| $name = strtolower($strpos->getChildByIndex(0)->getConcreteString()); | $name = strtolower($strpos->getChildByIndex(0)->getConcreteString()); | ||||
| if ($name == 'strpos') { | if ($name == 'strpos') { | ||||
| $this->raiseLintAtNode( | $this->raiseLintAtNode( | ||||
| $strpos, | $strpos, | ||||
| self::LINT_SLOWNESS, | self::LINT_SLOWNESS, | ||||
| "Use strncmp() for checking if the string starts with something."); | 'Use strncmp() for checking if the string starts with something.'); | ||||
| } else if ($name == 'stripos') { | } else if ($name == 'stripos') { | ||||
| $this->raiseLintAtNode( | $this->raiseLintAtNode( | ||||
| $strpos, | $strpos, | ||||
| self::LINT_SLOWNESS, | self::LINT_SLOWNESS, | ||||
| "Use strncasecmp() for checking if the string starts with ". | 'Use strncasecmp() for checking if the string starts with '. | ||||
| "something."); | 'something.'); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| public function lintPHP53Features(XHPASTNode $root) { | public function lintPHP53Features(XHPASTNode $root) { | ||||
| $functions = $root->selectTokensOfType('T_FUNCTION'); | $functions = $root->selectTokensOfType('T_FUNCTION'); | ||||
| foreach ($functions as $function) { | foreach ($functions as $function) { | ||||
| ▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | foreach ($calls as $call) { | ||||
| } | } | ||||
| } | } | ||||
| } else if ($windows === '' || version_compare($windows, '5.3.0') > 0) { | } else if ($windows === '' || version_compare($windows, '5.3.0') > 0) { | ||||
| $this->raiseLintAtNode( | $this->raiseLintAtNode( | ||||
| $node, | $node, | ||||
| self::LINT_PHP_53_FEATURES, | self::LINT_PHP_53_FEATURES, | ||||
| "This codebase targets PHP 5.3.0 on Windows, but `{$name}()` is not ". | "This codebase targets PHP 5.3.0 on Windows, but `{$name}()` is not ". | ||||
| "available there". | "available there". | ||||
| ($windows ? " until PHP {$windows}" : "")."."); | ($windows ? " until PHP {$windows}" : '')."."); | ||||
| } | } | ||||
| } | } | ||||
| $classes = $root->selectDescendantsOfType('n_CLASS_NAME'); | $classes = $root->selectDescendantsOfType('n_CLASS_NAME'); | ||||
| foreach ($classes as $node) { | foreach ($classes as $node) { | ||||
| $name = strtolower($node->getConcreteString()); | $name = strtolower($node->getConcreteString()); | ||||
| $version = idx($compat_info['interfaces'], $name); | $version = idx($compat_info['interfaces'], $name); | ||||
| $version = idx($compat_info['classes'], $name, $version); | $version = idx($compat_info['classes'], $name, $version); | ||||
| Show All 13 Lines | public function lintPHP54Features(XHPASTNode $root) { | ||||
| foreach ($indexes as $index) { | foreach ($indexes as $index) { | ||||
| $left = $index->getChildByIndex(0); | $left = $index->getChildByIndex(0); | ||||
| switch ($left->getTypeName()) { | switch ($left->getTypeName()) { | ||||
| case 'n_FUNCTION_CALL': | case 'n_FUNCTION_CALL': | ||||
| case 'n_METHOD_CALL': | case 'n_METHOD_CALL': | ||||
| $this->raiseLintAtNode( | $this->raiseLintAtNode( | ||||
| $index->getChildByIndex(1), | $index->getChildByIndex(1), | ||||
| self::LINT_PHP_54_FEATURES, | self::LINT_PHP_54_FEATURES, | ||||
| "The f()[...] syntax was not introduced until PHP 5.4, but this ". | 'The f()[...] syntax was not introduced until PHP 5.4, but this '. | ||||
| "codebase targets an earlier version of PHP. You can rewrite ". | 'codebase targets an earlier version of PHP. You can rewrite '. | ||||
| "this expression using idx()."); | 'this expression using idx().'); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| private function lintImplicitFallthrough(XHPASTNode $root) { | private function lintImplicitFallthrough(XHPASTNode $root) { | ||||
| $hook_obj = null; | $hook_obj = null; | ||||
| $working_copy = $this->getEngine()->getWorkingCopy(); | $working_copy = $this->getEngine()->getWorkingCopy(); | ||||
| ▲ Show 20 Lines • Show All 1,515 Lines • ▼ Show 20 Lines | protected function lintExitExpressions(XHPASTNode $root) { | ||||
| $unaries = $root->selectDescendantsOfType('n_UNARY_PREFIX_EXPRESSION'); | $unaries = $root->selectDescendantsOfType('n_UNARY_PREFIX_EXPRESSION'); | ||||
| foreach ($unaries as $unary) { | foreach ($unaries as $unary) { | ||||
| $operator = $unary->getChildByIndex(0)->getConcreteString(); | $operator = $unary->getChildByIndex(0)->getConcreteString(); | ||||
| if (strtolower($operator) == 'exit') { | if (strtolower($operator) == 'exit') { | ||||
| if ($unary->getParentNode()->getTypeName() != 'n_STATEMENT') { | if ($unary->getParentNode()->getTypeName() != 'n_STATEMENT') { | ||||
| $this->raiseLintAtNode( | $this->raiseLintAtNode( | ||||
| $unary, | $unary, | ||||
| self::LINT_EXIT_EXPRESSION, | self::LINT_EXIT_EXPRESSION, | ||||
| "Use exit as a statement, not an expression."); | 'Use exit as a statement, not an expression.'); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| private function lintArrayIndexWhitespace(XHPASTNode $root) { | private function lintArrayIndexWhitespace(XHPASTNode $root) { | ||||
| $indexes = $root->selectDescendantsOfType('n_INDEX_ACCESS'); | $indexes = $root->selectDescendantsOfType('n_INDEX_ACCESS'); | ||||
| foreach ($indexes as $index) { | foreach ($indexes as $index) { | ||||
| ▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | foreach ($array_literals as $array_literal) { | ||||
| } | } | ||||
| } | } | ||||
| foreach ($keys_warn as $key => $_) { | foreach ($keys_warn as $key => $_) { | ||||
| $node = array_pop($nodes_by_key[$key]); | $node = array_pop($nodes_by_key[$key]); | ||||
| $message = $this->raiseLintAtNode( | $message = $this->raiseLintAtNode( | ||||
| $node, | $node, | ||||
| self::LINT_DUPLICATE_KEYS_IN_ARRAY, | self::LINT_DUPLICATE_KEYS_IN_ARRAY, | ||||
| "Duplicate key in array initializer. PHP will ignore all ". | 'Duplicate key in array initializer. PHP will ignore all '. | ||||
| "but the last entry."); | 'but the last entry.'); | ||||
| $locations = array(); | $locations = array(); | ||||
| foreach ($nodes_by_key[$key] as $node) { | foreach ($nodes_by_key[$key] as $node) { | ||||
| $locations[] = $this->getOtherLocation($node->getOffset()); | $locations[] = $this->getOtherLocation($node->getOffset()); | ||||
| } | } | ||||
| $message->setOtherLocations($locations); | $message->setOtherLocations($locations); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 272 Lines • Show Last 20 Lines | |||||