ResultReporterManager   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 36
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 4 1
A notifyAll() 0 10 3
A postPersist() 0 8 2
1
<?php
2
3
namespace Overwatch\ResultBundle\Reporter;
4
5
use Doctrine\ORM\Event\LifecycleEventArgs;
6
use Overwatch\ResultBundle\Entity\TestResult;
7
use Overwatch\ResultBundle\Reporter\ResultReporterInterface;
8
9
/**
10
 * ResultReporterManager
11
 * The ResultReporterManager keeps a list of all known ResultReporters and also
12
 * acts as an event listener to the doctrine postPersist event. When a postPersist
13
 * event is fired for the TestResult class, this Manager will notify all ResultReporters
14
 * that have been added to it.
15
 */
16
class ResultReporterManager
17
{
18
    private $resultReporters = [];
19
20
    private $logger;
21
22 134
    public function __construct($logger)
23
    {
24 134
        $this->logger = $logger;
25 134
    }
26
27 134
    public function add(ResultReporterInterface $reporter)
28
    {
29 134
        $this->resultReporters[] = $reporter;
30 134
    }
31
32 129
    public function notifyAll(TestResult $result)
33
    {
34 129
        foreach ($this->resultReporters as $reporter) {
35
            try {
36 129
                $reporter->notify($result);
37 129
            } catch (\Exception $ex) {
38 1
                $this->logger->error('An error occurred whilst calling ResultReporter ' . \get_class($reporter) . ':' . $ex);
39
            }
40 129
        }
41 129
    }
42
43 127
    public function postPersist(LifecycleEventArgs $args)
44
    {
45 127
        $entity = $args->getEntity();
46
47 127
        if ($entity instanceof TestResult) {
48 127
            $this->notifyAll($entity);
49 127
        }
50 127
    }
51
}
52