SwiftMailerReporter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 41
loc 41
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A sendEmail() 23 23 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Liip\MonitorBundle\Helper;
4
5
use Laminas\Diagnostics\Check\CheckInterface;
6
use Laminas\Diagnostics\Result\Collection as ResultsCollection;
7
use Laminas\Diagnostics\Result\ResultInterface;
8
use Swift_Mailer;
9
use Swift_Message;
10
11
/**
12
 * @author louis <[email protected]>
13
 */
14 View Code Duplication
class SwiftMailerReporter extends AbstractMailReporter
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    private $mailer;
17
18
    /**
19
     * @param string|array $recipients
20
     * @param string       $sender
21
     * @param string       $subject
22
     * @param bool         $sendOnWarning
23
     */
24 7
    public function __construct(Swift_Mailer $mailer, $recipients, $sender, $subject, $sendOnWarning = true)
25
    {
26 7
        $this->mailer = $mailer;
27
28 7
        parent::__construct($recipients, $sender, $subject, $sendOnWarning);
29 7
    }
30
31 4
    protected function sendEmail(ResultsCollection $results)
32
    {
33 4
        $body = '';
34
35 4
        foreach ($results as $check) {
36
            /* @var $check  CheckInterface */
37
            /* @var $result ResultInterface */
38 4
            $result = $results[$check] ?? null;
39
40 4
            if ($result instanceof ResultInterface) {
41 4
                $body .= sprintf("Check: %s\n", $check->getLabel());
42 4
                $body .= sprintf("Message: %s\n\n", $result->getMessage());
43
            }
44
        }
45
46 4
        $message = (new Swift_Message())
47 4
            ->setSubject($this->subject)
48 4
            ->setFrom($this->sender)
49 4
            ->setTo($this->recipients)
50 4
            ->setBody($body);
51
52 4
        $this->mailer->send($message);
53 4
    }
54
}
55