AttachmentField   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 23
c 2
b 0
f 0
dl 0
loc 131
rs 10
wmc 11

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setShort() 0 5 1
A getValue() 0 3 1
A getTitle() 0 3 1
A getShort() 0 3 1
A setValue() 0 5 1
A __construct() 0 12 4
A setTitle() 0 5 1
A toArray() 0 6 1
1
<?php
2
3
namespace Eloquentcoder\Slack;
4
5
class AttachmentField
6
{
7
    /**
8
     * The required title field of the field.
9
     *
10
     * @var string
11
     */
12
    protected $title;
13
14
    /**
15
     * The required value of the field.
16
     *
17
     * @var string
18
     */
19
    protected $value;
20
21
    /**
22
     * Whether the value is short enough to fit side by side with
23
     * other values.
24
     *
25
     * @var bool
26
     */
27
    protected $short = false;
28
29
    /**
30
     * Instantiate a new AttachmentField.
31
     *
32
     * @param array $attributes
33
     *
34
     * @return void
35
     */
36
    public function __construct(array $attributes)
37
    {
38
        if (isset($attributes['title'])) {
39
            $this->setTitle($attributes['title']);
40
        }
41
42
        if (isset($attributes['value'])) {
43
            $this->setValue($attributes['value']);
44
        }
45
46
        if (isset($attributes['short'])) {
47
            $this->setShort($attributes['short']);
48
        }
49
    }
50
51
    /**
52
     * Get the title of the field.
53
     *
54
     * @return string
55
     */
56
    public function getTitle()
57
    {
58
        return $this->title;
59
    }
60
61
    /**
62
     * Set the title of the field.
63
     *
64
     * @param string $title
65
     *
66
     * @return $this
67
     */
68
    public function setTitle($title)
69
    {
70
        $this->title = $title;
71
72
        return $this;
73
    }
74
75
    /**
76
     * Get the value of the field.
77
     *
78
     * @return string
79
     */
80
    public function getValue()
81
    {
82
        return $this->value;
83
    }
84
85
    /**
86
     * Set the value of the field.
87
     *
88
     * @param string $value
89
     *
90
     * @return $this
91
     */
92
    public function setValue($value)
93
    {
94
        $this->value = $value;
95
96
        return $this;
97
    }
98
99
    /**
100
     * Get whether this field is short enough for displaying
101
     * side-by-side with other fields.
102
     *
103
     * @return bool
104
     */
105
    public function getShort()
106
    {
107
        return $this->short;
108
    }
109
110
    /**
111
     * Set whether this field is short enough for displaying
112
     * side-by-side with other fields.
113
     *
114
     * @param string $value
115
     *
116
     * @return $this
117
     */
118
    public function setShort($value)
119
    {
120
        $this->short = (bool) $value;
121
122
        return $this;
123
    }
124
125
    /**
126
     * Get the array representation of this attachment field.
127
     *
128
     * @return array
129
     */
130
    public function toArray()
131
    {
132
        return [
133
            'title' => $this->getTitle(),
134
            'value' => $this->getValue(),
135
            'short' => $this->getShort(),
136
        ];
137
    }
138
}
139