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

VarCompleter::canHandle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 2
1
<?php
2
3
namespace Padawan\Domain\Completer;
4
5
use Padawan\Domain\Core\Completion\Context;
6
use Padawan\Domain\Core\Completion\Scope;
7
use Padawan\Domain\Core\Project;
8
use Padawan\Domain\Core\Node\Variable;
9
use Padawan\Domain\Core\Completion\Entry;
10
use Padawan\Domain\Core\FQCN;
11
12
class VarCompleter extends AbstractInCodeBodyCompleter
13
{
14
    public function getEntries(Project $project, Context $context)
15
    {
16
        return array_map([$this, 'createEntry'], $context->getScope()->getVars());
17
    }
18
19
    public function canHandle(Project $project, Context $context)
20
    {
21
        return parent::canHandle($project, $context) && $context->isVar();
22
    }
23
24
    protected function createEntry(Variable $var)
25
    {
26
        $type = $var->getType() instanceof FQCN ?
27
            $var->getType()->toString() : $var->getType();
28
        return new Entry(
29
            $var->getName(),
30
            $type
31
        );
32
    }
33
}
34