SlackBot   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A hasEmojiAvatar() 0 4 2
A getAvatar() 0 3 1
A getName() 0 3 1
A fromNotification() 0 3 1
A fromBotDefinition() 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\Settings\Bots\Bot;
21
use CuyZ\Notiz\Domain\Notification\Slack\SlackNotification;
22
23
class SlackBot
24
{
25
    /**
26
     * @var string
27
     */
28
    private $name;
29
30
    /**
31
     * @var string
32
     */
33
    private $avatar;
34
35
    /**
36
     * @param string $name
37
     * @param string $avatar
38
     */
39
    private function __construct(string $name, string $avatar)
40
    {
41
        $this->name = $name;
42
        $this->avatar = $avatar;
43
    }
44
45
    /**
46
     * @param SlackNotification $notification
47
     * @return static
48
     */
49
    public static function fromNotification(SlackNotification $notification): self
50
    {
51
        return new static($notification->getName(), $notification->getAvatar());
52
    }
53
54
    /**
55
     * @param Bot $bot
56
     * @return static
57
     */
58
    public static function fromBotDefinition(Bot $bot): self
59
    {
60
        return new static($bot->getName(), $bot->getAvatar());
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function getName(): string
67
    {
68
        return $this->name;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getAvatar(): string
75
    {
76
        return $this->avatar;
77
    }
78
79
    /**
80
     * @return bool
81
     */
82
    public function hasEmojiAvatar(): bool
83
    {
84
        return substr($this->avatar, 0, 1) === ':'
85
            && substr($this->avatar, -1, 1) === ':';
86
    }
87
}
88