Passed
Push — master ( 128fe0...fa7a2a )
by Nico
10:40
created

EmailNotificationSender::sendNotification()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2.0491

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 17
ccs 10
cts 13
cp 0.7692
crap 2.0491
rs 9.8333
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Message\Lib;
6
7
use JBBCode\Parser;
8
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use RuntimeException;
10
use Stu\Lib\Mail\MailFactoryInterface;
11
use Stu\Module\Logging\LoggerEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Logging\LoggerEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Stu\Module\Logging\LoggerUtilFactoryInterface;
13
use Stu\Module\Logging\LoggerUtilInterface;
14
use Stu\Orm\Entity\UserInterface;
15
16
final class EmailNotificationSender implements EmailNotificationSenderInterface
17
{
18
    private LoggerUtilInterface $loggerUtil;
19
20 3
    public function __construct(
21
        private MailFactoryInterface $mailFactory,
22
        private Parser $bbcodeParser,
23
        LoggerUtilFactoryInterface $loggerUtilFactory
24
    ) {
25 3
        $this->loggerUtil = $loggerUtilFactory->getLoggerUtil();
26
    }
27
28 1
    #[Override]
29
    public function sendNotification(string $senderName, string $message, UserInterface $user): void
30
    {
31 1
        $mail = $this->mailFactory->createStuMail()
32 1
            ->withDefaultSender()
33 1
            ->addTo($user->getEmail())
34 1
            ->setSubject(sprintf(
35 1
                'Neue Privatnachricht von Spieler %s',
36 1
                $this->bbcodeParser->parse($senderName)->getAsText()
37 1
            ))
38 1
            ->setBody($message);
39
40
        try {
41 1
            $mail->send();
42
        } catch (RuntimeException $e) {
43
            $this->loggerUtil->init("mail", LoggerEnum::LEVEL_ERROR);
44
            $this->loggerUtil->log($e->getMessage());
45
        }
46
    }
47
}
48