Field::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Pageon\SlackWebhookMonolog\Slack\Attachment;
4
5
use JsonSerializable;
6
7
/**
8
 * Will be displayed in a table inside the message attachment.
9
 *
10
 * @author Jelmer Prins <[email protected]>
11
 *
12
 * @since 0.4.0
13
 */
14
final class Field implements JsonSerializable
15
{
16
    /**
17
     * Shown as a bold heading above the value text.
18
     * It cannot contain markup and will be escaped for you.
19
     *
20
     * @var string
21
     */
22
    private $title;
23
24
    /**
25
     * The text value of the field.
26
     * It may contain standard message markup and must be escaped as normal.
27
     * May be multi-line.
28
     *
29
     * @var string
30
     */
31
    private $value;
32
33
    /**
34
     * An optional flag indicating whether the value is short enough to be displayed side-by-side with other values.
35
     *
36
     * @var bool
37
     */
38
    private $short;
39
40
    /**
41
     * AttachmentField constructor.
42
     *
43
     * @param string $title
44
     * @param string $value
45
     * @param bool $short
46
     */
47 13
    public function __construct($title, $value, $short = false)
48
    {
49 13
        $this->title = $title;
50 13
        $this->value = $value;
51 13
        $this->short = $short;
52 13
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 13
    public function jsonSerialize()
58
    {
59
        return [
60 13
            'title' => $this->title,
61 13
            'value' => $this->value,
62 13
            'short' => $this->short,
63 13
        ];
64
    }
65
}
66