EmailReporter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 46
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A notify() 0 16 4
A sendEmail() 0 17 1
1
<?php
2
3
namespace Overwatch\ServiceBundle\Reporter;
4
5
use Overwatch\ResultBundle\Entity\TestResult;
6
use Overwatch\ResultBundle\Reporter\ResultReporterInterface;
7
8
/**
9
 * EmailReporter
10
 */
11
class EmailReporter implements ResultReporterInterface
12
{
13
    private $container;
14
    private $config;
15
    
16 132
    public function __construct($container, $config)
17
    {
18 132
        $this->container = $container;
19 132
        $this->config = $config;
20 132
    }
21
    
22 127
    public function notify(TestResult $result)
23
    {
24 127
        if ($this->config['enabled'] === false) {
25 1
            return;
26
        }
27
        
28 127
        $recipients = [];
29
        
30 127
        foreach ($result->getTest()->getGroup()->getUsers() as $user) {
31 8
            if ($user->shouldBeAlerted($result)) {
32 8
                $recipients[] = $user->getEmail();
33 8
            }
34 127
        }
35
        
36 127
        $this->sendEmail($result, $recipients);
37 127
    }
38
    
39 127
    private function sendEmail(TestResult $result, array $users)
40
    {
41 127
        $message = \Swift_Message::newInstance()
42 127
            ->setSubject($result->getTest()->getName() . ' ' . $result->getStatus())
43 127
            ->setFrom($this->config['report_from'])
44 127
            ->setTo($users)
45 127
            ->setBody(
46 127
                $this->container->get('templating')->render(
47 127
                    'OverwatchServiceBundle:Email:result.txt.twig',
48 127
                    ['result' => $result]
49 127
                ),
50
                'text\plain'
51 127
            )
52 127
        ;
53
        
54 127
        $this->container->get('mailer')->send($message);
55 127
    }
56
}
57