EntitySlackSettings::hasChannel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
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\Settings;
19
20
use CuyZ\Notiz\Core\Definition\Tree\AbstractDefinitionComponent;
21
use CuyZ\Notiz\Core\Exception\EntryNotFoundException;
22
use CuyZ\Notiz\Core\Notification\Settings\NotificationSettings;
23
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessor;
24
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessorInterface;
25
26
class EntitySlackSettings extends AbstractDefinitionComponent implements NotificationSettings, DataPreProcessorInterface
27
{
28
    /**
29
     * @var \CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Settings\Bots\Bot[]
30
     */
31
    protected $bots;
32
33
    /**
34
     * @var \CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Settings\Channels\Channel[]
35
     */
36
    protected $channels;
37
38
    /**
39
     * @return Bots\Bot[]
40
     */
41
    public function getBots(): array
42
    {
43
        return $this->bots;
44
    }
45
46
    /**
47
     * @return Channels\Channel[]
48
     */
49
    public function getChannels(): array
50
    {
51
        return $this->channels;
52
    }
53
54
    /**
55
     * @param string $identifier
56
     * @return bool
57
     */
58
    public function hasChannel(string $identifier): bool
59
    {
60
        return isset($this->channels[$identifier]);
61
    }
62
63
    /**
64
     * @param string $identifier
65
     * @return Channels\Channel
66
     *
67
     * @throws EntryNotFoundException
68
     */
69
    public function getChannel(string $identifier): Channels\Channel
70
    {
71
        if (!$this->hasChannel($identifier)) {
72
            throw EntryNotFoundException::entitySlackChannelDefinitionNotFound($identifier);
73
        }
74
75
        return $this->channels[$identifier];
76
    }
77
78
    /**
79
     * @param DataPreProcessor $processor
80
     */
81
    public static function dataPreProcessor(DataPreProcessor $processor)
82
    {
83
        $data = $processor->getData();
84
85
        // Bots object must always be set.
86
        if (!is_array($data['bots'])) {
87
            $data['bots'] = [];
88
        }
89
90
        // Channels object must always be set.
91
        if (!is_array($data['channels'])) {
92
            $data['channels'] = [];
93
        }
94
95
        $processor->setData($data);
96
    }
97
}
98