TestRepository   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 54
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
C findTests() 0 28 7
A findByName() 0 6 1
A findByGroupName() 0 15 2
1
<?php
2
3
namespace Overwatch\TestBundle\Entity;
4
5
use Doctrine\ORM\EntityRepository;
6
7
/**
8
 * TestRepository
9
 * Some shortcut and convienience methods to find tests
10
 */
11
class TestRepository extends EntityRepository
12
{
13 10
    public function findTests($search = null)
14
    {
15 10
        if ($search === null || empty($search)) {
16 6
            return $this->findAll();
17
        }
18
        
19 4
        if (!is_array($search)) {
20 1
            $search = [$search];
21 1
        }
22
        
23 4
        $tests = [];
24
        
25 4
        foreach ($search as $term) {
26
            //Find test by name first
27 4
            $test = $this->findByName($term);
28 4
            if ($test !== null) {
29 3
                $tests[] = $test;
30 3
                continue;
31
            }
32
             
33 3
            $testsInGroup = $this->findByGroupName($term);
34 3
            foreach ($testsInGroup as $test) {
35 2
                $tests[] = $test;
36 3
            }
37 4
        }
38
        
39 4
        return $tests;
40
    }
41
    
42 5
    public function findByName($name)
43
    {
44 5
        return $this->findOneBy([
45
            'name' => $name
46 5
        ]);
47
    }
48
    
49 5
    public function findByGroupName($name)
50
    {
51 5
        $group = $this->_em->getRepository('OverwatchTestBundle:TestGroup')
52 5
            ->findOneBy([
53
                'name' => $name
54 5
            ]);
55
56 5
        if ($group === null) {
57 2
            return [];
58
        }
59
        
60 3
        return $this->findBy([
61
            'group' => $group
62 3
        ]);
63
    }
64
}
65