SlackChannel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A fromDefinition() 0 3 1
A fromNotification() 0 5 1
A __construct() 0 4 1
A getWebhookUrl() 0 3 1
A getTarget() 0 3 1
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\Data;
19
20
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\EntitySlackNotification;
21
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Settings\Channels\Channel as ChannelDefinition;
22
23
class SlackChannel
24
{
25
    /**
26
     * @var string
27
     */
28
    private $webhookUrl;
29
30
    /**
31
     * @var string
32
     */
33
    private $target;
34
35
    /**
36
     * @param string $webhookUrl
37
     * @param string $target
38
     */
39
    private function __construct(string $webhookUrl, string $target)
40
    {
41
        $this->webhookUrl = $webhookUrl;
42
        $this->target = $target;
43
    }
44
45
    /**
46
     * @param EntitySlackNotification $notification
47
     * @return static
48
     */
49
    public static function fromNotification(EntitySlackNotification $notification): self
50
    {
51
        return new static(
52
            $notification->getWebhookUrl(),
53
            $notification->getTarget()
54
        );
55
    }
56
57
    /**
58
     * @param ChannelDefinition $channel
59
     * @return static
60
     */
61
    public static function fromDefinition(ChannelDefinition $channel): self
62
    {
63
        return new static($channel->getWebhookUrl(), $channel->getTarget());
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getWebhookUrl(): string
70
    {
71
        return $this->webhookUrl;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getTarget(): string
78
    {
79
        return $this->target;
80
    }
81
}
82