SlackWebhookAdapterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 56.25 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 27
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testFormat() 9 9 1
A testFormatWithTwig() 18 18 1
A assertValidDispatchData() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace IrishDan\NotificationBundle\Test\Adapter;
4
5
use IrishDan\NotificationBundle\Adapter\SlackWebhookMessageAdapter;
6
use IrishDan\NotificationBundle\Message\MessageInterface;
7
8
class SlackWebhookAdapterTest extends AdapterTestCase
9
{
10
    public function setUp()
11
    {
12
        parent::setUp();
13
        $this->adapter = new SlackWebhookMessageAdapter();
14
        $this->adapter->setConfiguration([]);
15
        $this->adapter->setChannelName('slack');
16
    }
17
18 View Code Duplication
    public function testFormat()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    {
20
        $message = $this->adapter->format($this->notification);
21
22
        $this->assertValidDispatchData($message);
23
        $this->assertMessageDataStructure($message);
24
25
        $this->assertBasicMessageData($message);
26
    }
27
28 View Code Duplication
    public function testFormatWithTwig()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        $this->setTwig();
31
        $message = $this->adapter->format($this->notification);
32
33
        $this->assertValidDispatchData($message);
34
        $this->assertMessageDataStructure($message);
35
36
        $messageData = $message->getMessageData();
37
        $this->assertEquals('New member', $messageData['title']);
38
        $message = 'Hello jimBob
39
Notification message for jimBob
40
Sincerely yours,
41
NotificationBundle
42
Sent via slack channel.';
43
44
        $this->assertEquals($message, $messageData['body']);
45
    }
46
47
    public function assertValidDispatchData(MessageInterface $message)
48
    {
49
        $this->assertEquals('slack', $message->getChannel());
50
51
        $dispatchData = $message->getDispatchData();
52
        $this->assertEquals('https://hooks.slack.com/services/salty/salt/1234567890',
53
            $dispatchData['webhook']);
54
    }
55
}