1
0
Fork 0

refactor: use FunctionLike Interface (#505)

ci-benchmarks
Jens Hausdorf 2017-10-30 11:33:19 +01:00 committed by Felix Becker
parent 744062c14e
commit 1edbe35609
4 changed files with 7 additions and 15 deletions

View File

@ -415,7 +415,7 @@ class CompletionProvider
// Walk the AST upwards until a scope boundary is met // Walk the AST upwards until a scope boundary is met
$level = $node; $level = $node;
while ($level && !ParserHelpers\isFunctionLike($level)) { while ($level && !($level instanceof PhpParser\FunctionLike)) {
// Walk siblings before the node // Walk siblings before the node
$sibling = $level; $sibling = $level;
while ($sibling = $sibling->getPreviousSibling()) { while ($sibling = $sibling->getPreviousSibling()) {
@ -429,7 +429,7 @@ class CompletionProvider
// If the traversal ended because a function was met, // If the traversal ended because a function was met,
// also add its parameters and closure uses to the result list // also add its parameters and closure uses to the result list
if ($level && ParserHelpers\isFunctionLike($level) && $level->parameters !== null) { if ($level && $level instanceof PhpParser\FunctionLike && $level->parameters !== null) {
foreach ($level->parameters->getValues() as $param) { foreach ($level->parameters->getValues() as $param) {
$paramName = $param->getName(); $paramName = $param->getName();
if (empty($namePrefix) || strpos($paramName, $namePrefix) !== false) { if (empty($namePrefix) || strpos($paramName, $namePrefix) !== false) {

View File

@ -509,7 +509,7 @@ class DefinitionResolver
// Traverse the AST up // Traverse the AST up
do { do {
// If a function is met, check the parameters and use statements // If a function is met, check the parameters and use statements
if (ParserHelpers\isFunctionLike($n)) { if ($n instanceof PhpParser\FunctionLike) {
if ($n->parameters !== null) { if ($n->parameters !== null) {
foreach ($n->parameters->getElements() as $param) { foreach ($n->parameters->getElements() as $param) {
if ($param->getName() === $name) { if ($param->getName() === $name) {
@ -1018,7 +1018,7 @@ class DefinitionResolver
// 1. doc block // 1. doc block
// 2. return type hint // 2. return type hint
// 3. TODO: infer from return statements // 3. TODO: infer from return statements
if (ParserHelpers\isFunctionLike($node)) { if ($node instanceof PhpParser\FunctionLike) {
// Functions/methods // Functions/methods
$docBlock = $this->getDocBlock($node); $docBlock = $this->getDocBlock($node);
if ( if (

View File

@ -25,7 +25,7 @@ function isConstantFetch(Node $node) : bool
$parent instanceof Node\Expression\CallExpression || $parent instanceof Node\Expression\CallExpression ||
$parent instanceof Node\Expression\ObjectCreationExpression || $parent instanceof Node\Expression\ObjectCreationExpression ||
$parent instanceof Node\Expression\ScopedPropertyAccessExpression || $parent instanceof Node\Expression\ScopedPropertyAccessExpression ||
isFunctionLike($parent) || $parent instanceof PhpParser\FunctionLike ||
( (
$parent instanceof Node\Expression\BinaryExpression && $parent instanceof Node\Expression\BinaryExpression &&
$parent->operator->kind === PhpParser\TokenKind::InstanceOfKeyword $parent->operator->kind === PhpParser\TokenKind::InstanceOfKeyword
@ -38,14 +38,6 @@ function getFunctionLikeDeclarationFromParameter(Node\Parameter $node)
return $node->parent->parent; return $node->parent->parent;
} }
function isFunctionLike(Node $node)
{
return
$node instanceof Node\Statement\FunctionDeclaration ||
$node instanceof Node\MethodDeclaration ||
$node instanceof Node\Expression\AnonymousFunctionCreationExpression;
}
function isBooleanExpression($expression) : bool function isBooleanExpression($expression) : bool
{ {
if (!($expression instanceof Node\Expression\BinaryExpression)) { if (!($expression instanceof Node\Expression\BinaryExpression)) {

View File

@ -72,10 +72,10 @@ class TreeAnalyzer
$range = PhpParser\PositionUtilities::getRangeFromPosition($error->start, $error->length, $this->sourceFileNode->fileContents); $range = PhpParser\PositionUtilities::getRangeFromPosition($error->start, $error->length, $this->sourceFileNode->fileContents);
switch ($error->kind) { switch ($error->kind) {
case \Microsoft\PhpParser\DiagnosticKind::Error: case PhpParser\DiagnosticKind::Error:
$severity = DiagnosticSeverity::ERROR; $severity = DiagnosticSeverity::ERROR;
break; break;
case \Microsoft\PhpParser\DiagnosticKind::Warning: case PhpParser\DiagnosticKind::Warning:
default: default:
$severity = DiagnosticSeverity::WARNING; $severity = DiagnosticSeverity::WARNING;
break; break;