Lines 100.00% 17 / 17
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Covered by tests of size
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 sendMailToNewUser 100.00% 16 / 16 100.00% 1 / 1 3
36readonly class MailHelper
37{
38    private Mail $mail;
39
40    /**
41     * MailHelper constructor.
42     */
43    public function __construct(
44        private Configuration $configuration,
45    ) {
46        $this->mail = new Mail($this->configuration);
47    }
48
49    /**
50     * @throws Exception
51     * @throws TransportExceptionInterface
52     */
53    public function sendMailToNewUser(User $user, #[SensitiveParameter] string $password): bool
54    {
55        $displayName = $user->getUserData('display_name');
56        $displayName = is_string($displayName) ? $displayName : '';
57        $email = $user->getUserData('email');
58        $email = is_string($email) ? $email : '';
59
60        $text = sprintf(
61            '<p>You have been registered as a new user:</p><p>Name: %s<br>Login name: %s<br>Password: %s</p>'
62            . '<p><a href="%s">Check it out here</a></p>',
63            $displayName,
64            $user->getLogin(),
65            $password,
66            $this->configuration->getDefaultUrl(),
67        );
68
69        $this->mail->addTo($email, $displayName);
70        $this->mail->subject = Utils::resolveMarkers(Translation::getString('emailRegSubject'), $this->configuration);
71        $this->mail->message = $text;
72
73        return (bool) $this->mail->send();
74    }
75}