Message   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A setDefaultOptions() 0 14 2
A addAttachment() 0 6 1
A getAttachments() 0 4 1
1
<?php
2
3
namespace Crummy\Phlack\Message;
4
5
use Crummy\Phlack\Common\OptionsResolver;
6
use Crummy\Phlack\Message\Collection\AttachmentCollection;
7
use Symfony\Component\OptionsResolver\Options;
8
9
class Message extends Partial implements MessageInterface
10
{
11
    protected $optional = ['text', 'channel', 'username', 'icon_emoji', 'attachments'];
12
13
    /**
14
     * @param $text
15
     * @param null $channel
16
     * @param null $username
17
     * @param null $iconEmoji
18
     */
19 15
    public function __construct($text, $channel = null, $username = null, $iconEmoji = null)
20
    {
21 15
        parent::__construct([
22 15
            'text'          => $text,
23 15
            'channel'       => $channel,
24 15
            'username'      => $username,
25 15
            'icon_emoji'    => $iconEmoji,
26 15
            'attachments'   => new AttachmentCollection(),
27 15
        ]);
28 15
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 15
    protected function setDefaultOptions(OptionsResolver $resolver)
34
    {
35 15
        parent::setDefaultOptions($resolver);
36
37 15
        $resolver->setTypesAllowed([
38 15
            'attachments' => '\Crummy\Phlack\Message\Collection\AttachmentCollection',
39 15
        ]);
40
41 15
        $resolver->setNormalizers([
42 15
            'icon_emoji' => function (Options $options, $value) {
43 15
                return empty($value) ? $value : sprintf(':%s:', trim($value, ':'));
44 15
            },
45 15
        ]);
46 15
    }
47
48
    /**
49
     * @param AttachmentInterface $attachment
50
     *
51
     * @return $this
52
     */
53 2
    public function addAttachment(AttachmentInterface $attachment)
54
    {
55 2
        $this['attachments']->add($attachment);
56
57 2
        return $this;
58
    }
59
60
    /**
61
     * @return AttachmentCollection
62
     */
63 1
    public function getAttachments()
64
    {
65 1
        return $this->data['attachments'];
66
    }
67
}
68