Conditions | 3 |
Paths | 3 |
Total Lines | 22 |
Lines | 22 |
Ratio | 100 % |
Tests | 13 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
25 | 1 | protected function sendEmail(ResultsCollection $results): void |
|
26 | { |
||
27 | 1 | $body = ''; |
|
28 | |||
29 | 1 | foreach ($results as $check) { |
|
30 | /* @var $check CheckInterface */ |
||
31 | /* @var $result ResultInterface */ |
||
32 | 1 | $result = $results[$check] ?? null; |
|
33 | |||
34 | 1 | if ($result instanceof ResultInterface) { |
|
35 | 1 | $body .= sprintf('[%s] %s', $check->getLabel(), $result->getMessage()); |
|
36 | } |
||
37 | } |
||
38 | |||
39 | 1 | $message = (new Email()) |
|
40 | 1 | ->subject($this->subject) |
|
41 | 1 | ->from($this->sender) |
|
42 | 1 | ->to(...$this->recipients) |
|
43 | 1 | ->text($body); |
|
44 | |||
45 | 1 | $this->mailer->send($message); |
|
46 | 1 | } |
|
47 | } |
||
48 |
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.