Completed
Pull Request — develop (#28)
by Michael
02:15
created

Attachment::setText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Crummy\Phlack\Message;
4
5
use Crummy\Phlack\Common\OptionsResolver;
6
use Crummy\Phlack\Message\Collection\FieldCollection;
7
8
class Attachment extends Partial implements AttachmentInterface
9
{
10
    protected $required = ['fallback'];
11
    protected $optional = [
12
        'text',
13
        'pretext',
14
        'color',
15
        'fields',
16
        'author_name',
17
        'author_link',
18
        'author_icon',
19
        'title',
20
        'title_link',
21
        'image_url',
22
        'thumb_url',
23
        'mrkdwn_in',
24
    ];
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 16
    public function __construct($data = [])
30
    {
31 16
        if (!isset($data['fields'])) {
32 9
            $data['fields'] = new FieldCollection();
33 9
        }
34
35 16
        parent::__construct($data);
36 15
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 16
    protected function setDefaultOptions(OptionsResolver $resolver)
42
    {
43 16
        parent::setDefaultOptions($resolver);
44
45 16
        $resolver->setTypesAllowed([
46 16
            'fields' => '\Crummy\Phlack\Message\Collection\FieldCollection',
47 16
        ]);
48 16
    }
49
50
    /**
51
     * @param FieldInterface $field
52
     *
53
     * @return $this
54
     */
55 4
    public function addField(FieldInterface $field)
56
    {
57 4
        $this['fields']->add($field);
58
59 4
        return $this;
60
    }
61
62
    /**
63
     * @return FieldCollection
64
     */
65 2
    public function getFields()
66
    {
67 2
        return $this['fields'];
68
    }
69
}
70