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

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