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

ClassNameCompleter   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 9
c 3
b 0
f 1
lcom 0
cbo 8
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntries() 0 16 4
B canHandle() 0 9 5
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