Completed
Pull Request — master (#39)
by Aleh
02:54
created

ClassRepository::findAllByNamePart()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
rs 9.2
cc 4
eloc 8
nc 4
nop 2
1
<?php
2
3
namespace Padawan\Framework\Domain\Project;
4
5
6
use Padawan\Domain\Project;
7
use Padawan\Domain\Project\FQCN;
8
use Padawan\Domain\Project\ClassRepository as ClassRepositoryInterface;
9
10
/**
11
 * Class ClassRepository
12
 * @author
13
 */
14
class ClassRepository implements ClassRepositoryInterface
15
{
16
    public function findByName(Project $project, FQCN $name)
17
    {
18
        $index = $project->getIndex();
19
        $class = $index->findClassByFQCN($name);
20
        if (empty($class)) {
21
            $class = $index->findInterfaceByFQCN($fqcn);
0 ignored issues
show
Bug introduced by
The variable $fqcn 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...
22
        }
23
        return $class;
24
    }
25
26
    public function findAllByNamePart(Project $project, $name = "")
27
    {
28
        if (empty($name)) {
29
            return $project->getIndex()->getClasses();
30
        }
31
        $classes = [];
32
        foreach ($project->getIndex()->getClasses() as $class) {
33
            if (strpos($class->fqcn->toString(), $name) !== false) {
34
                $classes[] = $class;
35
            }
36
        }
37
        return $classes;
38
    }
39
}
40