-
Notifications
You must be signed in to change notification settings - Fork 30
/
GlobalFunctionsCompleter.php
56 lines (49 loc) · 1.59 KB
/
GlobalFunctionsCompleter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Padawan\Domain\Completer;
use Padawan\Domain\Project;
use Padawan\Domain\Completion\Entry;
use Padawan\Domain\Completion\Context;
use Padawan\Domain\Project\ClassRepository;
use Padawan\Domain\Project\Node\FunctionData;
class GlobalFunctionsCompleter extends AbstractInCodeBodyCompleter
{
/** @property ClassRepository */
private $classRepository;
public function __construct(
ClassRepository $classRepository
) {
$this->classRepository = $classRepository;
}
public function getEntries(Project $project, Context $context)
{
$entries = [];
$postfix = trim($context->getData());
foreach ($project->getIndex()->getFunctions() as $function) {
/** @var FunctionData $function */
$name = $function->name;
if (!empty($postfix) && strpos($name, $postfix) !== 0) {
continue;
}
$nameToComplete = str_replace($postfix, "", $name);
$entries[$name] = new Entry(
$nameToComplete,
$function->getSignature(),
$function->doc,
$name
);
}
$entries = array_values($entries);
return $entries;
}
public function canHandle(Project $project, Context $context)
{
$postfix = "";
if (is_string($context->getData())) {
$postfix = trim($context->getData());
}
return parent::canHandle($project, $context)
&& ($context->isString() || $context->isEmpty())
&& strlen($postfix) > 0
;
}
}