Completed
Pull Request — develop (#28)
by Michael
04:20
created

Attachment   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 2 Features 1
Metric Value
wmc 5
c 5
b 2
f 1
lcom 0
cbo 3
dl 0
loc 62
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A setDefaultOptions() 0 8 1
A addField() 0 6 1
A getFields() 0 4 1
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