NexmoMessageAdapterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 73.58 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A testFormat() 9 9 1
A testFormatWithTwig() 19 19 1
A assertValidDispatchData() 11 11 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\NexmoMessageAdapter;
6
use IrishDan\NotificationBundle\Message\MessageInterface;
7
8
class NexmoMessageAdapterTest extends AdapterTestCase
9
{
10
    public function setUp()
11
    {
12
        parent::setUp();
13
        $parameters = $this->getParametersFromContainer('notification.channel.nexmo.configuration');
14
        $this->adapter = new NexmoMessageAdapter();
15
        $this->adapter->setConfiguration($parameters);
16
        $this->adapter->setChannelName('nexmo');
17
    }
18
19 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...
20
    {
21
        $message = $this->adapter->format($this->notification);
22
23
        $this->assertValidDispatchData($message);
24
        $this->assertMessageDataStructure($message);
25
26
        $this->assertBasicMessageData($message);
27
    }
28
29 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...
30
    {
31
        $this->setTwig();
32
        $message = $this->adapter->format($this->notification);
33
34
        $this->assertValidDispatchData($message);
35
        $this->assertMessageDataStructure($message);
36
37
        $messageData = $message->getMessageData();
38
        $this->assertEquals('New member', $messageData['title']);
39
40
        $message = 'Hello jimBob
41
Notification message for jimBob
42
Sincerely yours,
43
NotificationBundle
44
Sent via nexmo channel.';
45
46
        $this->assertEquals($message, $messageData['body']);
47
    }
48
49 View Code Duplication
    private function assertValidDispatchData(MessageInterface $message)
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...
50
    {
51
        $this->assertEquals('nexmo', $message->getChannel());
52
53
        $dispatchData = $message->getDispatchData();
54
        $this->assertArrayHasKey('to', $dispatchData);
55
        $this->assertArrayHasKey('from', $dispatchData);
56
57
        $this->assertEquals('+44755667788', $dispatchData['to']);
58
        $this->assertEquals('JimBob', $dispatchData['from']);
59
    }
60
}