EntityNotificationProcessor::enable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * Copyright (C)
6
 * Nathan Boiron <[email protected]>
7
 * Romain Canon <[email protected]>
8
 *
9
 * This file is part of the TYPO3 NotiZ project.
10
 * It is free software; you can redistribute it and/or modify it
11
 * under the terms of the GNU General Public License, either
12
 * version 3 of the License, or any later version.
13
 *
14
 * For the full copyright and license information, see:
15
 * http://www.gnu.org/licenses/gpl-3.0.html
16
 */
17
18
namespace CuyZ\Notiz\Core\Notification\Processor;
19
20
use CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\EventDefinition;
21
use CuyZ\Notiz\Core\Notification\Activable;
22
use CuyZ\Notiz\Core\Notification\Notification;
23
use CuyZ\Notiz\Domain\Notification\EntityNotification;
24
use CuyZ\Notiz\Domain\Repository\EntityNotificationRepository;
25
26
abstract class EntityNotificationProcessor extends NotificationProcessor
27
{
28
    /**
29
     * The repository needs to be injected in the child class.
30
     *
31
     * @var EntityNotificationRepository
32
     */
33
    protected $notificationRepository;
34
35
    /**
36
     * @param EventDefinition $definition
37
     * @return Notification[]
38
     */
39
    public function getNotificationsFromEventDefinition(EventDefinition $definition): array
40
    {
41
        return $this->notificationRepository
42
            ->findFromEventDefinition($definition)
43
            ->toArray();
44
    }
45
46
    /**
47
     * @param EventDefinition $definition
48
     * @return Notification[]
49
     */
50
    public function getNotificationsFromEventDefinitionWithDisabled(EventDefinition $definition): array
51
    {
52
        return $this->notificationRepository
53
            ->findFromEventDefinitionWithDisabled($definition)
54
            ->toArray();
55
    }
56
57
    /**
58
     * @param EventDefinition $definition
59
     * @return int
60
     */
61
    public function countNotificationsFromEventDefinition(EventDefinition $definition): int
62
    {
63
        return $this->notificationRepository->countFromEventDefinition($definition);
64
    }
65
66
    /**
67
     * @param string $identifier
68
     * @return Notification
69
     */
70
    public function getNotificationFromIdentifier(string $identifier): Notification
71
    {
72
        return $this->notificationRepository->findByIdentifierForce($identifier);
73
    }
74
75
    /**
76
     * @return Notification[]
77
     */
78
    public function getAllNotifications(): array
79
    {
80
        return $this->notificationRepository
81
            ->findAll()
82
            ->toArray();
83
    }
84
85
    /**
86
     * @return Notification[]
87
     */
88
    public function getAllNotificationsWithDisabled(): array
89
    {
90
        return $this->notificationRepository
91
            ->findAllWithDisabled()
92
            ->toArray();
93
    }
94
95
    /**
96
     * @return int
97
     */
98
    public function getTotalNumber(): int
99
    {
100
        return $this->notificationRepository
101
            ->findAll()
102
            ->count();
103
    }
104
105
    /**
106
     * @param Activable|EntityNotification $notification
107
     */
108
    public function enable(Activable $notification)
109
    {
110
        $notification->setActive(true);
0 ignored issues
show
Bug introduced by
The method setActive() does not exist on CuyZ\Notiz\Core\Notification\Activable. Since it exists in all sub-types, consider adding an abstract or default implementation to CuyZ\Notiz\Core\Notification\Activable. ( Ignorable by Annotation )

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

110
        $notification->/** @scrutinizer ignore-call */ 
111
                       setActive(true);
Loading history...
111
112
        $this->notificationRepository->update($notification);
113
    }
114
115
    /**
116
     * @param Activable|EntityNotification $notification
117
     */
118
    public function disable(Activable $notification)
119
    {
120
        $notification->setActive(false);
121
122
        $this->notificationRepository->update($notification);
123
    }
124
}
125