Passed
Pull Request — master (#75)
by Nathan
03:50
created

EntitySlackTcaService::getSlackChannelsList()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 10
rs 9.4285
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\Settings\EntitySlackSettings;
22
23
class EntitySlackTcaService extends NotificationTcaService
24
{
25
    /**
26
     * @return string
27
     */
28
    protected function getNotificationIdentifier()
29
    {
30
        return 'entitySlack';
31
    }
32
33
    /**
34
     * Loads all bots provided by the notification and stores them as an array
35
     * to be used in the TCA.
36
     *
37
     * @param array $parameters
38
     */
39
    public function getBotsList(array &$parameters)
40
    {
41
        if ($this->definitionHasErrors()) {
42
            return;
43
        }
44
45
        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

45
        foreach ($this->getNotificationSettings()->/** @scrutinizer ignore-call */ getBots() as $bot) {
Loading history...
46
            $parameters['items'][] = [
47
                $bot->getName(),
48
                $bot->getIdentifier(),
49
            ];
50
        }
51
    }
52
53
    /**
54
     * Loads all Slack channels provided by the notification and stores them as
55
     * an array to be used in the TCA.
56
     *
57
     * @param array $parameters
58
     */
59
    public function getSlackChannelsList(array &$parameters)
60
    {
61
        if ($this->definitionHasErrors()) {
62
            return;
63
        }
64
65
        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

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