EntitySlackChannelMapper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getChannels() 0 21 4
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\Service;
19
20
use CuyZ\Notiz\Core\Channel\Payload;
21
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Data\SlackChannel;
22
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\EntitySlackNotification;
23
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Settings\EntitySlackSettings;
24
25
class EntitySlackChannelMapper
26
{
27
    /**
28
     * @var EntitySlackNotification
29
     */
30
    private $notification;
31
32
    /**
33
     * @var EntitySlackSettings
34
     */
35
    private $notificationSettings;
36
37
    /**
38
     * @param Payload $payload
39
     */
40
    public function __construct(Payload $payload)
41
    {
42
        $this->notification = $payload->getNotification();
0 ignored issues
show
Documentation Bug introduced by
It seems like $payload->getNotification() of type CuyZ\Notiz\Core\Notification\Notification is incompatible with the declared type CuyZ\Notiz\Domain\Notifi...EntitySlackNotification of property $notification.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
        $this->notificationSettings = $payload->getNotificationDefinition()->getSettings();
44
    }
45
46
    /**
47
     * Returns an array of channels from a custom one and/or from one or
48
     * more defined ones.
49
     *
50
     * @return SlackChannel[]
51
     */
52
    public function getChannels(): array
53
    {
54
        $channels = [];
55
56
        if ($this->notification->hasCustomSlackChannel()) {
57
            $channels[] = SlackChannel::fromNotification($this->notification);
58
        }
59
60
        $identifiers = explode(',', $this->notification->getSlackChannel());
61
62
        foreach ($identifiers as $identifier) {
63
            if (!$this->notificationSettings->hasChannel($identifier)) {
64
                continue;
65
            }
66
67
            $channels[] = SlackChannel::fromDefinition(
68
                $this->notificationSettings->getChannel($identifier)
69
            );
70
        }
71
72
        return $channels;
73
    }
74
}
75