2017-03-01 23:55:29 +00:00
|
|
|
<?php
|
|
|
|
|
2017-06-07 23:44:14 +00:00
|
|
|
namespace LanguageServer\FqnUtilities;
|
2017-03-01 23:55:29 +00:00
|
|
|
|
|
|
|
use phpDocumentor\Reflection\{Type, Types};
|
2017-05-24 18:26:53 +00:00
|
|
|
use Microsoft\PhpParser;
|
2017-03-01 23:55:29 +00:00
|
|
|
|
2017-06-07 23:44:14 +00:00
|
|
|
/**
|
|
|
|
* Returns all possible FQNs in a type
|
|
|
|
*
|
|
|
|
* @param Type|null $type
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
function getFqnsFromType($type): array
|
2017-03-01 23:55:29 +00:00
|
|
|
{
|
2017-06-07 23:44:14 +00:00
|
|
|
$fqns = [];
|
|
|
|
if ($type instanceof Types\Object_) {
|
|
|
|
$fqsen = $type->getFqsen();
|
|
|
|
if ($fqsen !== null) {
|
|
|
|
$fqns[] = substr((string)$fqsen, 1);
|
2017-03-01 23:55:29 +00:00
|
|
|
}
|
2017-06-07 23:44:14 +00:00
|
|
|
}
|
|
|
|
if ($type instanceof Types\Compound) {
|
|
|
|
for ($i = 0; $t = $type->get($i); $i++) {
|
|
|
|
foreach (getFqnsFromType($type) as $fqn) {
|
|
|
|
$fqns[] = $fqn;
|
2017-03-01 23:55:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-07 23:44:14 +00:00
|
|
|
return $fqns;
|
2017-05-25 18:39:42 +00:00
|
|
|
}
|