Passed
Branch tmp/scrutinizer-notification-d... (24bdcd)
by Romain
05:04
created

EntitySlackTcaService::getDefinitionIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\TCA;
18
19
use CuyZ\Notiz\Core\Notification\Service\NotificationTcaService;
20
use CuyZ\Notiz\Core\Notification\Settings\NotificationSettings;
21
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\EntitySlackNotification;
22
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Settings\EntitySlackSettings;
23
24
class EntitySlackTcaService extends NotificationTcaService
25
{
26
    /**
27
     * Loads all bots provided by the notification and stores them as an array
28
     * to be used in the TCA.
29
     *
30
     * @param array $parameters
31
     */
32
    public function getBotsList(array &$parameters)
33
    {
34
        if ($this->definitionHasErrors()) {
35
            return;
36
        }
37
38
        foreach ($this->getNotificationSettings()->getBots() as $bot) {
0 ignored issues
show
Bug introduced by
The method getBots() does not exist on CuyZ\Notiz\Core\Notifica...gs\NotificationSettings. It seems like you code against a sub-type of said class. However, the method does not exist in CuyZ\Notiz\Core\Notifica...ptyNotificationSettings. 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

38
        foreach ($this->getNotificationSettings()->/** @scrutinizer ignore-call */ getBots() as $bot) {
Loading history...
39
            $parameters['items'][] = [
40
                $bot->getName(),
41
                $bot->getIdentifier(),
42
            ];
43
        }
44
    }
45
46
    /**
47
     * Loads all Slack channels provided by the notification and stores them as
48
     * an array to be used in the TCA.
49
     *
50
     * @param array $parameters
51
     */
52
    public function getSlackChannelsList(array &$parameters)
53
    {
54
        if ($this->definitionHasErrors()) {
55
            return;
56
        }
57
58
        foreach ($this->getNotificationSettings()->getChannels() as $channel) {
0 ignored issues
show
Bug introduced by
The method getChannels() does not exist on CuyZ\Notiz\Core\Notifica...gs\NotificationSettings. It seems like you code against a sub-type of said class. However, the method does not exist in CuyZ\Notiz\Core\Notifica...ptyNotificationSettings. 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

58
        foreach ($this->getNotificationSettings()->/** @scrutinizer ignore-call */ getChannels() as $channel) {
Loading history...
59
            $parameters['items'][] = [
60
                $channel->getLabel(),
61
                $channel->getIdentifier(),
62
            ];
63
        }
64
    }
65
66
    /**
67
     * @return bool
68
     */
69
    public function hasDefinedBot()
70
    {
71
        if ($this->definitionHasErrors()) {
72
            return false;
73
        }
74
75
        return count($this->getNotificationSettings()->getBots()) > 0;
76
    }
77
78
    /**
79
     * @return bool
80
     */
81
    public function hasNoDefinedBot()
82
    {
83
        return !$this->hasDefinedBot();
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getNoDefinedBotText()
90
    {
91
        $view = $this->viewService->getStandaloneView('Backend/TCA/NoDefinedBotMessage');
92
93
        return $view->render();
94
    }
95
96
    /**
97
     * @return bool
98
     */
99
    public function hasDefinedSlackChannel()
100
    {
101
        if ($this->definitionHasErrors()) {
102
            return false;
103
        }
104
105
        return count($this->getNotificationSettings()->getChannels()) > 0;
106
    }
107
108
    /**
109
     * @return bool
110
     */
111
    public function hasNoDefinedSlackChannel()
112
    {
113
        return !$this->hasDefinedSlackChannel();
114
    }
115
116
    /**
117
     * @return string
118
     */
119
    public function getNoDefinedSlackChannelText()
120
    {
121
        $view = $this->viewService->getStandaloneView('Backend/TCA/NoDefinedSlackChannel');
122
123
        return $view->render();
124
    }
125
126
    /**
127
     * @return EntitySlackSettings|NotificationSettings
128
     */
129
    protected function getNotificationSettings()
130
    {
131
        return $this->getNotificationDefinition()->getSettings();
132
    }
133
134
    /**
135
     * @return string
136
     */
137
    protected function getDefinitionIdentifier()
138
    {
139
        return EntitySlackNotification::getDefinitionIdentifier();
140
    }
141
}
142