Completed
Push — master ( cb2c73...1a2628 )
by Aleh
12s
created

GlobalFunctionsCompleter   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 6
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntries() 0 21 4
B canHandle() 0 11 5
1
<?php
2
3
namespace Padawan\Domain\Completer;
4
5
use Padawan\Domain\Core\Project;
6
use Padawan\Domain\Core\Completion\Context;
7
use Padawan\Domain\Core\Completion\Entry;
8
use Padawan\Domain\Core\Node\FunctionData;
9
10
class GlobalFunctionsCompleter extends AbstractInCodeBodyCompleter
11
{
12
    public function getEntries(Project $project, Context $context)
13
    {
14
        $entries = [];
15
        $postfix = trim($context->getData());
16
        foreach ($project->getIndex()->getFunctions() as $function) {
17
            /** @var FunctionData $function */
18
            $name = $function->name;
19
            if (!empty($postfix) && strpos($name, $postfix) !== 0) {
20
                continue;
21
            }
22
            $nameToComplete = str_replace($postfix, "", $name);
23
            $entries[$name] = new Entry(
24
                $nameToComplete,
25
                $function->getSignature(),
26
                $function->doc,
27
                $name
28
            );
29
        }
30
        $entries = array_values($entries);
31
        return $entries;
32
    }
33
34
    public function canHandle(Project $project, Context $context)
35
    {
36
        $postfix = "";
37
        if (is_string($context->getData())) {
38
            $postfix = trim($context->getData());
39
        }
40
        return parent::canHandle($project, $context)
41
            && ($context->isString() || $context->isEmpty())
42
            && strlen($postfix) > 2
43
            ;
44
    }
45
}
46