getNoDefinedSlackChannelText()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
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\Domain\Notification\Slack\Application\EntitySlack\TCA;
19
20
use CuyZ\Notiz\Core\Notification\Service\NotificationTcaService;
21
use CuyZ\Notiz\Core\Notification\Settings\NotificationSettings;
22
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\EntitySlackNotification;
23
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Settings\EntitySlackSettings;
24
25
class EntitySlackTcaService extends NotificationTcaService
26
{
27
    /**
28
     * Loads all bots provided by the notification and stores them as an array
29
     * to be used in the TCA.
30
     *
31
     * @param array $parameters
32
     */
33
    public function getBotsList(array &$parameters)
34
    {
35
        if ($this->definitionHasErrors()) {
36
            return;
37
        }
38
39
        foreach ($this->getNotificationSettings()->getBots() as $bot) {
40
            $parameters['items'][] = [
41
                $bot->getName(),
42
                $bot->getIdentifier(),
43
            ];
44
        }
45
    }
46
47
    /**
48
     * Loads all Slack channels provided by the notification and stores them as
49
     * an array to be used in the TCA.
50
     *
51
     * @param array $parameters
52
     */
53
    public function getSlackChannelsList(array &$parameters)
54
    {
55
        if ($this->definitionHasErrors()) {
56
            return;
57
        }
58
59
        foreach ($this->getNotificationSettings()->getChannels() as $channel) {
60
            $parameters['items'][] = [
61
                $channel->getLabel(),
62
                $channel->getIdentifier(),
63
            ];
64
        }
65
    }
66
67
    /**
68
     * @return bool
69
     */
70
    public function hasDefinedBot(): bool
71
    {
72
        if ($this->definitionHasErrors()) {
73
            return false;
74
        }
75
76
        return count($this->getNotificationSettings()->getBots()) > 0;
77
    }
78
79
    /**
80
     * @return bool
81
     */
82
    public function hasNoDefinedBot(): bool
83
    {
84
        return !$this->hasDefinedBot();
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getNoDefinedBotText(): string
91
    {
92
        $view = $this->viewService->getStandaloneView('Backend/TCA/NoDefinedBotMessage');
93
94
        return $view->render();
95
    }
96
97
    /**
98
     * @return bool
99
     */
100
    public function hasDefinedSlackChannel(): bool
101
    {
102
        if ($this->definitionHasErrors()) {
103
            return false;
104
        }
105
106
        return count($this->getNotificationSettings()->getChannels()) > 0;
107
    }
108
109
    /**
110
     * @return bool
111
     */
112
    public function hasNoDefinedSlackChannel(): bool
113
    {
114
        return !$this->hasDefinedSlackChannel();
115
    }
116
117
    /**
118
     * @return string
119
     */
120
    public function getNoDefinedSlackChannelText(): string
121
    {
122
        $view = $this->viewService->getStandaloneView('Backend/TCA/NoDefinedSlackChannel');
123
124
        return $view->render();
125
    }
126
127
    /**
128
     * @return EntitySlackSettings|NotificationSettings
129
     */
130
    protected function getNotificationSettings(): EntitySlackSettings
131
    {
132
        return $this->getNotificationDefinition()->getSettings();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getNotific...nition()->getSettings() returns the type CuyZ\Notiz\Core\Notifica...gs\NotificationSettings which includes types incompatible with the type-hinted return CuyZ\Notiz\Domain\Notifi...ngs\EntitySlackSettings.
Loading history...
133
    }
134
135
    /**
136
     * @return string
137
     */
138
    protected function getDefinitionIdentifier(): string
139
    {
140
        return EntitySlackNotification::getDefinitionIdentifier();
141
    }
142
}
143