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
$level = $node;
while ($level && !ParserHelpers\isFunctionLike($level)) {
while ($level && !($level instanceof PhpParser\FunctionLike)) {
// Walk siblings before the node
$sibling = $level;
while ($sibling = $sibling->getPreviousSibling()) {
@ -429,7 +429,7 @@ class CompletionProvider
// If the traversal ended because a function was met,
// 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) {
$paramName = $param->getName();
if (empty($namePrefix) || strpos($paramName, $namePrefix) !== false) {

View File

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

View File

@ -25,7 +25,7 @@ function isConstantFetch(Node $node) : bool
$parent instanceof Node\Expression\CallExpression ||
$parent instanceof Node\Expression\ObjectCreationExpression ||
$parent instanceof Node\Expression\ScopedPropertyAccessExpression ||
isFunctionLike($parent) ||
$parent instanceof PhpParser\FunctionLike ||
(
$parent instanceof Node\Expression\BinaryExpression &&
$parent->operator->kind === PhpParser\TokenKind::InstanceOfKeyword
@ -38,14 +38,6 @@ function getFunctionLikeDeclarationFromParameter(Node\Parameter $node)
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
{
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);
switch ($error->kind) {
case \Microsoft\PhpParser\DiagnosticKind::Error:
case PhpParser\DiagnosticKind::Error:
$severity = DiagnosticSeverity::ERROR;
break;
case \Microsoft\PhpParser\DiagnosticKind::Warning:
case PhpParser\DiagnosticKind::Warning:
default:
$severity = DiagnosticSeverity::WARNING;
break;