Test Setup Failed
Push — master ( d6bd2d...bc363c )
by Alexey
03:03
created

Notifier   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 61
ccs 0
cts 22
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A sendUsersRenamedNotification() 0 6 1
B sendUserSubscribersUpdatedNotification() 0 24 2
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\Service\Telegram;
4
5
use Skobkin\Bundle\PointToolsBundle\Entity\Telegram\Account;
6
use Skobkin\Bundle\PointToolsBundle\Entity\User;
7
use Skobkin\Bundle\PointToolsBundle\Entity\UserRenameEvent;
8
use Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository;
9
10
/**
11
 * Notifies Telegram users about some events
12
 */
13
class Notifier
14
{
15
    /**
16
     * @var AccountRepository
17
     */
18
    private $accountsRepo;
19
20
    /**
21
     * @var MessageSender
22
     */
23
    private $messenger;
24
25
26
    public function __construct(AccountRepository $accountRepository, MessageSender $messenger)
27
    {
28
        $this->accountsRepo = $accountRepository;
29
        $this->messenger = $messenger;
30
    }
31
32
    /**
33
     * @param UserRenameEvent[] $userRenameEvents
34
     */
35
    public function sendUsersRenamedNotification(array $userRenameEvents)
36
    {
37
        $accounts = $this->accountsRepo->findBy(['renameNotification' => true]);
38
39
        $this->messenger->sendMassTemplatedMessage($accounts, '@SkobkinPointTools/Telegram/users_renamed_notification.md.twig', ['events' => $userRenameEvents]);
40
    }
41
42
    /**
43
     * Send notification about changes in user's subscribers list
44
     *
45
     * @param User $user
46
     * @param User[] $subscribed
47
     * @param User[] $unsubscribed
48
     */
49
    public function sendUserSubscribersUpdatedNotification(User $user, array $subscribed, array $unsubscribed)
50
    {
51
        /** @var Account $account */
52
        $account = $this->accountsRepo->findOneBy(
53
            [
54
                'user' => $user,
55
                'subscriberNotification' => true,
56
            ]
57
        );
58
59
        if (null === $account) {
60
            return;
61
        }
62
63
        $this->messenger->sendTemplatedMessage(
64
            $account,
65
            '@SkobkinPointTools/Telegram/user_subscribers_updated_notification.md.twig',
66
            [
67
                'user' => $user,
68
                'subscribed' => $subscribed,
69
                'unsubscribed' => $unsubscribed,
70
            ]
71
        );
72
    }
73
}