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

VarCompleter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 6
dl 0
loc 22
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntries() 0 4 1
A canHandle() 0 4 2
A createEntry() 0 9 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