Passed
Pull Request — master (#75)
by Nathan
05:29
created

SlackBot::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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