Completed
Push — master ( 81db43...f030be )
by Aleh
12s
created

ClassRepository::findByName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 2
eloc 6
nc 2
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($name);
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