Failed Conditions
Pull Request — master (#142)
by Zac
04:15
created

TestRepository   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

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
    public function findTests($search = null)
14
    {
15
        if ($search === null || empty($search)) {
16
            return $this->findAll();
17
        }
18
        
19
        if (!is_array($search)) {
20
            $search = [$search];
21
        }
22
        
23
        $tests = [];
24
        
25
        foreach ($search as $term) {
26
            //Find test by name first
27
            $test = $this->findByName($term);
28
            if ($test !== null) {
29
                $tests[] = $test;
30
                continue;
31
            }
32
             
33
            $testsInGroup = $this->findByGroupName($term);
34
            foreach ($testsInGroup as $test) {
35
                $tests[] = $test;
36
            }
37
        }
38
        
39
        return $tests;
40
    }
41
    
42
    public function findByName($name)
43
    {
44
        return $this->findOneBy([
45
            'name' => $name
46
        ]);
47
    }
48
    
49
    public function findByGroupName($name)
50
    {
51
        $group = $this->_em->getRepository('OverwatchTestBundle:TestGroup')
52
            ->findOneBy([
53
                'name' => $name
54
            ]);
55
56
        if ($group === null) {
57
            return [];
58
        }
59
        
60
        return $this->findBy([
61
            'group' => $group
62
        ]);
63
    }
64
}
65