Code Duplication    Length = 37-41 lines in 2 locations

Helper/SwiftMailerReporter.php 1 location

@@ 14-54 (lines=41) @@
11
/**
12
 * @author louis <[email protected]>
13
 */
14
class SwiftMailerReporter extends AbstractMailReporter
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
    public function __construct(Swift_Mailer $mailer, $recipients, $sender, $subject, $sendOnWarning = true)
25
    {
26
        $this->mailer = $mailer;
27
28
        parent::__construct($recipients, $sender, $subject, $sendOnWarning);
29
    }
30
31
    protected function sendEmail(ResultsCollection $results)
32
    {
33
        $body = '';
34
35
        foreach ($results as $check) {
36
            /* @var $check  CheckInterface */
37
            /* @var $result ResultInterface */
38
            $result = $results[$check] ?? null;
39
40
            if ($result instanceof ResultInterface) {
41
                $body .= sprintf("Check: %s\n", $check->getLabel());
42
                $body .= sprintf("Message: %s\n\n", $result->getMessage());
43
            }
44
        }
45
46
        $message = (new Swift_Message())
47
            ->setSubject($this->subject)
48
            ->setFrom($this->sender)
49
            ->setTo($this->recipients)
50
            ->setBody($body);
51
52
        $this->mailer->send($message);
53
    }
54
}
55

Helper/SymfonyMailerReporter.php 1 location

@@ 11-47 (lines=37) @@
8
use Symfony\Component\Mailer\MailerInterface;
9
use Symfony\Component\Mime\Email;
10
11
class SymfonyMailerReporter extends AbstractMailReporter
12
{
13
    /**
14
     * @var MailerInterface
15
     */
16
    private $mailer;
17
18
    public function __construct(MailerInterface $mailer, array $recipients, string $sender, string $subject, bool $sendOnWarning = true)
19
    {
20
        $this->mailer = $mailer;
21
22
        parent::__construct($recipients, $sender, $subject, $sendOnWarning);
23
    }
24
25
    protected function sendEmail(ResultsCollection $results): void
26
    {
27
        $body = '';
28
29
        foreach ($results as $check) {
30
            /* @var $check  CheckInterface */
31
            /* @var $result ResultInterface */
32
            $result = $results[$check] ?? null;
33
34
            if ($result instanceof ResultInterface) {
35
                $body .= sprintf('[%s] %s', $check->getLabel(), $result->getMessage());
36
            }
37
        }
38
39
        $message = (new Email())
40
            ->subject($this->subject)
41
            ->from($this->sender)
42
            ->to(...$this->recipients)
43
            ->text($body);
44
45
        $this->mailer->send($message);
46
    }
47
}
48