Passed
Branch master (4d781a)
by jelmer
02:23
created

Title::setTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Pageon\SlackWebhookMonolog\Slack\Attachment;
4
5
use Pageon\SlackWebhookMonolog\General\SerializeToString;
6
use Pageon\SlackWebhookMonolog\General\Url;
7
8
/**
9
 * The title is displayed as larger, bold text near the top of a message attachment.
10
 * By passing a valid URL in the link parameter (optional), the title text will be hyperlinked.
11
 *
12
 * @author Jelmer Prins <[email protected]>
13
 *
14
 * @since 0.3.2
15
 */
16
final class Title extends SerializeToString
17
{
18
    /**
19
     * @var string
20
     */
21
    private $title;
22
23
    /**
24
     * @var Url|null
25
     */
26
    private $link;
27
28
    /**
29
     * @param string $title
30
     * @param Url|null $link
31
     */
32 3
    public function __construct($title, Url $link = null)
33
    {
34 3
        $this->title = $title;
35 3
        $this->link = $link;
36 3
    }
37
38
    /**
39
     * @return string
40
     */
41 1
    public function getTitle()
42
    {
43 1
        return $this->title;
44
    }
45
46
    /**
47
     * @return bool
48
     */
49 1
    public function hasLink()
50
    {
51 1
        return $this->link !== null;
52
    }
53
54
    /**
55
     * @return Url|null
56
     */
57 1
    public function getLink()
58
    {
59 1
        return $this->link;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 1
    public function __toString()
66
    {
67 1
        return $this->getTitle();
68
    }
69
}
70