AbstractMailReporter   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 68%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 72
ccs 17
cts 25
cp 0.68
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A onStart() 0 3 1
A onBeforeRun() 0 3 1
A onAfterRun() 0 3 1
A onStop() 0 3 1
A onFinish() 0 20 5
sendEmail() 0 1 ?
1
<?php
2
3
namespace Liip\MonitorBundle\Helper;
4
5
use ArrayObject;
6
use Laminas\Diagnostics\Check\CheckInterface;
7
use Laminas\Diagnostics\Result\Collection as ResultsCollection;
8
use Laminas\Diagnostics\Result\ResultInterface;
9
use Laminas\Diagnostics\Runner\Reporter\ReporterInterface;
10
11
abstract class AbstractMailReporter implements ReporterInterface
12
{
13
    /**
14
     * @var array|string
15
     */
16
    protected $recipients;
17
    /**
18
     * @var string
19
     */
20
    protected $subject;
21
    /**
22
     * @var string
23
     */
24
    protected $sender;
25
    /**
26
     * @var bool
27
     */
28
    protected $sendOnWarning;
29
30
    /**
31
     * @param string|array $recipients
32
     * @param string       $sender
33
     * @param string       $subject
34
     * @param bool         $sendOnWarning
35
     */
36 8
    public function __construct($recipients, $sender, $subject, $sendOnWarning = true)
37
    {
38 8
        $this->recipients = $recipients;
39 8
        $this->sender = $sender;
40 8
        $this->subject = $subject;
41 8
        $this->sendOnWarning = $sendOnWarning;
42 8
    }
43
44
    public function onStart(ArrayObject $checks, $runnerConfig)
45
    {
46
    }
47
48
    public function onBeforeRun(CheckInterface $check, $checkAlias = null)
49
    {
50
    }
51
52
    public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null)
53
    {
54
    }
55
56
    public function onStop(ResultsCollection $results)
57
    {
58
    }
59
60 8
    public function onFinish(ResultsCollection $results)
61
    {
62 8
        if ($results->getUnknownCount() > 0) {
63 1
            $this->sendEmail($results);
64
65 1
            return;
66
        }
67
68 7
        if ($results->getWarningCount() > 0 && $this->sendOnWarning) {
69 1
            $this->sendEmail($results);
70
71 1
            return;
72
        }
73
74 6
        if ($results->getFailureCount() > 0) {
75 3
            $this->sendEmail($results);
76
77 3
            return;
78
        }
79 3
    }
80
81
    abstract protected function sendEmail(ResultsCollection $results);
82
}
83