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

ClassRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 0
cbo 4
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findByName() 0 9 2
A findAllByNamePart() 0 13 4
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