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

StuMail::withDefaultSender()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 1
rs 10
c 0
b 0
f 0
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