NotificationActivationController::processAction()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 31
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 16
c 1
b 0
f 0
nc 8
nop 3
dl 0
loc 31
rs 9.7333
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\Controller\Backend\Manager;
19
20
use CuyZ\Notiz\Controller\Backend\Menu;
21
use CuyZ\Notiz\Core\Notification\Activable;
22
23
class NotificationActivationController extends ManagerController
24
{
25
    /**
26
     * @param string $notificationType
27
     * @param string $notificationIdentifier
28
     * @param string|null $filterEvent
29
     */
30
    public function processAction(string $notificationType, string $notificationIdentifier, string $filterEvent = null)
31
    {
32
        $definition = $this->getDefinition();
33
34
        if (!$definition->hasNotification($notificationType)) {
35
            $this->addErrorMessage(
36
                'Backend/Module/Manager:notification_type_not_found',
37
                $notificationType
38
            );
39
40
            $this->returnToList($notificationType, $filterEvent);
41
        }
42
43
        $notificationDefinition = $definition->getNotification($notificationType);
44
        $processor = $notificationDefinition->getProcessor();
45
46
        $notification = $processor->getNotificationFromIdentifier($notificationIdentifier);
47
48
        if (!$notification instanceof Activable) {
49
            $this->returnToList($notificationType, $filterEvent);
50
        }
51
52
        if ($notification->isActive()) {
0 ignored issues
show
Bug introduced by
The method isActive() does not exist on CuyZ\Notiz\Core\Notification\Notification. It seems like you code against a sub-type of said class. However, the method does not exist in CuyZ\Notiz\Domain\Notifi...Slack\SlackNotification or CuyZ\Notiz\Domain\Notifi...Email\EmailNotification or CuyZ\Notiz\Domain\Notification\Log\LogNotification. Are you sure you never get one of those? ( Ignorable by Annotation )

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

52
        if ($notification->/** @scrutinizer ignore-call */ isActive()) {
Loading history...
53
            $processor->disable($notification);
54
55
            $this->returnToList($notificationType, $filterEvent);
56
        }
57
58
        $processor->enable($notification);
59
60
        $this->returnToList($notificationType, $filterEvent);
61
    }
62
63
    /**
64
     * @param string $notificationType
65
     * @param string|null $filterEvent [PHP 7.1]
66
     */
67
    private function returnToList(string $notificationType, $filterEvent)
68
    {
69
        $this->forward(
70
            'process',
71
            'Backend\\Manager\\ListNotifications',
72
            null,
73
            [
74
                'notificationIdentifier' => $notificationType,
75
                'filterEvent' => $filterEvent,
76
            ]
77
        );
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    protected function getMenu(): string
84
    {
85
        return Menu::MANAGER_NOTIFICATIONS;
86
    }
87
}
88