Passed
Push — master ( 62f88c...f66e07 )
by Marcel
09:55
created

MessageStrategy::getHtmlTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
namespace App\Notification\Email;
4
5
use App\Notification\MessageNotification;
6
use App\Notification\Notification;
7
use App\Settings\NotificationSettings;
8
use App\Utils\ArrayUtils;
9
10
class MessageStrategy implements EmailStrategyInterface {
11
12
    public function __construct(private readonly NotificationSettings $notificationSettings) { }
13
14
    public function supports(Notification $notification): bool {
15
        return $notification instanceof MessageNotification
16
            // Da es sich um eine Massen-Benachrichtigung handelt, sind nur ausgewählte Benutzertypen erlaubt
17
            && ArrayUtils::inArray($notification->getRecipient()->getUserType(), $this->notificationSettings->getEmailEnabledUserTypes()) !== false;
18
    }
19
20
    /**
21
     * @param MessageNotification $notification
22
     * @return string|null
23
     */
24
    public function getReplyTo(Notification $notification): ?string {
25
        return $notification->getMessage()->getCreatedBy()?->getEmail();
0 ignored issues
show
Bug introduced by
The method getMessage() does not exist on App\Notification\Notification. It seems like you code against a sub-type of App\Notification\Notification such as App\Notification\MessageNotification. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        return $notification->/** @scrutinizer ignore-call */ getMessage()->getCreatedBy()?->getEmail();
Loading history...
26
    }
27
28
    /**
29
     * @param MessageNotification $notification
30
     * @return string
31
     */
32
    public function getSender(Notification $notification): string {
33
        $user = $notification->getMessage()->getCreatedBy();
34
35
        if($user === null) {
36
            return 'N/A';
37
        }
38
39
        return sprintf('%s %s', $user->getFirstname(), $user->getLastname());
40
    }
41
42
    public function getTemplate(): string {
43
        return 'email/message.txt.twig';
44
    }
45
46
    public function getHtmlTemplate(): ?string {
47
        return 'email/message.html.twig';
48
    }
49
}