Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Notification
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getTextForUser
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Olz\Command\Notifications\Common;
4
5use Olz\Constants\NotificationType;
6use Olz\Entity\Users\User;
7
8/**
9 * @phpstan-type NotificationConfig array{
10 *   notification_type?: NotificationType,
11 *   recipient_user_ids?: array<int>,
12 * }
13 */
14class Notification {
15    public string $title;
16    public string $text;
17    /** @var NotificationConfig */
18    public array $config;
19
20    /** @param NotificationConfig $config */
21    public function __construct(string $title, string $text, array $config = []) {
22        $this->title = $title;
23        $this->text = $text;
24        $this->config = $config;
25    }
26
27    public function getTextForUser(User $user): string {
28        $placeholders = [
29            '%%userFirstName%%',
30            '%%userLastName%%',
31            '%%userUsername%%',
32            '%%userEmail%%',
33        ];
34        $replacements = [
35            $user->getFirstName(),
36            $user->getLastName(),
37            $user->getUsername(),
38            $user->getEmail() ?? '',
39        ];
40        return str_replace($placeholders, $replacements, $this->text);
41    }
42}