Completed
Pull Request — master (#64)
by Aleh
13:01 queued 05:24
created

ClassNameCompleter::canHandle()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 9
rs 8.8571
cc 5
eloc 6
nc 5
nop 2
1
<?php
2
3
namespace Padawan\Domain\Completer;
4
5
use Padawan\Domain\Project;
6
use Padawan\Domain\Completion\Context;
7
use Padawan\Domain\Completion\Entry;
8
9
class ClassNameCompleter extends AbstractInCodeBodyCompleter
10
{
11
    public function getEntries(Project $project, Context $context) {
12
        $entries = [];
13
        $postfix = trim("");
14
        foreach ($project->getIndex()->getClasses() as $fqcn => $class) {
15
            if (!empty($postfix) && strpos($fqcn, $postfix) === false) {
16
                continue;
17
            }
18
            $fqcn = $context->getScope()->getUses()->findAlias($class->fqcn);
19
            $complete = str_replace($postfix, "", $fqcn);
20
            $entries[] = new Entry(
21
                $complete, '', '',
22
                $fqcn
23
            );
24
        }
25
        return $entries;
26
    }
27
28
    public function canHandle(Project $project, Context $context)
29
    {
30
        return $context->isClassName()
31
            || (
32
                parent::canHandle($project, $context)
33
                && ($context->isString() || $context->isEmpty())
34
                && strlen($postfix) > 0
0 ignored issues
show
Bug introduced by
The variable $postfix does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
35
            );
36
    }
37
}
38