Passed
Pull Request — master (#1914)
by Janko
81:21
created

StuMail   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 39.13%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 50
ccs 9
cts 23
cp 0.3913
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 3 1
A setBody() 0 5 1
A setFrom() 0 5 1
A setSubject() 0 5 1
A withDefaultSender() 0 9 1
A addTo() 0 5 1
A __construct() 0 5 1
1
<?php
2
3
namespace Stu\Lib\Mail;
4
5
use Stu\Module\Config\StuConfigInterface;
6
use Symfony\Component\Mailer\MailerInterface;
7
use Symfony\Component\Mime\Email;
8
9
class StuMail implements StuMailInterface
10
{
11 1
    public function __construct(
12
        private Email $email,
13
        private MailerInterface $mailer,
14
        private StuConfigInterface $stuConfig
15 1
    ) {}
16
17 1
    public function withDefaultSender(): StuMailInterface
18
    {
19 1
        $this->email->from($this
20 1
            ->stuConfig
21 1
            ->getGameSettings()
22 1
            ->getEmailSettings()
23 1
            ->getSenderAddress());
24
25 1
        return $this;
26
    }
27
28
    public function setFrom(string $from): StuMailInterface
29
    {
30
        $this->email->from($from);
31
32
        return $this;
33
    }
34
35
    public function addTo(string $to): StuMailInterface
36
    {
37
        $this->email->to($to);
38
39
        return $this;
40
    }
41
42
    public function setSubject(string $subject): StuMailInterface
43
    {
44
        $this->email->subject($subject);
45
46
        return $this;
47
    }
48
49
    public function setBody(string $text): StuMailInterface
50
    {
51
        $this->email->text($text);
52
53
        return $this;
54
    }
55
56
    public function send(): void
57
    {
58
        $this->mailer->send($this->email);
59
    }
60
}
61