1
0
Fork 0

Make FqnUtilities a module of functions, not a static class

pull/357/head
Rob Lourens 2017-06-07 16:44:14 -07:00
parent 0a15afc130
commit cfc8cc7815
4 changed files with 28 additions and 28 deletions

View File

@ -53,7 +53,8 @@
"LanguageServer\\": "src/" "LanguageServer\\": "src/"
}, },
"files" : [ "files" : [
"src/utils.php" "src/utils.php",
"src/FqnUtilities.php"
] ]
}, },
"autoload-dev": { "autoload-dev": {

View File

@ -179,7 +179,7 @@ class CompletionProvider
$a->c# $a->c#
$a-># */ $a-># */
elseif ($node instanceof Node\Expression\MemberAccessExpression) { elseif ($node instanceof Node\Expression\MemberAccessExpression) {
$prefixes = FqnUtilities::getFqnsFromType( $prefixes = FqnUtilities\getFqnsFromType(
$this->definitionResolver->resolveExpressionNodeToType($node->dereferencableExpression) $this->definitionResolver->resolveExpressionNodeToType($node->dereferencableExpression)
); );
$prefixes = $this->expandParentFqns($prefixes); $prefixes = $this->expandParentFqns($prefixes);
@ -209,7 +209,7 @@ class CompletionProvider
($scoped = $node->parent) instanceof Node\Expression\ScopedPropertyAccessExpression || ($scoped = $node->parent) instanceof Node\Expression\ScopedPropertyAccessExpression ||
($scoped = $node) instanceof Node\Expression\ScopedPropertyAccessExpression ($scoped = $node) instanceof Node\Expression\ScopedPropertyAccessExpression
) { ) {
$prefixes = FqnUtilities::getFqnsFromType( $prefixes = FqnUtilities\getFqnsFromType(
$classType = $this->definitionResolver->resolveExpressionNodeToType($scoped->scopeResolutionQualifier) $classType = $this->definitionResolver->resolveExpressionNodeToType($scoped->scopeResolutionQualifier)
); );

View File

@ -1,34 +1,33 @@
<?php <?php
namespace LanguageServer; namespace LanguageServer\FqnUtilities;
use phpDocumentor\Reflection\{Type, Types}; use phpDocumentor\Reflection\{Type, Types};
use Microsoft\PhpParser; use Microsoft\PhpParser;
class FqnUtilities echo "FQN_UTILIIES" . PHP_EOL;
/**
* Returns all possible FQNs in a type
*
* @param Type|null $type
* @return string[]
*/
function getFqnsFromType($type): array
{ {
/** $fqns = [];
* Returns all possible FQNs in a type if ($type instanceof Types\Object_) {
* $fqsen = $type->getFqsen();
* @param Type|null $type if ($fqsen !== null) {
* @return string[] $fqns[] = substr((string)$fqsen, 1);
*/
public static function getFqnsFromType($type): array
{
$fqns = [];
if ($type instanceof Types\Object_) {
$fqsen = $type->getFqsen();
if ($fqsen !== null) {
$fqns[] = substr((string)$fqsen, 1);
}
} }
if ($type instanceof Types\Compound) {
for ($i = 0; $t = $type->get($i); $i++) {
foreach (self::getFqnsFromType($type) as $fqn) {
$fqns[] = $fqn;
}
}
}
return $fqns;
} }
if ($type instanceof Types\Compound) {
for ($i = 0; $t = $type->get($i); $i++) {
foreach (getFqnsFromType($type) as $fqn) {
$fqns[] = $fqn;
}
}
}
return $fqns;
} }

View File

@ -4,7 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer\Server; namespace LanguageServer\Server;
use LanguageServer\{ use LanguageServer\{
CompletionProvider, FqnUtilities, LanguageClient, PhpDocument, PhpDocumentLoader, DefinitionResolver CompletionProvider, LanguageClient, PhpDocument, PhpDocumentLoader, DefinitionResolver
}; };
use LanguageServer\Index\ReadableIndex; use LanguageServer\Index\ReadableIndex;
use LanguageServer\Protocol\{ use LanguageServer\Protocol\{